Page 1 of 1

Trigger based on user variable

Posted: Saturday 08 April 2017 22:12
by dakipro
Hi,
enjoying the script a lot. Would it be possible to use user variable change as a trigger?
Like the "official" blocky (lua?) has it
https://www.domoticz.com/wiki/Events
3. Event Type. Controls what events events will cause Domoticz to execute the script. Drop down values:
5.User Variable - Will run when User Variables are updated
would be very useful do "de-couple" activity using user variables.
F.ek.s isSleepingTime and isAnyoneInLivingroom (which it self could be controlled by different sensors, like pir, or ping of Tv/playstation etc.)
and if some of those changes, actions would be performed /lua would be triggered.

Or perhaps this could be achieved with "dzVents Global variables"?

Re: Trigger based on user variable

Posted: Saturday 08 April 2017 23:01
by kubrik
If you update uservariable via json, uservariable lua script will be triggered.

Code: Select all

/json.htm?type=command&param=updateuservariable&vname=USERVARIABLENAME&vtype=USERVARIABLETYPE
&vvalue=USERVARIABLEVALUE

Re: Trigger based on user variable

Posted: Wednesday 12 April 2017 8:04
by dannybloe
The problem is that Domoticz only triggers variable change events when they are changed through the UI. If a script changes this variable then no change event is emitted and dzVents cannot know it was changed.

But you could add this feature request in the dzVents tracker. Then we could use the json call when a variable is changed in dzVents instead of using the commandArray method. We could encapsulate that in the dzVents code.

Re: Trigger based on user variable

Posted: Wednesday 12 April 2017 10:00
by jannl
When I update a uservar via a perl script, as far as I know the uservariable lua script is fired. My presence detection is based on this.

Re: Trigger based on user variable

Posted: Wednesday 12 April 2017 10:02
by dannybloe
Yes, that's because you (probably) use the json way of changing the variable and that is exactly how Domoticz UI does this as well. But if you change it using the CommandArray from a Lua script it doesn't get triggered.

Re: Trigger based on user variable

Posted: Sunday 23 April 2017 10:57
by cyclops1982
Hi,

I was wondering if there's an update on this?
The reason i'm asking is that i don't like adding dummy switches to trigger events based on other lua scripts. I'm doing the Alarm Setup, and i just don't like the dummy switches for that.
Then, the user variables can be updated using JSON, but now i need to hardcode the URL and a username+password.
I come from a developer background and it's just not fantastic to use dummy switches or hardcode values into the script. It would be tons better if uservariables that are updated from Lua would trigger events as well or if we had control over that.
There could be a separate array to say 'these updated variables need to trigger events'. For example instead of "commandArray['Variable:myVar'] = '1'" have a "commandArray['VariableTrigger:myVar'] = '1'".

This way we give the developer of the scripts the control.

Any feedback is welcome! :-)

Re: Trigger based on user variable

Posted: Saturday 13 May 2017 10:30
by poudenes
I have same issue... I have a blocky script that check some user variable. When a user variable changed using a CURL action then the script change all other user variable to 0. etc etc.

Now i want to convert this to a LUA script. Easier to manage easier to update.... But if its true that you cannot use a IF on a change user variable how is it possible that it is working in BLOCKY?

I also habe dummy switches now to do same actions, but 5 dummy switches to manage my scenes its not best way... Don't wanna see this (visible) switch variable... want them into user variable.

Re: Trigger based on user variable

Posted: Monday 15 May 2017 7:56
by dannybloe
I added this ticket. As soon as I have some extra time I will look into this.

Re: Trigger based on user variable

Posted: Saturday 29 September 2018 2:10
by greenwitch
Hi,

When do you plan to fix it?
I am on domoticz 4.97 and it is still not working.
I wanted to switch from virtual devices to variables to make my domoticz cleaner but currenty event if I change value of variable through json it does not trigger an event.

Adam

Re: Trigger based on user variable

Posted: Saturday 29 September 2018 9:40
by waaren
greenwitch wrote: Saturday 29 September 2018 2:10 I am on domoticz 4.97 and it is still not working.
I wanted to switch from virtual devices to variables to make my domoticz cleaner but currenty event if I change value of variable through json it does not trigger an event.
I am on domoticz V4.10009 (dzVents 2.4.7)
An update of a uservariable via the GUI, uservar.set() in dzVents or JSON does trigger dzVents scripts. I don't know on what version this was implemented. Also discussed here