dzVents Not Handling Temperatures Correctly

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

Moderator: leecollings

Post Reply
dpcreel
Posts: 44
Joined: Friday 25 November 2016 14:30
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

dzVents Not Handling Temperatures Correctly

Post by dpcreel »

This may be a problem on my end but I could't find a solution here. I just may be missing something. I am using beta version 8057 (Fahrenheit scale) on a pi3 with some zwave & MySensors devices and just started to use dzVent scripts. The issue is when I ran this code:

Just a note: The temperature data comes from a MySensors node that I have set up to give me the temperatures of my drinking hot water, water heater flue temp, HVAC Supply Air Temp, HVAC Return Air Temp and the local space temp. I wanted to get a delta on the HVAC temp sensors. MySensors sends the temperatures to Domoticz in the Celcius scale and Domoticz converts it Fahrenheit. All worked well for the past two years until I started testing dzVents.

Code: Select all

--[[
	Assume you have two temperature sensors and a third dummy sensor that should be the
	difference of these two sensors (e.g. you want to see the difference between water temperature
	going into a radiator and the temperature of the water going out of it
]]--


return {
	active = true,
	on = {
		['timer'] = {'every minute'}
	},
	execute = function(domoticz)
		local inTemp = domoticz.devices('HVAC Return Air Temp').temperature
		local outTemp = domoticz.devices('HVAC Supply Air Temp').temperature
		local delta = math.abs(outTemp - inTemp) -- how much did the temperature change?
		-- update the dummy sensor
		domoticz.devices('HVAC Delta').updateTemperature(delta)

	end
}
The dummy temperature sensor (HVAC Delta) in Domoticz was reading 39.5 degF however I knew that the delta was more like 4 degF. It looked liked somewhere along the way of the data going through Domoticz, it thought the delta (4) was in Celsius. Thus it re-calculated it back to Fahrenheit when actually it was already in the Fahrenheit scale. So I change the code to this to correct the issue.

Code: Select all

--[[
	Assume you have two temperature sensors and a third dummy sensor that should be the
	difference of these two sensors (e.g. you want to see the difference between water temperature
	going into a radiator and the temperature of the water going out of it
]]--


return {
	active = true,
	on = {
		['timer'] = {'every minute'}
	},
	execute = function(domoticz)
		local inTemp = domoticz.devices('HVAC Return Air Temp').temperature
		local outTemp = domoticz.devices('HVAC Supply Air Temp').temperature
		local delta = math.abs(outTemp - inTemp) -- how much did the temperature change?
		delta = (delta - 32) / 1.8
		-- update the dummy sensor
		domoticz.devices('HVAC Delta').updateTemperature(delta)

	end
}
After this change the dummy sensor displayed the correct value of 4.2. Is this a bug, I this me doing something wrong, please let me know what I am missing.
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: dzVents Not Handling Temperatures Correctly

Post by dannybloe »

Interesting situation. It is certainly not you doing something wrong. dzVents gets the data from Domoticz and that's what's linked to the device object. So it must be going wrong in the preparation of that data. Just to make sure this is indeed the case, could you put dzVents in debug mode (settings > other). At least for the period of one dzVents script being called. Then you can disable the debug logging mode again. In the folder /path/to/domoticz/scripts/dzVents there should be a file created domoticzData.lua. That holds all the data that is coming from Domoticz. Could you email me that file (it has no security sensitive info) to danny at bloemeland point nl?
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
dpcreel
Posts: 44
Joined: Friday 25 November 2016 14:30
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: dzVents Not Handling Temperatures Correctly

Post by dpcreel »

Certainly. I'm at work right now, when I get home I do what you asked.
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: dzVents Not Handling Temperatures Correctly

Post by dannybloe »

I think I have found the problem. When you update your temperature devices you always have to do it in Celcius. Apparently that's how the domoticz api works. What I can do is add a couple of helper methods to the domoticz object like domoticz.celciusToFahrenheit() and vice versa.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
dpcreel
Posts: 44
Joined: Friday 25 November 2016 14:30
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: dzVents Not Handling Temperatures Correctly

Post by dpcreel »

All of the temperature data that is send to Domoticz from MySensors is in Celsius. I put some print statements in the code to see the output from "delta". It is in Fahrenheit, but the data MySensors is sending to Domoticz is C. That make sense why the double conversion to F. F in the domoticz.data statement, F in the output (delta), and another conversion somewhere along the way from C to F. Thanks for all your help, I emailed you the file you requested. To make it work I had to do a F-C conversion on "delta".
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: dzVents Not Handling Temperatures Correctly

Post by dannybloe »

In the upcoming 2.0.1 release I have added a toCelsius() method on the domoticz object and adjusted the documentation. Thanks for reporting.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
dpcreel
Posts: 44
Joined: Friday 25 November 2016 14:30
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: dzVents Not Handling Temperatures Correctly

Post by dpcreel »

Thanks so much.

There is one thing I'd like to add if I may from what I have learned by going through this. One would think if you subtracted two F numbers the output would convert to the same as if you subtracted two C numbers. But it's not.

Example: 100C-0C=100C or 212F but if you did 212F-32F=180F or 82.2C (boiling and freezing temps of water), they're not the same.
Example: 20C-15C=5C or 41F but if you did 68F-59F=9F or -12.7C

As you see they the equations don't equal. So whats up?

What I have found is that if your source numbers are in C and you want an result in F, you must convert the individual numbers first to F then do the math. If your source numbers are in F and you want a result in C, one must convert the individual number to C first then do the math.

Domoticz cannot convert the result of your math further ie. when it gets to a dummy sensor. Does it?
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: dzVents Not Handling Temperatures Correctly

Post by dannybloe »

Well, if you do this: 68F-59F=9F then you cannot convert 9F using the formula ((f-32) / 1.8) as that is for conversion along the temperature scale. You have to calculate with differences: A temperature difference of 1C is the equivalent of a temperature difference 1.8F. Or 1F == 0.56C. So if you have a difference of 9F that is exactly 5C. So there you have it. :)
I added a flag the the new toCelsius() method on the domoticz object. If you do: domoticz.toCelsius(18, true) you will get 10C as 18F==10C (relatively speaking). This will be in 2.0.1 when it's ready.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
dpcreel
Posts: 44
Joined: Friday 25 November 2016 14:30
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: dzVents Not Handling Temperatures Correctly

Post by dpcreel »

Thanks so much for the clarification. But isn't 18F = -7.7C? Or is domoticz.toCelcius for temperature differences only. Thanks.

Another questions if I may and it is out of the current topic we were talking about but it is has to do with dzVents. Should I start another Topic?
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: dzVents Not Handling Temperatures Correctly

Post by dannybloe »

dpcreel wrote:Thanks so much for the clarification. But isn't 18F = -7.7C? Or is domoticz.toCelcius for temperature differences only. Thanks.
Clearly my clarification wasn't that much of a clarification for you :P . You have two type of conversions:
  • Absolute, from a place on the Celsius thermometer to a corresponding place on the Fahrenheit thermometer. In this case, when you look at 18F you will find it at -7.7C on the Celsius thermometer. You can do something similar to a Kelvin thermometer.
  • Relative, 1F == 0.56C. That means that if you have an increase in temperature of 1F that is equivalent of the increase of 0.56C. So if you have 10F increase, you have an increase of 5.6C. At this point it is irrelevant where on the thermometer this happens. It is relative.
The helper function I just added can do both types:
domoticz.toCelsius(100, false) = 37.8 -- absolute
domoticz.toCelsius(100, true) = 55.56 -- relative ( = how much is an increase in 100F in Celsius?)
dpcreel wrote:Another questions if I may and it is out of the current topic we were talking about but it is has to do with dzVents. Should I start another Topic?
Yes please.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
dpcreel
Posts: 44
Joined: Friday 25 November 2016 14:30
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: dzVents Not Handling Temperatures Correctly

Post by dpcreel »

Thanks so much for the clarification, your time and patience.
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: dzVents Not Handling Temperatures Correctly

Post by dannybloe »

No prob.. was an interesting question that I never thought of myself.. well, don't use Fahrenheit here so that might explain it.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest