Round function - Help needed

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

Moderator: leecollings

Post Reply
areg
Posts: 7
Joined: Sunday 13 January 2019 9:57
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Round function - Help needed

Post by areg »

Hi,
I need to use the round function to round the PM2.5 value to an integer.
I used code:

Code: Select all

rreturn {
	on = {
		devices = {'airly'},
	
	},
	
	execute = domoticz.round('PM2,5 Norma',0)

	end 

}
However, it does not work.
Device name: Airly
Value: Pm2.5 Norma

Please, tell me what I'm doing wrong.
Thanks
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Round function - Help needed

Post by jvdz »

I would assume the round function needs a value and you are feeding it with a sting which also contains regular characters.

Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Round function - Help needed

Post by waaren »

areg wrote: Sunday 13 January 2019 10:09 I need to use the round function to round the PM2.5 value to an integer.
Please, tell me what I'm doing wrong.
Thanks
Please begin with reading the introduction and getting started of the wiki
After that try this

Code: Select all

return {
   on = {
      devices = {
         'airly'}
      }
   },
   
   execute = function(domoticz, item)
      if (item.state == 'On') then
         domoticz.log('Hey! I am on!')
         domoticz.log('rounding now 2.23435 to 2 decimals .... : ' .. domoticz.utils.round(2.23435,2))
      else
         domoticz.log('Hey! I am off! ; No rounding today')
      end
   end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
areg
Posts: 7
Joined: Sunday 13 January 2019 9:57
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Round function - Help needed

Post by areg »

Thank you I will try!
areg
Posts: 7
Joined: Sunday 13 January 2019 9:57
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Round function - Help needed

Post by areg »

Holy crap, doesn't work :)
Can anyone help?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Round function - Help needed

Post by waaren »

areg wrote: Sunday 13 January 2019 18:36 Holy crap, doesn't work :)
Can anyone help?
Can you show what's in the log ? And try this one.

Code: Select all

return {
   on = { devices = { 'airly'}},
   
   execute = function(domoticz, item)
      if (item.state == 'On') then
         domoticz.log('Hey! I am on!')
         domoticz.log('rounding now 2.23435 to 2 decimals .... : ' .. domoticz.utils.round(2.23435,2),domoticz.LOG_FORCE)
      else
         domoticz.log('Hey! I am off! ; No rounding today',domoticz.LOG_FORCE)
      end
   end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
areg
Posts: 7
Joined: Sunday 13 January 2019 9:57
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Round function - Help needed

Post by areg »

Script
Image
and logs
Image

it doesn't show any errors but it doesn't work
I will add that data from airly is sent via http to the Nextion display.
areg
Posts: 7
Joined: Sunday 13 January 2019 9:57
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Round function - Help needed

Post by areg »

I need the data from the first row (25,0)to be sent in the second row as a whole number (25).
Image

Image

This is the way values without rounding are displayed.
areg
Posts: 7
Joined: Sunday 13 January 2019 9:57
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Round function - Help needed

Post by areg »

Is it possible to do?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Round function - Help needed

Post by waaren »

areg wrote: Monday 14 January 2019 12:33 Is it possible to do?
It is not clear to me what you want to do based on the information you provided. Is this value that you want to round in a device or in a variable and where do you want the converted value. In the log, -in a device or in a uservar.
Please elaborate.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
areg
Posts: 7
Joined: Sunday 13 January 2019 9:57
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Round function - Help needed

Post by areg »

I want the percentage value of PM2.5 (airly, unit 11)to be sent after rounded via http. Currently it is eg 32.00 and I need 32.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 1 guest