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!
Lua using old variable value
Moderator: leecollings
- jvdz
- Posts: 2334
- 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
When/how do you print it? Within the same script you put in the CommandArray entry?
Jos
Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
- 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
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 therednas 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!
Code: Select all
return commandArray
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- 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
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..
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..
- 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
Again; showing the script would help..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..
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- 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
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!
Now the script works like a charm!
- jvdz
- Posts: 2334
- 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
I think your issues is simply:
You do something like:
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
You do something like:
Code: Select all
commandArray = {}
commandArray['Variable:Test']='1'
print(uservariables["Test"])
return commandArray
Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
-
- 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
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.
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.
Who is online
Users browsing this forum: No registered users and 0 guests