increase or decrease of temperature

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
User avatar
jacobsentertainment
Posts: 211
Joined: Thursday 01 October 2020 1:47
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021-1
Location: Not @ home
Contact:

increase or decrease of temperature

Post 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.
User avatar
waltervl
Posts: 5148
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: increase or decrease of temperature

Post 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.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
User avatar
waltervl
Posts: 5148
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: increase or decrease of temperature

Post 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
}
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
thomasbaetge
Posts: 153
Joined: Wednesday 02 October 2019 11:47
Target OS: Linux
Domoticz version: 2023.1
Location: DE / BY / LT
Contact:

Re: increase or decrease of temperature

Post 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..?
User avatar
jacobsentertainment
Posts: 211
Joined: Thursday 01 October 2020 1:47
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021-1
Location: Not @ home
Contact:

Re: increase or decrease of temperature

Post by jacobsentertainment »

Cheers Walter :D 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
}
User avatar
jacobsentertainment
Posts: 211
Joined: Thursday 01 October 2020 1:47
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021-1
Location: Not @ home
Contact:

Re: increase or decrease of temperature

Post by jacobsentertainment »

Sure I do something wrong here :oops: 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.
User avatar
waltervl
Posts: 5148
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: increase or decrease of temperature

Post 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)?
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
User avatar
jacobsentertainment
Posts: 211
Joined: Thursday 01 October 2020 1:47
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021-1
Location: Not @ home
Contact:

Re: increase or decrease of temperature

Post 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.
User avatar
waltervl
Posts: 5148
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: increase or decrease of temperature

Post 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.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
User avatar
jacobsentertainment
Posts: 211
Joined: Thursday 01 October 2020 1:47
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021-1
Location: Not @ home
Contact:

Re: increase or decrease of temperature

Post by jacobsentertainment »

Ill try to have a look in to this this week, currently back on job and away from home.
User avatar
jacobsentertainment
Posts: 211
Joined: Thursday 01 October 2020 1:47
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021-1
Location: Not @ home
Contact:

Re: increase or decrease of temperature

Post 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 :?
User avatar
waltervl
Posts: 5148
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: increase or decrease of temperature

Post 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
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
User avatar
jacobsentertainment
Posts: 211
Joined: Thursday 01 October 2020 1:47
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021-1
Location: Not @ home
Contact:

Re: increase or decrease of temperature

Post 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 :D

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 :D
ayasystems
Posts: 66
Joined: Tuesday 19 April 2016 23:37
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: increase or decrease of temperature

Post by ayasystems »

should be included into dzevents params
bitzy
Posts: 33
Joined: Tuesday 18 April 2023 8:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Contact:

Re: increase or decrease of temperature

Post 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.
User avatar
waltervl
Posts: 5148
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: increase or decrease of temperature

Post by waltervl »

Looking at https://github.com/domoticz/domoticz/bl ... lculator.h it seems to be measured over an average of 30 minutes.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest