DzVents脚本获取中国天气网实时室外天气温湿度数据
发表于 : 周四 12月 21, 2023 12:44
代码: 全选
return {
on = {
--每5分钟更新一次
timer = { 'every 5 minutes' },
httpResponses = {
'd_response'
}
},
execute = function(domoticz, item)
--天气地址码,根据自己的地区更改,从链接中获取:http://www.weather.com.cn/weather1d/101010100.shtml
local location = 101120509
--温湿度设备名称
local deviceName = '室外'
if (item.isTimer) then
domoticz.openURL({
headers = {['Host']='d1.weather.com.cn',['Referer']='http://www.weather.com.cn/',['User-Agent']='Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36' },
url = 'http://d1.weather.com.cn/sk_2d/'..location..'.html',
method = 'GET',
callback = 'd_response',
})
end
if (item.isHTTPResponse and item.ok) then
data_s = string.match(item.data,'({.*})')
local d_json = domoticz.utils.fromJSON(data_s)
domoticz.devices(deviceName).updateTempHum(d_json["temp"],d_json["SD"]:sub(1, -2))
end
end
}