Variable doesn't trigger script
Moderator: leecollings
-
- Posts: 3
- Joined: Wednesday 26 September 2018 10:29
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.9700
- Contact:
Variable doesn't trigger script
Hi All,
After a few days of searching I hope you can help me. I've got the following time script that updates a uservariable 'Night' with True of False:
commandArray = {}
--Haal de huidige tijd op
timenow = os.date("*t")
minutesnow = timenow.min + timenow.hour * 60
--Vergelijk de tijd met zonsondergang - 30 minuten en zet variabele Nacht op True als ze overeenkomen
if (minutesnow == timeofday['SunsetInMinutes'] - 30) then
commandArray['Variable:Nacht']='True'
end
--Vergelijk de tijd met zonsopgang - 0 minuten en zet variabele Nacht op False als ze overeenkomen
if (minutesnow == timeofday['SunriseInMinutes'] - 0) then
commandArray['Variable:Nacht']='False'
end
return commandArray
This works fine. The following uservariable script should be triggered when 'Night' is updated. The problem is that it isn't triggered:
commandArray = {}
if (uservariables['Thuis'] == 'True' and uservariables['Nacht'] == 'True') then
commandArray['Lampen bij bank']='On'
commandArray['Lamp bij tv']='On'
commandArray['Vensterbank']='On'
end
if uservariables['Thuis'] == 'False' then
commandArray['Lampen bij bank']='Off'
commandArray['Lamp bij tv']='Off'
commandArray['Vensterbank']='Off'
end
if uservariables['Nacht'] == 'False' then
commandArray['Lampen bij bank']='Off'
commandArray['Lamp bij tv']='Off'
commandArray['Vensterbank']='Off'
end
return commandArray
The other variable 'Home' is updated via API/JSON. When 'Night' is True all is fine and lights switch on.
Do you have ideas what might be the problem?
After a few days of searching I hope you can help me. I've got the following time script that updates a uservariable 'Night' with True of False:
commandArray = {}
--Haal de huidige tijd op
timenow = os.date("*t")
minutesnow = timenow.min + timenow.hour * 60
--Vergelijk de tijd met zonsondergang - 30 minuten en zet variabele Nacht op True als ze overeenkomen
if (minutesnow == timeofday['SunsetInMinutes'] - 30) then
commandArray['Variable:Nacht']='True'
end
--Vergelijk de tijd met zonsopgang - 0 minuten en zet variabele Nacht op False als ze overeenkomen
if (minutesnow == timeofday['SunriseInMinutes'] - 0) then
commandArray['Variable:Nacht']='False'
end
return commandArray
This works fine. The following uservariable script should be triggered when 'Night' is updated. The problem is that it isn't triggered:
commandArray = {}
if (uservariables['Thuis'] == 'True' and uservariables['Nacht'] == 'True') then
commandArray['Lampen bij bank']='On'
commandArray['Lamp bij tv']='On'
commandArray['Vensterbank']='On'
end
if uservariables['Thuis'] == 'False' then
commandArray['Lampen bij bank']='Off'
commandArray['Lamp bij tv']='Off'
commandArray['Vensterbank']='Off'
end
if uservariables['Nacht'] == 'False' then
commandArray['Lampen bij bank']='Off'
commandArray['Lamp bij tv']='Off'
commandArray['Vensterbank']='Off'
end
return commandArray
The other variable 'Home' is updated via API/JSON. When 'Night' is True all is fine and lights switch on.
Do you have ideas what might be the problem?
- jvdz
- Posts: 2334
- Joined: Tuesday 30 December 2014 19:25
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.107
- Location: Netherlands
- Contact:
Re: Variable doesn't trigger script
There use to be a remark in the Wiki about this, so don't know whether it has changed, but it use to be the case that UserVariable events would ONLY trigger when the uservariable was updated by a JSON call and not by a Commandarray[] action.
The remark isn't there anymore so maybe it was updated in a recent version?
My scripts still use a http request to update the variable with a JSON call to trigger the event system.
Jos
The remark isn't there anymore so maybe it was updated in a recent version?
My scripts still use a http request to update the variable with a JSON call to trigger the event system.
Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
-
- Posts: 3
- Joined: Wednesday 26 September 2018 10:29
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.9700
- Contact:
Re: Variable doesn't trigger script
Thank you! Most likely that only JSON will trigger uservariable scripts then.
How did you write your http request in the script?
I've tried different 'versions' of the following line:
But keep getting errors:
How did you write your http request in the script?
I've tried different 'versions' of the following line:
Code: Select all
commandArray['OpenURL']="http://127.0.0.1:8080/json.htm?param=updateuservariable&type=command&vname=Nacht&vtype=2&vvalue=False"
Code: Select all
2018-09-26 16:05:56.788 Error: Error opening url: http://127.0.0.1:8080/json.htm?param=updateuservariable&type=command&vname=Nacht&vtype=2&vvalue=False
- emme
- Posts: 909
- Joined: Monday 27 June 2016 11:02
- Target OS: Raspberry Pi / ODroid
- Domoticz version: latest
- Location: Milano, Italy
- Contact:
Re: Variable doesn't trigger script
look into the settings if 127.0.0.1 is in the IP whitelist
try also to open it into your browser (replacing 127.0.0.1 with the dz box ip) and post the error
try also to open it into your browser (replacing 127.0.0.1 with the dz box ip) and post the error
The most dangerous phrase in any language is:
"We always done this way"
"We always done this way"
- jvdz
- Posts: 2334
- Joined: Tuesday 30 December 2014 19:25
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.107
- Location: Netherlands
- Contact:
Re: Variable doesn't trigger script
Try this variant without the http:// prefix:
Jos
Code: Select all
commandArray['OpenURL'] = "127.0.0.1:8080/json.htm?type=command¶m=updateuservariable&vname=Nacht&vtype=2&vvalue=False"
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: Variable doesn't trigger script
I just tested this with a Lua and with a dzVents script. The Lua script (using commandArray) does not trigger an event. The dzVents script does.jvdz wrote: ↑Wednesday 26 September 2018 11:52 There use to be a remark in the Wiki about this, so don't know whether it has changed, but it use to be the case that UserVariable events would ONLY trigger when the uservariable was updated by a JSON call and not by a Commandarray[] action.
The remark isn't there anymore so maybe it was updated in a recent version?
My scripts still use a http request to update the variable with a JSON call to trigger the event system.
Jos
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
- jvdz
- Posts: 2334
- Joined: Tuesday 30 December 2014 19:25
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.107
- Location: Netherlands
- Contact:
Re: Variable doesn't trigger script
That is pretty strange that we aren't worried about an indefinite trigger loop in dzVents and still are with LUA.
I've already mentioned this before that I never understood why this "safeguard" was build in for uservariables. It is just a nuisance having to resort to a JSON call to update a uservariable and want to trigger subsequent events.
I vote for changing this behavior.

Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
-
- Posts: 3
- Joined: Wednesday 26 September 2018 10:29
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.9700
- Contact:
Re: Variable doesn't trigger script
Thanks for all the input guys! Whitelisting the IP did the trick.
-
- Posts: 106
- Joined: Monday 11 March 2019 0:14
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Variable doesn't trigger script
Hallo everyone!
Anny news on this?
I have a Plex script (python) witch updates my user variable, but when it changes (for example: Movie Pause) it is not triggering DzVents.
Anny news on this?
I have a Plex script (python) witch updates my user variable, but when it changes (for example: Movie Pause) it is not triggering DzVents.
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Variable doesn't trigger script
Can you change the script is such a way that it updates a virtual domoticz device ? That could trigger the dzVents script.
One way would be to use a selector switch and set it to a pre-defined level. Or just update the variable and switchOn a switch. dzVents would be triggered by the switch and read the value of the var in the body of the script.
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: 106
- Joined: Monday 11 March 2019 0:14
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Variable doesn't trigger script
The script is updating a text device, but i dont know if i can get my trigger out of it!
Sorry, im not an expert in python cripting.
Exapple:
Sorry, im not an expert in python cripting.
Exapple:
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Variable doesn't trigger script
Can you please share the Python and dzVents scripts (and please use code tags </>) related to this question here ?
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: 106
- Joined: Monday 11 March 2019 0:14
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Variable doesn't trigger script
- Spoiler: show
-
- Posts: 106
- Joined: Monday 11 March 2019 0:14
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Variable doesn't trigger script
And this is the script..
I am just started with domoticz, so hope the script is oke!?
I am just started with domoticz, so hope the script is oke!?
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Variable doesn't trigger script
Please use code tags ( use </> button in the edit window and put your code between the tags )
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
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Variable doesn't trigger script
Can you try this ?
Code: Select all
return {
on = { devices = { 'Plex_Status_Chrome' }},
logging = { level = domoticz.LOG_DEBUG,
marker = "plexTest" },
execute = function(dz)
plexVar = dz.variables('PLEX STATUS [Chrome]')
testSwitch = dz.devices('test1')
if tostring(plexVar.value) == '1' then
testSwitch.switchOn()
elseif tostring(plexVar.value) == '2' then
testSwitch.switchOff()
end
dz.log('Value of vatiable ' .. plexVar.name .. " is " .. plexVar.value,dz.log_DEBUG )
end
}
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: 106
- Joined: Monday 11 March 2019 0:14
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Variable doesn't trigger script
IT WORKS !!! amazing!!!
But.......... the script is updating every X seconds, so my log is going crazy right now.
But.......... the script is updating every X seconds, so my log is going crazy right now.
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Variable doesn't trigger script
It only means that the text sensor is updated (very) frequently. If you don't wan't to fill your log and only send a command to the switch when it should change state then adjust script to
Code: Select all
return {
on = {
devices = { 'Plex_Status_Chrome' }},
logging = { level = domoticz.LOG_ERROR,
marker = "plexTest" },
execute = function(dz)
plexVar = dz.variables('PLEX STATUS [Chrome]')
testSwitch = dz.devices('test1')
if tostring(plexVar.value) == '1' then
testSwitch.switchOn().checkFirst()
elseif tostring(plexVar.value) == '2' then
testSwitch.switchOff().checkFirst()
end
-- dz.log('Value of vatiable ' .. plexVar.name .. " is " .. plexVar.value,dz.log_DEBUG )
end
}
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
Re: Variable doesn't trigger script
Just to up the topic, just tested on very last version (2022.1) still, lua's scripts updating user variables doesn't trigger a change event.
So problem is still there on this version.
I will implement the json API response from here.
Thank you for the workaround.
Soulwax62
So problem is still there on this version.
I will implement the json API response from here.
Thank you for the workaround.
Soulwax62
Who is online
Users browsing this forum: No registered users and 1 guest