I want avgtemp with two decimal places  [Solved]

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

Moderator: leecollings

Post Reply
besix
Posts: 99
Joined: Friday 25 January 2019 11:33
Target OS: Linux
Domoticz version: beta
Location: Poland
Contact:

I want avgtemp with two decimal places

Post by besix »

A simple script gives me the average of two sensors

Code: Select all

return {
   on = { timer = { 'every 2 minutes' }},      

   execute = function(dz, item)
       
       local Temp1 = dz.devices('Temp Salon').temperature
       local Temp2 = dz.devices('Temp Biuro').temperature
       local Tempavg = (Temp1+Temp2)/2
         dz.devices('Temp Srednia').updateTemperature(Tempavg)
         dz.log('Średnia wyliczona temperatura: ' .. Tempavg, dz.LOG_INFO) 
   end
}   
I get the result as in the logs

Code: Select all

2019-12-23 12:58:00.359 Status: dzVents: Info: ------ Start internal script: Srednia:, trigger: every 2 minutes
2019-12-23 12:58:00.362 Status: dzVents: Info: Średnia wyliczona temperatura: 21.529999732971
2019-12-23 12:58:00.362 Status: dzVents: Info: ------ Finished Srednia
how to make the result be e.g. 21.53? What I do below does not work

Code: Select all

return {
   on = { timer = { 'every 2 minutes' }},      

   execute = function(dz, item)
       
       local Temp1 = dz.devices('Temp Salon').temperature
       local Temp2 = dz.devices('Temp Biuro').temperature
       local decimals = 2
       local Tempavg = ((Temp1+Temp2)/2).decimals
         dz.devices('Temp Srednia').updateTemperature(Tempavg)
         dz.log('Średnia wyliczona temperatura: ' .. Tempavg, dz.LOG_INFO) 
   end
}    
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: I want avgtemp with two decimal places

Post by waaren »

besix wrote: Monday 23 December 2019 14:03 A simple script gives me the average of two sensors
how to make the result be e.g. 21.53? What I do below does not work
Almost as simple..

Code: Select all

return {
   on = { timer = { 'every 2 minutes' }},      

   execute = function(dz, item)
       
       local Temp1 = dz.devices('Temp Salon').temperature
       local Temp2 = dz.devices('Temp Biuro').temperature
       local decimals = 2
       local Tempavg = dz.utils.round((Temp1 + Temp2 ) / 2 , decimals)
       dz.devices('Temp Srednia').updateTemperature(Tempavg)
       dz.log('Średnia wyliczona temperatura: ' .. Tempavg, dz.LOG_INFO) 
   end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
besix
Posts: 99
Joined: Friday 25 January 2019 11:33
Target OS: Linux
Domoticz version: beta
Location: Poland
Contact:

Re: I want avgtemp with two decimal places  [Solved]

Post by besix »

Yes it is Thank you
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest