29.04.2023, 15:37
(This post was last modified: 02.05.2023, 07:53 by fleeceable.)
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.
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