variable not updated correctly
Posted: Monday 09 October 2017 20:20
Below is a script that will update the variable BurstSwitch sometimes, but not always. Who can help me figure out what is wrong?
I made this dzVent (I copied only the 'execute' part):
Expected behaviour: if the script is triggered (by switching device 46 on), the variable BurstSwitch (which is initialized to 5) will be lowered by 1, and since the same loop turns 46 on again (and triggers this same script again), this loop is continued until BurstSwitch is 0. Then BurstSwitch will be reset to 5, waiting for the next time this script is triggered.
Intended behaviour: if a device is turned on, Domoticz will send 5 on-commands to ensure the signal is received (in general, my device might miss one or two on-commands, but never 5 in a row).
Observed behaviour: the variable BurstSwitch is sometimes stored correctly (by my calll domoticz.variables('BurstSwitch').set(newValue)), but not always.
This is what my log looks like:
As you can see, the 'newValue' is always 1 lower that the 'currentValue'. As expected. But somehow this newValue is not always assigned to my variable BurstSwitch. For example here:
I made this dzVent (I copied only the 'execute' part):
Code: Select all
execute = function(domoticz, roomSwitch)
if (roomSwitch.state == 'On') then
domoticz.log('---------------------------------- Switch 46 has been turned on')
domoticz.log(domoticz.variables('BurstSwitch').value)
if (domoticz.variables('BurstSwitch').value > 0) then
domoticz.log('---------------------------------- begin minus 1 loop')
currentValue = domoticz.variables('BurstSwitch').value
domoticz.log('currentValue is:')
domoticz.log(currentValue)
newValue = currentValue - 1
domoticz.log('newValue is:')
domoticz.log(newValue)
domoticz.variables('BurstSwitch').set(newValue)
domoticz.log(domoticz.variables('BurstSwitch').value)
domoticz.devices(46).switchOn()
domoticz.log('---------------------------------- end of minus 1 loop')
end
domoticz.devices(46).switchOff().afterSec(5)
if (domoticz.variables('BurstSwitch').value == 0) then
domoticz.variables('BurstSwitch').set('5')
domoticz.log('---------------------------------- reset to 5')
domoticz.log(domoticz.variables('BurstSwitch').value)
end
end
end
Intended behaviour: if a device is turned on, Domoticz will send 5 on-commands to ensure the signal is received (in general, my device might miss one or two on-commands, but never 5 in a row).
Observed behaviour: the variable BurstSwitch is sometimes stored correctly (by my calll domoticz.variables('BurstSwitch').set(newValue)), but not always.
This is what my log looks like:
Code: Select all
2017-10-09 20:00:04.259 EventSystem: Script event triggered: /home/pi/domoticz/scripts/dzVents/runtime/dzVents.lua
2017-10-09 20:00:04.277 (RFXCOM zender) Lighting 1 (A7)
2017-10-09 20:00:04.405 dzVents: Info: Handling events for: "A7", value: "On"
2017-10-09 20:00:04.405 dzVents: Info: ------ Start internal script: dztest: Device: "A7 (RFXCOM zender)", Index: 46
2017-10-09 20:00:04.405 dzVents: Info: ---------------------------------- Switch 46 has been turned on
2017-10-09 20:00:04.406 dzVents: Info: 5
2017-10-09 20:00:04.406 dzVents: Info: ---------------------------------- begin minus 1 loop
2017-10-09 20:00:04.406 dzVents: Info: currentValue is:
2017-10-09 20:00:04.406 dzVents: Info: 5
2017-10-09 20:00:04.406 dzVents: Info: newValue is:
2017-10-09 20:00:04.406 dzVents: Info: 4
2017-10-09 20:00:04.407 dzVents: Info: 5
2017-10-09 20:00:04.407 dzVents: Info: ---------------------------------- end of minus 1 loop
2017-10-09 20:00:04.407 dzVents: Info: ------ Finished dztest
2017-10-09 20:00:04.407 EventSystem: Fetching url...
2017-10-09 20:00:04.409 EventSystem: Script event triggered: /home/pi/domoticz/scripts/dzVents/runtime/dzVents.lua
2017-10-09 20:00:04.425 (RFXCOM zender) Lighting 1 (A7)
2017-10-09 20:00:04.653 dzVents: Info: Handling events for: "A7", value: "On"
2017-10-09 20:00:04.653 dzVents: Info: ------ Start internal script: dztest: Device: "A7 (RFXCOM zender)", Index: 46
2017-10-09 20:00:04.653 dzVents: Info: ---------------------------------- Switch 46 has been turned on
2017-10-09 20:00:04.654 dzVents: Info: 4
2017-10-09 20:00:04.654 dzVents: Info: ---------------------------------- begin minus 1 loop
2017-10-09 20:00:04.654 dzVents: Info: currentValue is:
2017-10-09 20:00:04.654 dzVents: Info: 4
2017-10-09 20:00:04.654 dzVents: Info: newValue is:
2017-10-09 20:00:04.654 dzVents: Info: 3
2017-10-09 20:00:04.654 dzVents: Info: 4
2017-10-09 20:00:04.654 dzVents: Info: ---------------------------------- end of minus 1 loop
2017-10-09 20:00:04.655 dzVents: Info: ------ Finished dztest
2017-10-09 20:00:04.655 EventSystem: Fetching url...
2017-10-09 20:00:04.656 EventSystem: Script event triggered: /home/pi/domoticz/scripts/dzVents/runtime/dzVents.lua
2017-10-09 20:00:04.673 (RFXCOM zender) Lighting 1 (A7)
2017-10-09 20:00:04.900 dzVents: Info: Handling events for: "A7", value: "On"
2017-10-09 20:00:04.900 dzVents: Info: ------ Start internal script: dztest: Device: "A7 (RFXCOM zender)", Index: 46
2017-10-09 20:00:04.900 dzVents: Info: ---------------------------------- Switch 46 has been turned on
2017-10-09 20:00:04.901 dzVents: Info: 4
2017-10-09 20:00:04.901 dzVents: Info: ---------------------------------- begin minus 1 loop
2017-10-09 20:00:04.901 dzVents: Info: currentValue is:
2017-10-09 20:00:04.901 dzVents: Info: 4
2017-10-09 20:00:04.901 dzVents: Info: newValue is:
2017-10-09 20:00:04.901 dzVents: Info: 3
2017-10-09 20:00:04.901 dzVents: Info: 4
2017-10-09 20:00:04.901 dzVents: Info: ---------------------------------- end of minus 1 loop
2017-10-09 20:00:04.901 dzVents: Info: ------ Finished dztest
2017-10-09 20:00:04.902 EventSystem: Fetching url...
2017-10-09 20:00:04.903 EventSystem: Script event triggered: /home/pi/domoticz/scripts/dzVents/runtime/dzVents.lua
2017-10-09 20:00:04.920 (RFXCOM zender) Lighting 1 (A7)
2017-10-09 20:00:05.149 dzVents: Info: Handling events for: "A7", value: "On"
2017-10-09 20:00:05.150 dzVents: Info: ------ Start internal script: dztest: Device: "A7 (RFXCOM zender)", Index: 46
2017-10-09 20:00:05.150 dzVents: Info: ---------------------------------- Switch 46 has been turned on
2017-10-09 20:00:05.150 dzVents: Info: 3
2017-10-09 20:00:05.150 dzVents: Info: ---------------------------------- begin minus 1 loop
2017-10-09 20:00:05.151 dzVents: Info: currentValue is:
2017-10-09 20:00:05.151 dzVents: Info: 3
2017-10-09 20:00:05.151 dzVents: Info: newValue is:
2017-10-09 20:00:05.151 dzVents: Info: 2
2017-10-09 20:00:05.151 dzVents: Info: 3
2017-10-09 20:00:05.151 dzVents: Info: ---------------------------------- end of minus 1 loop
2017-10-09 20:00:05.151 dzVents: Info: ------ Finished dztest
2017-10-09 20:00:05.151 EventSystem: Fetching url...
2017-10-09 20:00:05.153 EventSystem: Script event triggered: /home/pi/domoticz/scripts/dzVents/runtime/dzVents.lua
2017-10-09 20:00:05.171 (RFXCOM zender) Lighting 1 (A7)
2017-10-09 20:00:05.401 dzVents: Info: Handling events for: "A7", value: "On"
2017-10-09 20:00:05.402 dzVents: Info: ------ Start internal script: dztest: Device: "A7 (RFXCOM zender)", Index: 46
2017-10-09 20:00:05.402 dzVents: Info: ---------------------------------- Switch 46 has been turned on
2017-10-09 20:00:05.402 dzVents: Info: 3
2017-10-09 20:00:05.402 dzVents: Info: ---------------------------------- begin minus 1 loop
2017-10-09 20:00:05.402 dzVents: Info: currentValue is:
2017-10-09 20:00:05.402 dzVents: Info: 3
2017-10-09 20:00:05.403 dzVents: Info: newValue is:
2017-10-09 20:00:05.403 dzVents: Info: 2
2017-10-09 20:00:05.403 dzVents: Info: 3
2017-10-09 20:00:05.403 dzVents: Info: ---------------------------------- end of minus 1 loop
2017-10-09 20:00:05.403 dzVents: Info: ------ Finished dztest
2017-10-09 20:00:05.403 EventSystem: Fetching url...
2017-10-09 20:00:05.405 EventSystem: Script event triggered: /home/pi/domoticz/scripts/dzVents/runtime/dzVents.lua
2017-10-09 20:00:05.423 (RFXCOM zender) Lighting 1 (A7)
2017-10-09 20:00:06.160 dzVents: Info: Handling events for: "A7", value: "On"
2017-10-09 20:00:06.168 dzVents: Info: ------ Start internal script: dztest: Device: "A7 (RFXCOM zender)", Index: 46
2017-10-09 20:00:06.168 dzVents: Info: ---------------------------------- Switch 46 has been turned on
2017-10-09 20:00:06.169 dzVents: Info: 1
2017-10-09 20:00:06.169 dzVents: Info: ---------------------------------- begin minus 1 loop
2017-10-09 20:00:06.169 dzVents: Info: currentValue is:
2017-10-09 20:00:06.169 dzVents: Info: 1
2017-10-09 20:00:06.169 dzVents: Info: newValue is:
2017-10-09 20:00:06.169 dzVents: Info: 0
2017-10-09 20:00:06.169 dzVents: Info: 1
2017-10-09 20:00:06.169 dzVents: Info: ---------------------------------- end of minus 1 loop
2017-10-09 20:00:06.170 dzVents: Info: ------ Finished dztest
2017-10-09 20:00:06.170 EventSystem: Fetching url...
2017-10-09 20:00:06.172 EventSystem: Script event triggered: /home/pi/domoticz/scripts/dzVents/runtime/dzVents.lua
2017-10-09 20:00:06.190 (RFXCOM zender) Lighting 1 (A7)
2017-10-09 20:00:06.420 dzVents: Info: Handling events for: "A7", value: "On"
2017-10-09 20:00:06.421 dzVents: Info: ------ Start internal script: dztest: Device: "A7 (RFXCOM zender)", Index: 46
2017-10-09 20:00:06.421 dzVents: Info: ---------------------------------- Switch 46 has been turned on
2017-10-09 20:00:06.421 dzVents: Info: 1
2017-10-09 20:00:06.421 dzVents: Info: ---------------------------------- begin minus 1 loop
2017-10-09 20:00:06.421 dzVents: Info: currentValue is:
2017-10-09 20:00:06.421 dzVents: Info: 1
2017-10-09 20:00:06.421 dzVents: Info: newValue is:
2017-10-09 20:00:06.422 dzVents: Info: 0
2017-10-09 20:00:06.422 dzVents: Info: 1
2017-10-09 20:00:06.422 dzVents: Info: ---------------------------------- end of minus 1 loop
2017-10-09 20:00:06.422 dzVents: Info: ------ Finished dztest
2017-10-09 20:00:06.422 EventSystem: Fetching url...
2017-10-09 20:00:06.424 EventSystem: Script event triggered: /home/pi/domoticz/scripts/dzVents/runtime/dzVents.lua
2017-10-09 20:00:06.442 (RFXCOM zender) Lighting 1 (A7)
2017-10-09 20:00:06.673 dzVents: Info: Handling events for: "A7", value: "On"
2017-10-09 20:00:06.673 dzVents: Info: ------ Start internal script: dztest: Device: "A7 (RFXCOM zender)", Index: 46
2017-10-09 20:00:06.673 dzVents: Info: ---------------------------------- Switch 46 has been turned on
2017-10-09 20:00:06.674 dzVents: Info: 0
2017-10-09 20:00:06.674 dzVents: Info: ---------------------------------- reset to 5
2017-10-09 20:00:06.674 dzVents: Info: 0
2017-10-09 20:00:06.674 dzVents: Info: ------ Finished dztest
2017-10-09 20:00:06.675 EventSystem: Fetching url...
2017-10-09 20:00:06.676 EventSystem: Script event triggered: /home/pi/domoticz/scripts/dzVents/runtime/dzVents.lua
2017-10-09 20:00:06.693 (RFXCOM zender) Lighting 1 (A7)
2017-10-09 20:00:11.841 dzVents: Info: Handling events for: "A7", value: "Off"
2017-10-09 20:00:11.841 dzVents: Info: ------ Start internal script: dztest: Device: "A7 (RFXCOM zender)", Index: 46
2017-10-09 20:00:11.841 dzVents: Info: ------ Finished dztest
Code: Select all
2017-10-09 20:00:06.421 dzVents: Info: ------ Start internal script: dztest: Device: "A7 (RFXCOM zender)", Index: 46
2017-10-09 20:00:06.421 dzVents: Info: ---------------------------------- Switch 46 has been turned on >>>> general note that the script has started
2017-10-09 20:00:06.421 dzVents: Info: 1 >>>> current value of BurstSwitch
2017-10-09 20:00:06.421 dzVents: Info: ---------------------------------- begin minus 1 loop
2017-10-09 20:00:06.421 dzVents: Info: currentValue is:
2017-10-09 20:00:06.421 dzVents: Info: 1 >>>> current value of BurstSwitch
2017-10-09 20:00:06.421 dzVents: Info: newValue is:
2017-10-09 20:00:06.422 dzVents: Info: 0 >>>> current value of newValue
2017-10-09 20:00:06.422 dzVents: Info: 1 >>>> current value of BurstSwitch (expected: 0)