[Solved] struggle with an uservariable

Moderator: leecollings

Post Reply
Jan Jansen
Posts: 229
Joined: Wednesday 30 April 2014 20:27
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: The Netherlands
Contact:

[Solved] struggle with an uservariable

Post by Jan Jansen »

With great pleasure I use the text sensor as described in https://www.domoticz.com/wiki/Is_it_gonna_rain (thanks Hansbit). Hereafter, the part of the script that is relevant to this topic:

Code: Select all

commandArray = {}
   minuten=30
   RainPrediction = IsItGonnaRain(minuten)
   RainmmHour=10^((RainPrediction-109)/32)

   if (RainPrediction > 20  ) then
      verw = 3
      RainPredictionText=('('..round(RainmmHour, 1)..' mm) Regen verwacht!')
   else 
      verw = 2
      RainPredictionText=('Voorlopig blijft het droog!')
   end
   
   commandArray['Variable:Neerslagverwachting']=('round(RainmmHour, 1)')
   commandArray[2] = {['UpdateDevice'] = RainTextIDX .. '|0|' .. tostring(RainPredictionText)}

return commandArray
I would like to use a user variable whose value = round (RainmmHour, 1) = the value as shown in the text sensor. In Domoticz I created a uservariable, integer. I completed the original script with the line: commandArray['Variable:Neerslagverwachting']=('round(RainmmHour, 1)'). The log shows: Error: EventSystem: Error updating variable Neerslagverwachting: Not a valid integer.

Actually, I don't know exactly what I'm doing. Help is therefore appreciated, thanks in advance.
Last edited by Jan Jansen on Friday 15 June 2018 14:25, edited 1 time in total.
SweetPants

Re: struggle with an uservariable

Post by SweetPants »

Jan Jansen wrote: Saturday 02 June 2018 14:08 With great pleasure I use the text sensor as described in https://www.domoticz.com/wiki/Is_it_gonna_rain (thanks Hansbit). Hereafter, the part of the script that is relevant to this topic:

Code: Select all

commandArray = {}
   minuten=30
   RainPrediction = IsItGonnaRain(minuten)
   RainmmHour=10^((RainPrediction-109)/32)

   if (RainPrediction > 20  ) then
      verw = 3
      RainPredictionText=('('..round(RainmmHour, 1)..' mm) Regen verwacht!')
   else 
      verw = 2
      RainPredictionText=('Voorlopig blijft het droog!')
   end
   
   commandArray['Variable:Neerslagverwachting']=('round(RainmmHour, 1)')
   commandArray[2] = {['UpdateDevice'] = RainTextIDX .. '|0|' .. tostring(RainPredictionText)}

return commandArray
I would like to use a user variable whose value = round (RainmmHour, 1) = the value as shown in the text sensor. In Domoticz I created a uservariable, integer. I completed the original script with the line: commandArray['Variable:Neerslagverwachting']=('round(RainmmHour, 1)'). The log shows: Error: EventSystem: Error updating variable Neerslagverwachting: Not a valid integer.

Actually, I don't know exactly what I'm doing. Help is therefore appreciated, thanks in advance.
Have you tried tonumber(('round(RainmmHour, 1)') already?
Jan Jansen
Posts: 229
Joined: Wednesday 30 April 2014 20:27
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: The Netherlands
Contact:

Re: struggle with an uservariable

Post by Jan Jansen »

@Sweetpants,

Thanks for your quick reply. Your suggestion: commandArray['Variable:Neerslagverwachting']=tonumber(('round(RainmmHour, 1)') gives an error>>
Error: EventSystem: in /home/pi/domoticz/scripts/lua/script_time_regentekst.lua: /home/pi/domoticz/scripts/lua/script_time_regentekst.lua:63: ')' expected (to close '(' at line 62) near 'commandArray'

I also tried with: commandArray['Variable:Neerslagverwachting']=tonumber('round(RainmmHour, 1)') >> no errors in the log, but also no update of the uservariable.
SweetPants

Re: struggle with an uservariable

Post by SweetPants »

Jan Jansen wrote: Saturday 02 June 2018 15:40 @Sweetpants,

Thanks for your quick reply. Your suggestion: commandArray['Variable:Neerslagverwachting']=tonumber(('round(RainmmHour, 1)') gives an error>>
Error: EventSystem: in /home/pi/domoticz/scripts/lua/script_time_regentekst.lua: /home/pi/domoticz/scripts/lua/script_time_regentekst.lua:63: ')' expected (to close '(' at line 62) near 'commandArray'

I also tried with: commandArray['Variable:Neerslagverwachting']=tonumber('round(RainmmHour, 1)') >> no errors in the log, but also no update of the uservariable.
Hmm, try round(RainmmHour, 1)
Jan Jansen
Posts: 229
Joined: Wednesday 30 April 2014 20:27
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: The Netherlands
Contact:

Re: struggle with an uservariable

Post by Jan Jansen »

SweetPants wrote: Saturday 02 June 2018 16:02
Hmm, try round(RainmmHour, 1)
round(RainmmHour, 1) >>> log shows Error: EventSystem: commandArray in script /home/pi/domoticz/scripts/lua/script_time_regentekst.lua should only return ['string']='actionstring' or [integer]={['string']='actionstring'}

On the forum I searched for ['string']='actionstring' or [integer]={['string']='actionstring'}
>> I found http://www.domoticz.com/forum/viewtopic ... %7D#p93877.

commandArray['Variable:Neerslagverwachting']=tostring(round(RainmmHour, 1)) >> no errors and the variable is updated to the current value (= 0 at the time). I changed the variable type from integer to float and it works

Thanks to SweetPants and Jos
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest