Lua using old variable value

Moderator: leecollings

Post Reply
rednas
Posts: 132
Joined: Tuesday 20 October 2015 12:23
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Netherlands
Contact:

Lua using old variable value

Post by rednas »

Hello,

I am using a Lua script to check a variable with a date and a time.
If the date and time have passed, it runs a script and empties the variable.
However, I am printing the variable value and it still uses the old value with the date and time (shown in the log) and if I look at the variables page it shows up emtpy.
Does someone know what's happening?

Thanks!
User avatar
jvdz
Posts: 2335
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Lua using old variable value

Post by jvdz »

When/how do you print it? Within the same script you put in the CommandArray entry?

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: Lua using old variable value

Post by waaren »

rednas wrote: Thursday 02 August 2018 22:33 Hello,

I am using a Lua script to check a variable with a date and a time.
If the date and time have passed, it runs a script and empties the variable.
However, I am printing the variable value and it still uses the old value with the date and time (shown in the log) and if I look at the variables page it shows up emtpy.
Does someone know what's happening?

Thanks!
To be certain we will have to see your relevant script(s) but my guess in this case is that you print the content of the var before the

Code: Select all

return commandArray 
line. If that is how your code looks like the change of the variable simply did not happen yet as domoticz only act on the commands in the commandArray when it received the array back from your Lua
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
rednas
Posts: 132
Joined: Tuesday 20 October 2015 12:23
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Netherlands
Contact:

Re: Lua using old variable value

Post by rednas »

The script runs every minute and I print the value before "return commandArray" because I want to know what the value is before changing it offcourse.
However, the next time the script runs (when the value should be empty and it is empty in my variable tab in domoticz) it still shows the old value..
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Lua using old variable value

Post by waaren »

rednas wrote: Friday 03 August 2018 8:05 The script runs every minute and I print the value before "return commandArray" because I want to know what the value is before changing it offcourse.
However, the next time the script runs (when the value should be empty and it is empty in my variable tab in domoticz) it still shows the old value..
Again; showing the script would help..
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
rednas
Posts: 132
Joined: Tuesday 20 October 2015 12:23
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Netherlands
Contact:

Re: Lua using old variable value

Post by rednas »

Already got it to work. Looks like Domoticz doesn't like empty strings as variables or I am doing something wrong. However, I now changed the script to change the variable to a dash "-" instead of an empty string.
Now the script works like a charm!
User avatar
jvdz
Posts: 2335
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Lua using old variable value

Post by jvdz »

I think your issues is simply:
You do something like:

Code: Select all

commandArray = {}
commandArray['Variable:Test']='1'
print(uservariables["Test"])
return commandArray
That will not work as the commands you put in commandArray are handed back to the event system at the script end and will then be performed by the event system, not during execution of the script!

Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
rednas
Posts: 132
Joined: Tuesday 20 October 2015 12:23
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Netherlands
Contact:

Re: Lua using old variable value

Post by rednas »

No, that is not the case.
I am printing the ORIGINAL value and I am never printing the value I change it to.
It does work with updating my variable to a dash "-" instead of changing it to empty "".
So, it has nothing to do with the printing of the value, but with the value of the variable.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest