Page 1 of 1
increase or decrease of temperature
Posted: Friday 18 March 2022 9:39
by jacobsentertainment
Hi all,
I'm currently working on a heating system where I need to determine if a temperature is increasing or decreasing so I can anticipate with the script.
My intention is to open up a valve in the system when the temperature of the stove is 45° and increasing. and close the valve as soon as the temperature is below 50° and decreasing.
If someone can help me get started that would be much appreciated.
Re: increase or decrease of temperature
Posted: Wednesday 30 March 2022 14:45
by waltervl
when you request the data from a temperature device with /json.htm?type=devices&rid=IDX you can get the trend (2 or 3).
3 is decreasing
2 is increasing
Edit: 0=Unknown, 1=Stable, 2=Up, 3=Down
See also the up/down arrows in a temperature device widget.
the attribute is not exposed within dzVents so you will have to read it with openurl and parse the json for the trend value.
Re: increase or decrease of temperature
Posted: Wednesday 30 March 2022 21:53
by waltervl
Well to be prepared for the next question I made an example script how to get the trend ( 0=Unknown, 1=Stable, 2=Up, 3=Down) of a temperature device.
Replace IP_DOMO, PORT and IDX to your own environment
Code: Select all
return {
on = {
timer = {
'every 1 minutes' -- just an example to trigger the request
},
httpResponses = {
'GetTrend' -- must match with the callback passed to the openURL command
}
},
logging = {
level = domoticz.LOG_INFO,
marker = 'template',
},
execute = function(domoticz, item)
if (item.isTimer) then
domoticz.openURL({
url = 'http://IP_DOMO:PORT/json.htm?type=devices&rid=IDX',
method = 'GET',
callback = 'GetTrend', -- see httpResponses above.
})
end
if (item.isHTTPResponse) then
if (item.ok) then
if (item.isJSON) then
local DevTrend = item.json.result[1].trend -- to get the trend out of the json.
-- log trend of device in Domoticz, 0=Unknown, 1=Stable, 2=Up, 3=Down
domoticz.log('Trend of dev = ' .. DevTrend, domoticz.LOG_LOG)
end
else
domoticz.log('There was a problem handling the request', domoticz.LOG_ERROR)
domoticz.log(item, domoticz.LOG_ERROR)
end
end
end
}
Re: increase or decrease of temperature
Posted: Thursday 31 March 2022 13:08
by thomasbaetge
Hi,
I just came across this.... is there an option to get the trend value in MQTT as well? IIRC it is not in the payload for temp sensors so far..?
Re: increase or decrease of temperature
Posted: Thursday 31 March 2022 13:10
by jacobsentertainment
Cheers Walter

Ill give it try tonight.
waltervl wrote: ↑Wednesday 30 March 2022 21:53
Well to be prepared for the next question I made an example script how to get the trend ( 0=Unknown, 1=Stable, 2=Up, 3=Down) of a temperature device.
Replace IP_DOMO, PORT and IDX to your own environment
Code: Select all
return {
on = {
timer = {
'every 1 minutes' -- just an example to trigger the request
},
httpResponses = {
'GetTrend' -- must match with the callback passed to the openURL command
}
},
logging = {
level = domoticz.LOG_INFO,
marker = 'template',
},
execute = function(domoticz, item)
if (item.isTimer) then
domoticz.openURL({
url = 'http://IP_DOMO:PORT/json.htm?type=devices&rid=IDX',
method = 'GET',
callback = 'GetTrend', -- see httpResponses above.
})
end
if (item.isHTTPResponse) then
if (item.ok) then
if (item.isJSON) then
local DevTrend = item.json.result[1].trend -- to get the trend out of the json.
-- log trend of device in Domoticz, 0=Unknown, 1=Stable, 2=Up, 3=Down
domoticz.log('Trend of dev = ' .. DevTrend, domoticz.LOG_LOG)
end
else
domoticz.log('There was a problem handling the request', domoticz.LOG_ERROR)
domoticz.log(item, domoticz.LOG_ERROR)
end
end
end
}
Re: increase or decrease of temperature
Posted: Thursday 31 March 2022 20:24
by jacobsentertainment
Sure I do something wrong here

And I admit I know to little of this.
Anyway me result where
Code: Select all
2022-03-31 20:20:01.335 Error: Error opening url: http://192.168.178.72:8080/json.htm?type=devices&rid=64
2022-03-31 20:20:01.697 Error: dzVents: Error: (3.1.8) Trend: HTTP/1.1 response: 401 ==>> Unauthorized
2022-03-31 20:20:01.700 Error: dzVents: Error: (3.1.8) Trend: There was a problem handling the request
2022-03-31 20:20:01.700 Error: dzVents: Error: (3.1.8) Trend: {["data"]="<html><head><title>Unauthorized</title></head><body><h1>401 Unauthorized</h1></body></html>", ["isJSON"]=false, ["isDevice"]=false, ["isVariable"]=false, ["headers"]={["Content-Type"]="text/html;charset=UTF-8", ["Set-Cookie"]="DMZSID=none; HttpOnly; Expires=Thu, 01 Jan 1970 00:00:00 GMT", ["Content-Length"]="91"}, ["callback"]="GetTrend", ["isXML"]=true, ["isSecurity"]=false, ["trigger"]="GetTrend", ["statusCode"]=401, ["protocol"]="HTTP/1.1", ["xml"]={["html"]={["body"]={["h1"]="401 Unauthorized"}, ["head"]={["title"]="Unauthorized"}}}, ["isCustomEvent"]=false, ["isHTTPResponse"]=true, ["baseType"]="httpResponse", ["_contentType"]="text/html;charset=UTF-8", ["isSystem"]=false, ["isHardware"]=false, ["statusText"]="Unauthorized", ["isShellCommandResponse"]=false, ["isTimer"]=false, ["isGroup"]=false, ["isScene"]=false, ["ok"]=false, ["dump"]=function}
If I put the http directly in a browser I get the info of that sensor.
Re: increase or decrease of temperature
Posted: Thursday 31 March 2022 22:01
by waltervl
If you have user/password, do you have 127.0.0.* (next to your local network 192.168.178.*) in the local Networks setting (menu setup- settings)?
Re: increase or decrease of temperature
Posted: Thursday 31 March 2022 23:11
by jacobsentertainment
waltervl wrote: ↑Thursday 31 March 2022 22:01
If you have user/password, do you have 127.0.0.* (next to your local network 192.168.178.*) in the local Networks setting (menu setup- settings)?
I do have a username and password setup in domoticz, but nothing in 127.0.0.
Re: increase or decrease of temperature
Posted: Thursday 31 March 2022 23:35
by waltervl
So you should. Like the dzvents documentation says:
https://www.domoticz.com/wiki/DzVents:_ ... h_Domoticz
Also make sure that in the Security section in the settings (Setup > Settings > System > Local Networks (no username/password) you allow 127.0.0.1 (and / or ::1 when using IPv6 ) to not need a password. dzVents does use this port to get the location settings and to send certain commands to Domoticz.
Re: increase or decrease of temperature
Posted: Saturday 02 April 2022 5:42
by jacobsentertainment
Ill try to have a look in to this this week, currently back on job and away from home.
Re: increase or decrease of temperature
Posted: Sunday 03 April 2022 17:42
by jacobsentertainment
I have it working;
Code: Select all
2022-04-03 17:40:00.420 Status: dzVents: Info: Trend: ------ Start internal script: trend test:, trigger: "every 1 minutes"
2022-04-03 17:40:00.420 Status: dzVents: Info: Trend: ------ Finished trend test
2022-04-03 17:40:00.992 Status: dzVents: Info: Handling httpResponse-events for: "GetTrend"
2022-04-03 17:40:00.992 Status: dzVents: Info: Trend: ------ Start internal script: trend test: HTTPResponse: "GetTrend"
2022-04-03 17:40:00.994 Status: dzVents: Info: Trend: Trend of dev = 3
2022-04-03 17:40:00.994 Status: dzVents: Info: Trend: ------ Finished trend test
Maybe silly to ask but how can I use this 0, 1, 2, or 3 to trigger an action

Re: increase or decrease of temperature
Posted: Sunday 03 April 2022 18:22
by waltervl
Like you said in first post (make it dzvents yourself):
If temp = 45 and trend = 2 then open valve
If temp = 50 and trend = 3 then close valve
Re: increase or decrease of temperature
Posted: Sunday 03 April 2022 18:25
by jacobsentertainment
waltervl wrote: ↑Sunday 03 April 2022 18:22
Like you said in first post (make it dzvents yourself):
If temp = 45 and trend = 2 then open valve
If temp = 50 and trend = 3 then close valve
Cheers Walter
I also had a little play to get some results
Code: Select all
if DevTrend ~= 2 then
domoticz.log('Trend gaat omhoog', domoticz.LOG_LOG)
elseif
DevTrend ~= 3 then
domoticz.log('Trend gaat omlaag', domoticz.LOG_LOG)
And it works just fine, this opens up some options

Re: increase or decrease of temperature
Posted: Friday 30 June 2023 9:01
by ayasystems
should be included into dzevents params
Re: increase or decrease of temperature
Posted: Friday 03 November 2023 20:06
by bitzy
can someone explain how the trend is set in domoticz? after how many readings is the trend set? or is set after a time and the value of the temperature? how dose domoticz set the trend for a sensore temperature?
i have a sensore that is updated every 10 seconds and the trend is changing very slow.
Re: increase or decrease of temperature
Posted: Saturday 04 November 2023 0:41
by waltervl
Looking at
https://github.com/domoticz/domoticz/bl ... lculator.h it seems to be measured over an average of 30 minutes.