前言

用过一段时间的彩云天气 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

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

最终效果图
Domoticz 中添加彩云天气

相关文章:

  • 2022-12-23
  • 2021-04-23
  • 2021-07-29
  • 2021-11-22
  • 2022-02-10
  • 2021-09-22
  • 2021-09-09
  • 2022-12-23
猜你喜欢
  • 2021-12-14
  • 2022-12-23
  • 2021-10-07
  • 2022-01-13
  • 2021-04-09
  • 2021-10-13
相关资源
相似解决方案