用来干嘛 最适合需要定时获取而不需要变更参数的各网站的api
比如和风,彩云这种api返回json的天气网站
然后通过编写lua paraser进行数据解析更新到创建的设备上
这里举个最简单的例子 不需header 没有data 使用get方式获取的彩云天气
代码: 全选
s = request['content'];
local temperature = domoticz_applyJsonPath(s, '.result.realtime.temperature')
local humidity = domoticz_applyJsonPath(s, '.result.realtime.humidity')
local pressure = domoticz_applyJsonPath(s, '.result.realtime.pres')
local aqi = domoticz_applyJsonPath(s, '.result.realtime.aqi')
local pm25 = domoticz_applyJsonPath(s, '.result.realtime.pm25')
local pm10 = domoticz_applyJsonPath(s, '.result.realtime.pm10')
local wind_dir = domoticz_applyJsonPath(s, '.result.realtime.wind.direction')
local wind_speed = domoticz_applyJsonPath(s, '.result.realtime.wind.speed')
local skycon = domoticz_applyJsonPath(s, '.result.realtime.skycon')
local alert = domoticz_applyJsonPath(s, '.result.alert.content[0]')
local description = domoticz_applyJsonPath(s, '.result.minutely.description')
local pres_for = '0'
local hum_stat = '0'
if alert == nil then
alert = '无天气预警'
end
--if aqi >= 100 then
-- description = description..'。建议佩戴口罩。'
--end
if humidity >= 0.4 and humidity <= 0.6 then
hum_stat = '1'
elseif humidity >= 0.3 and humidity <= 0.8 then
hum_stat = '0'
elseif humidity > 0.8 then
hum_stat = '3'
elseif humidity < 0.3 then
hum_stat = '2'
end
if skycon == 'CLEAR_DAY' or skycon == 'CLEAR_NIGHT' then
pres_for = '1'
elseif skycon == 'PARTLY_CLOUDY_DAY' or skycon == 'PARTLY_CLOUDY_NIGHT' then
pres_for = '2'
elseif skycon == 'CLOUDY' then
pres_for = '3'
elseif skycon == 'RAIN' then
pres_for = '4'
end
local thb = tostring(temperature)..';'..tostring(humidity*100)..';'..hum_stat..';'..tostring(pressure/100)..';'..pres_for
domoticz_updateDevice(122,'',thb)
domoticz_updateDevice(123,'',tostring(aqi))
domoticz_updateDevice(124,'',tostring(pm25))
domoticz_updateDevice(125,'',tostring(pm10))
domoticz_updateDevice(126,'',alert)
domoticz_updateDevice(127,'',description)
文件名填入command
效果图