Page 1 of 1

dzVents: How to round notification value

Posted: Saturday 07 October 2023 19:42
by fjuppe
How to correctly write the code to have the value sent in push notification ("Regn idag") rounded to one decimal, I have tried so many different ways...

Code: Select all

 execute = function(domoticz)
               if (domoticz.devices('WU: Rain').rain > domoticz.data.Raincounter1) then
               domoticz.data.Raincounter1 = domoticz.devices('WU: Rain').rain
               domoticz.notify(('Regn idag:'), domoticz.devices('WU: Rain').rain)
From log:

Code: Select all

 SendNotification = Regn idag:#2.2000000476837#0#pushover##
Newbie trying to learn dzVents......

Re: dzVents: How to round notification value

Posted: Saturday 07 October 2023 20:51
by waltervl
Did you check the Dzvents wiki and search for the round function? https://www.domoticz.com/wiki/DzVents:_ ... _scripting
round(number, [decimalPlaces]): Function. Helper function to round numbers. Default decimalPlaces is 0.
So try

Code: Select all

domoticz.notify(('Regn idag:'), domoticz.utils.round(domoticz.devices('WU: Rain').rain,1))

Re: dzVents: How to round notification value

Posted: Sunday 08 October 2023 9:32
by fjuppe
Yes, I did read it and I saw some examples, changed my code to this:

Code: Select all

execute = function(domoticz)
               if (domoticz.devices('WU: Rain').rain > domoticz.data.Raincounter1) then
               domoticz.data.Raincounter1 = domoticz.devices('WU: Rain').rain
               domoticz.notify(('Regn idag:'), round(domoticz.devices('WU: Rain').rain),1)
But I missed the fact that you must write it as "domoticz.utils.round"

Thanks a lot for your help !