This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

WeatherXM integration and real time weather data from nearby weather stations
#1
Hello!

In crypto world there is WeatherXM project where weather station owners gonna get tokens if they run station.

XM have also an API so I made a simple integration to get realtime weather data.
Go to address and find a weather station what is nearest for your location: 
https://explorer.weatherxm.com/

Then zoom in and press on station and you'll see station device ID on address bar. Example: https://explorer.weatherxm.com/#87089b192ffffff
Change "Weather_device_ID" variable with your desired device ID.

Create scheduled script (what runs on every 15 minutes)...
If you run program on first time, enable "greate_ga" variable. That creates KNX variables automatically for you.

Code:
https = require("ssl.https")
require('json')
Weather_device_ID = '87089b192ffffff'   --Device ID from https://explorer.weatherxm.com/
greate_ga = false            --This variable enables group addresses automatic generation
main_ga = '32/1/'            --Main group address of weather data



--**********CREATE GROUP ADDRESSES******************
function createga(groupaddress,datatype2,name2, units)
  exist = grp.alias(groupaddress)
  if exist == nil then
    address = grp.create({
    datatype = datatype2,
    address = groupaddress,
    name = name2,
    comment = 'Automatically created object',
    units = units,
    tags = { },
    })
  end
end


if greate_ga then
  createga(main_ga .. '1',dt.float16,'Weather - Temperature', '°C')
  createga(main_ga .. '2',dt.float16,'Weather - Feels like temperature', '°C')
  createga(main_ga .. '3',dt.uint8,'Weather - Humidity', ' %')
  createga(main_ga .. '4',dt.float16,'Weather - Wind speed', ' m/s')
  createga(main_ga .. '5',dt.float16,'Weather - Wind gust', ' m/s')
  createga(main_ga .. '6',dt.uint8,'Weather - UV index', '')
  createga(main_ga .. '7',dt.float16,'Weather - Precipitation', ' mm/h')
  createga(main_ga .. '8',dt.float16,'Weather - Dew point', '°C')
  createga(main_ga .. '9',dt.float16,'Weather - Solar irradiance', ' W/m2')
  createga(main_ga .. '10',dt.float16,'Weather - Pressure', ' hPa')
  createga(main_ga .. '11',dt.text,'Weather - Update time', '')
  os.sleep(3)
  log('---GROUP ADDRESSES HAS BEEN CREATED---')
end

data, code = https.request('https://api.weatherxm.com/api/v1/cells/' .. Weather_device_ID .. '/devices')

if data then
  data = json.pdecode(data)
  grp.checkupdate(main_ga .. 1, data[1]["current_weather"]["temperature"])
  grp.checkupdate(main_ga .. 2, data[1]["current_weather"]["feels_like"])
  grp.checkupdate(main_ga .. 3, data[1]["current_weather"]["humidity"])
  grp.checkupdate(main_ga .. 4, data[1]["current_weather"]["wind_speed"])
  grp.checkupdate(main_ga .. 5, data[1]["current_weather"]["wind_gust"])
  grp.checkupdate(main_ga .. 6, data[1]["current_weather"]["uv_index"])
  grp.checkupdate(main_ga .. 7, data[1]["current_weather"]["precipitation_accumulated"])
  grp.checkupdate(main_ga .. 8, data[1]["current_weather"]["dew_point"])
  grp.checkupdate(main_ga .. 9, data[1]["current_weather"]["solar_irradiance"])
  grp.checkupdate(main_ga .. 10, data[1]["current_weather"]["pressure"])
  grp.checkupdate(main_ga .. 11, data[1]["current_weather"]["timestamp"])
end

Attached Files Thumbnail(s)
   
Reply
#2
Hi, thank you, looks very interesting.

But what kind of meteo station can be connected to this project?

Alex
Reply
#3
(01.05.2023, 19:39)AlexLV Wrote: Hi, thank you, looks very interesting.

But what kind of meteo station can be connected to this project? 

Alex

Hi!

Since project is still quite new, you need to buy station for them. They have plans to add almost any weather station to this project using SDR (software defined radio) but I believe that this happens end of this year.
Here is link to weather stations what people, who are in beta, using right now (and last one gonna be integration module). I have that wifi version bundle.
https://weatherxm.com/shop/
Reply


Forum Jump: