Page 1 of 1
[Solved] struggle with an uservariable
Posted: Saturday 02 June 2018 14:08
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.
Re: struggle with an uservariable
Posted: Saturday 02 June 2018 14:37
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?
Re: struggle with an uservariable
Posted: Saturday 02 June 2018 15:40
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.
Re: struggle with an uservariable
Posted: Saturday 02 June 2018 16:02
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)
Re: struggle with an uservariable
Posted: Sunday 03 June 2018 12:17
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