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

1468845-20180829214355654-821626358.png
点击“创建虚拟传感器”,依次添加温度、湿度、气压、PM2.5、PM10,其中 PM2.5、PM10 类型为 Custom Sensor,单位 ug/m³。添加完成后在设置 → 设备中可看到各项添加的传感器
1468845-20180829214749580-531081927.png
在树莓派的 /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)

最终效果图
1468845-20180829215147426-2144585331.png

转载于:https://www.cnblogs.com/HintLee/p/9557182.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值