dzVents: How to round notification value

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
fjuppe
Posts: 42
Joined: Thursday 14 September 2023 19:32
Target OS: Raspberry Pi / ODroid
Domoticz version: 16341
Location: Stockholm
Contact:

dzVents: How to round notification value

Post 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......
User avatar
waltervl
Posts: 6689
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2025.1
Location: NL
Contact:

Re: dzVents: How to round notification value

Post 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))
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
fjuppe
Posts: 42
Joined: Thursday 14 September 2023 19:32
Target OS: Raspberry Pi / ODroid
Domoticz version: 16341
Location: Stockholm
Contact:

Re: dzVents: How to round notification value

Post 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 !
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest