Page 1 of 1
Calculate average temperature
Posted: Monday 07 December 2020 20:24
by HenkHavelaar
How do I write the average temperature from 3 outside sensors in one created dummy temperature sensor?
Re: Calculate average temperature
Posted: Monday 07 December 2020 20:40
by waaren
HenkHavelaar wrote: ↑Monday 07 December 2020 20:24
How do I write the average temperature from 3 outside sensors in one created dummy temperature sensor?
Using a dzVents script, it Could look like below script
__________________________________________________________________________________________________________________________
When not yet familiar with dzVents please start with reading
Get started Before implementing (~ 5 minutes). Special attention please for "In Domoticz go to Setup > Settings > Other and in the section EventSystem make sure the checkbox 'dzVents enabled' is checked. Also make sure that in the Security section in the settings you allow 127.0.0.1 to not need a password. dzVents uses that port to send certain commands to Domoticz. Finally make sure you have set your current location in Setup > Settings > System > Location, otherwise there is no way to determine nighttime/daytime state."
___________________________________________________________________________________________________________________________
Code: Select all
return
{
on =
{
timer =
{
'every minute',
},
},
logging =
{
level = domoticz.LOG_DEBUG, -- change to LOG_ERROR when all OK
marker = 'Average temperature',
},
execute = function(dz, device)
local t1 = dz.devices('temperature 1').temperature -- change text between quotes to name of your devices
local t2 = dz.devices('temperature 2').temperature
local t3 = dz.devices('temperature 3').temperature
local averageTemperature = dz.devices('Average Temperature')
averageTemperature.updateTemperature( dz.utils.round( ( ( t1 + t2 + t3 ) / 3 ) , 1 ) )
end
}
Re: Calculate average temperature
Posted: Monday 07 December 2020 20:56
by HenkHavelaar
Thanx waaren for the tips. I am going to try this after reading the tips and wiki.
Programma ingevoegd, aangepast aan eigen device namen, werkt perfect! Bedankt.
Re: Calculate average temperature
Posted: Thursday 26 September 2024 13:10
by Thuis
Hello, so i came across this script and i use it now for average of 3 temperatures.
But there is something i do not understand. The average temperature is correct but.
2 of the temperature devices are Temp,Hum and Baro. Only one device, is temperature only.
Now i call it every 2 minutes. But the sensor with only temperature gives an error in the log like:
- Spoiler: show
- Error reading switch data!
But it is not a switch? It is a sensor, or are all sensors also switches? No idea.
Now if i just disable this reading in the script and change the script to take only t2 and t3 divide by 2 then no error.
Enable the original 3 temperature devices and error.
How come? Do i need to read-out the sensor in a different way instead of ".temperature"?
Anyone has an answer? Much appreciated.
- Spoiler: show
- return
{
on =
{
timer =
{
'every 2 minutes',
},
},
logging =
{
level = domoticz.LOG_ERROR, -- change to LOG_ERROR when all OK
marker = 'Gem. Woonkamer Temp.',
},
execute = function(domoticz, device)
local t1 = domoticz.devices('Temp. Huiskamer Honeywell').temperature -- This is the device that is not THB only T. Also give the error in log
local t2 = domoticz.devices('Woonkamer - THB').temperature -- THB sensor
local t3 = domoticz.devices('Temp. Huiskamer').temperature --THB sensor
local averageTemperature = domoticz.devices('Gem. Woonkamer Temp.')
averageTemperature.updateTemperature( domoticz.utils.round( ( ( t1 + t2 + t3 ) / 3 ) , 1 ) )
end
}