Page 1 of 1

Round function - Help needed

Posted: Sunday 13 January 2019 10:09
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

Re: Round function - Help needed

Posted: Sunday 13 January 2019 11:09
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

Re: Round function - Help needed

Posted: Sunday 13 January 2019 11:11
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
}

Re: Round function - Help needed

Posted: Sunday 13 January 2019 11:51
by areg
Thank you I will try!

Re: Round function - Help needed

Posted: Sunday 13 January 2019 18:36
by areg
Holy crap, doesn't work :)
Can anyone help?

Re: Round function - Help needed

Posted: Sunday 13 January 2019 19:00
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
}

Re: Round function - Help needed

Posted: Sunday 13 January 2019 20:17
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.

Re: Round function - Help needed

Posted: Sunday 13 January 2019 20:29
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.

Re: Round function - Help needed

Posted: Monday 14 January 2019 12:33
by areg
Is it possible to do?

Re: Round function - Help needed

Posted: Monday 14 January 2019 17:27
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.

Re: Round function - Help needed

Posted: Monday 14 January 2019 18:08
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.