Calculate average temperature

Topics (not sure which fora)
when not sure where to post, post here and mods will move it to right forum.

Moderators: leecollings, remb0

Post Reply
HenkHavelaar
Posts: 9
Joined: Saturday 30 September 2017 17:13
Target OS: Linux
Domoticz version: 2020.2
Location: NL/PT
Contact:

Calculate average temperature

Post by HenkHavelaar »

How do I write the average temperature from 3 outside sensors in one created dummy temperature sensor?
Domoticz on Synology NAS and Intel NUC (Linux)
Interfaces: zWave, Zigbee and RFXcom
Locations: Netherlands and Portugal
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Calculate average temperature

Post 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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
HenkHavelaar
Posts: 9
Joined: Saturday 30 September 2017 17:13
Target OS: Linux
Domoticz version: 2020.2
Location: NL/PT
Contact:

Re: Calculate average temperature

Post 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.
Domoticz on Synology NAS and Intel NUC (Linux)
Interfaces: zWave, Zigbee and RFXcom
Locations: Netherlands and Portugal
User avatar
Thuis
Posts: 251
Joined: Tuesday 11 September 2018 11:36
Target OS: Linux
Domoticz version: Beta
Location: The Netherlands
Contact:

Re: Calculate average temperature

Post 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
}
I Love Domoticz ! And the community around it :-)
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests