Unable to update a user variable

Moderator: leecollings

Post Reply
duodiscu92
Posts: 27
Joined: Sunday 11 February 2018 18:20
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: Montrouge, France
Contact:

Unable to update a user variable

Post by duodiscu92 »

Hi everyone,
Below is a part of my script_device code in lua where b1 and b2 are user variables
I can easily read them but I cannot change them

Code: Select all

...
b1 = 'Batterie1'
b2 = 'Batterie2'

------------------------------------------------------------------------------
commandArray = {}

if (devicechanged[actb1]) then
  print("B1 : " .. tostring(devicechanged[actb1]) .. " User VarB1 = " .. uservariables[b1])
  if( (tostring(devicechanged[actb1]) == "EN SERVICE") and (uservariables[b1] == 0) ) then
    print ("En service et B1 == 0")
    commandArray['Variable:b1'] = '1'
...
The line

Code: Select all

commandArray['Variable:b1'] = '1'
seems to be without effect

An idea ?
Thanks for your help
sieth
Posts: 33
Joined: Wednesday 15 November 2017 19:40
Target OS: Linux
Domoticz version: 2020.2
Location: Belgium
Contact:

Re: Unable to update a user variable

Post by sieth »

if b1 is a string


if( (tostring(devicechanged[actb1]) == "EN SERVICE") and (uservariables[b1] == 0) ) then
print ("En service et B1 == 0")
commandArray[#commandArray+1]={['Variable:b1'] = tostring ('1')}


or if 1b is an integer:
if( (tostring(devicechanged[actb1]) == "EN SERVICE") and (uservariables[b1] == 0) ) then
print ("En service et B1 == 0")
commandArray[#commandArray+1]={['Variable:b1'] = 1}
duodiscu92
Posts: 27
Joined: Sunday 11 February 2018 18:20
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: Montrouge, France
Contact:

Re: Unable to update a user variable

Post by duodiscu92 »

Thank you Sieth but I have found just now :

Code: Select all

commandArray['Variable:b1'] = '1'
is not allowed, because b1 is not replaced by its value which is "Batterie1"

So the good writing is :

Code: Select all

commandArray['Variable:Batterie1'] = '1'
and then it works well.
Post Reply

Who is online

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