Domoticz 中添加彩云天气

前言

用过一段时间的彩云天气 APP,最吸引我的地方是精确到局部区域的天气预测,虽然准确度并不算高,但是对于预测下雨还是不错的选择。在 Domoticz 中添加彩云天气的数据,利用的是彩云天气提供的 API,本文参考了 Domoticz 官方文档http/https poller 的使用,在此表示感谢。

步骤

在设置 → 硬件中添加一项 HTTP/HTTPS poller,填入 URL,此处需要加入自己的经纬度,点此处查询,URL 中的 API_KEY 来源于 github

https://api.caiyunapp.com/v2/Y2FpeXVuIGFuZHJpb2QgYXBp/116.404412,39.915156/realtime.json


点击“创建虚拟传感器”,依次添加温度、湿度、气压、PM2.5、PM10,其中 PM2.5、PM10 类型为 Custom Sensor,单位 ug/m³。添加完成后在设置 → 设备中可看到各项添加的传感器

在树莓派的 /home/pi/domoticz/scripts/lua_parsers 目录添加 caiyun_paraser.lua 文件,内容如下,结尾的 domoticz_updateDevice 第一个参数要修改为上图中对应的 Idx

s = request['content'];

local temperature = domoticz_applyJsonPath(s, '.result.temperature')
local humidity = domoticz_applyJsonPath(s, '.result.humidity')
local hum_stat = '0'
local bar = domoticz_applyJsonPath(s, '.result.pres')
local bar_for = '0'
local skycon = domoticz_applyJsonPath(s, '.result.skycon')
local pm25 = domoticz_applyJsonPath(s, '.result.pm25')
local pm10 = domoticz_applyJsonPath(s, '.result.pm10')

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
	bar_for = '1'
elseif skycon == 'PARTLY_CLOUDY_DAY' or skycon == 'PARTLY_CLOUDY_NIGHT' then
	bar_for = '2'
elseif skycon == 'CLOUDY' then
	bar_for = '3'
elseif skycon == 'RAIN' then
	bar_for = '4'
end

domoticz_updateDevice(3, 0, temperature)
domoticz_updateDevice(4, humidity*100, hum_stat)
domoticz_updateDevice(5, 0, tostring(bar/100)..';'..bar_for)
domoticz_updateDevice(6, 0, pm25)
domoticz_updateDevice(7, 0, pm10)

最终效果图

posted @ 2018-08-29 21:52  HintLee  阅读(2710)  评论(4编辑  收藏  举报