Page 1 of 1

I want avgtemp with two decimal places

Posted: Monday 23 December 2019 14:03
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
}    

Re: I want avgtemp with two decimal places

Posted: Monday 23 December 2019 14:57
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
}

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

Posted: Monday 23 December 2019 16:23
by besix
Yes it is Thank you