http/https poller的使用——一个wiki都懒得提的设备

文档:
https://en.domoticz.cn/wiki/DzVents:_ne ... _scripting
回复
blindlight
帖子: 98
注册时间: 周四 3月 30, 2017 00:03

http/https poller的使用——一个wiki都懒得提的设备

帖子 blindlight »

先上个图混个脸熟
hpcreate.png
hpcreate.png (205.87 KiB) 查看 20258 次
说白了 就是个request的gui界面
用来干嘛 最适合需要定时获取而不需要变更参数的各网站的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)
创建文件在domoticz/scripts/lua_parasers/caiyun_paraser.lua
文件名填入command

效果图
hpshow1.png
hpshow1.png (151.06 KiB) 查看 20258 次
hpshow2.png
hpshow2.png (27.82 KiB) 查看 20258 次
blindlight
帖子: 98
注册时间: 周四 3月 30, 2017 00:03

Re: http/https poller的使用——一个wiki都懒得提的设备

帖子 blindlight »

对了 给个大神博客 里面有poller参数具体格式用法
https://xujiwei.com/blog/
头像
DT27
帖子: 345
注册时间: 周四 3月 30, 2017 08:54
Gender:

Re: http/https poller的使用——一个wiki都懒得提的设备

帖子 DT27 »

膜拜 :o wiki里都没有的东西怎么研究出来的
lixy
帖子: 2
注册时间: 周四 1月 11, 2018 09:35

Re: http/https poller的使用——一个wiki都懒得提的设备

帖子 lixy »

彩云的格式变了,修改了下代码成功。最后几句代码里面的18,23等数字要改成自个设备代码。

s = request['content'];

local temperature = domoticz_applyJsonPath(s, '.result.temperature')
local humidity = domoticz_applyJsonPath(s, '.result.humidity')
local status=domoticz_applyJsonPath(s, '.result.status')
local skycon = domoticz_applyJsonPath(s, '.result.skycon')
local aqi = domoticz_applyJsonPath(s, '.result.aqi')
local pm25 = domoticz_applyJsonPath(s, '.result.pm25')
local wind_dir = domoticz_applyJsonPath(s, '.result.wind.direction')
local wind_speed = domoticz_applyJsonPath(s, '.result.wind.speed')



local thb = skycon.. ';'..'temperature:'..tostring(temperature)..';humidity:'..tostring(humidity*100)..';aqi='..tostring(aqi)..';pm25='..tostring(pm25)

domoticz_updateDevice(18,'',thb)
domoticz_updateDevice(23,'',tostring(aqi))
domoticz_updateDevice(22,'',tostring(humidity*100))
domoticz_updateDevice(21,'',tostring(temperature))
domoticz_updateDevice(19,'',tostring(pm25))
blindlight
帖子: 98
注册时间: 周四 3月 30, 2017 00:03

Re: http/https poller的使用——一个wiki都懒得提的设备

帖子 blindlight »

lixy 写了: 周五 1月 12, 2018 10:38 彩云的格式变了,修改了下代码成功。最后几句代码里面的18,23等数字要改成自个设备代码。

s = request['content'];

local temperature = domoticz_applyJsonPath(s, '.result.temperature')
local humidity = domoticz_applyJsonPath(s, '.result.humidity')
local status=domoticz_applyJsonPath(s, '.result.status')
local skycon = domoticz_applyJsonPath(s, '.result.skycon')
local aqi = domoticz_applyJsonPath(s, '.result.aqi')
local pm25 = domoticz_applyJsonPath(s, '.result.pm25')
local wind_dir = domoticz_applyJsonPath(s, '.result.wind.direction')
local wind_speed = domoticz_applyJsonPath(s, '.result.wind.speed')



local thb = skycon.. ';'..'temperature:'..tostring(temperature)..';humidity:'..tostring(humidity*100)..';aqi='..tostring(aqi)..';pm25='..tostring(pm25)

domoticz_updateDevice(18,'',thb)
domoticz_updateDevice(23,'',tostring(aqi))
domoticz_updateDevice(22,'',tostring(humidity*100))
domoticz_updateDevice(21,'',tostring(temperature))
domoticz_updateDevice(19,'',tostring(pm25))
厉害
回复