Trigger based on user variable

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
dakipro
Posts: 49
Joined: Thursday 17 December 2015 22:24
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.5877
Location: Norway
Contact:

Trigger based on user variable

Post 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"?
Raspberry Pi 2 B - MySensors (dimmers, switches, motion, temperature, lux, humidity sensors)
zWave (220v switches)
various 433 via RFLink
kubrik
Posts: 47
Joined: Wednesday 30 November 2016 15:07
Target OS: Linux
Domoticz version: 2020.2
Location: Italy
Contact:

Re: Trigger based on user variable

Post 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
Ubuntu 20.04 on ACEPC AK1 (previously RPi3b+)
Z-Stick Gen5, RFXtrx433E, Philips HUE Bridge, Yeelight, ESP8266 NodeMCU, Broadlink RM
dZvents, bash, php, Node-RED
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: Trigger based on user variable

Post 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.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
jannl
Posts: 625
Joined: Thursday 02 October 2014 6:36
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Location: Geleen
Contact:

Re: Trigger based on user variable

Post 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.
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: Trigger based on user variable

Post 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.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
cyclops1982
Posts: 13
Joined: Monday 20 March 2017 13:28
Target OS: -
Domoticz version:
Contact:

Re: Trigger based on user variable

Post 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! :-)
poudenes
Posts: 667
Joined: Wednesday 08 March 2017 9:42
Target OS: Linux
Domoticz version: 3.8993
Location: Amsterdam
Contact:

Re: Trigger based on user variable

Post 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.
RPi3 B+, Debain Stretch, Domoticz, Homebridge, Dashticz, RFLink, Milight, Z-Wave, Fibaro, Nanoleaf, Nest, Harmony Hub, Now try to understand pass2php
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: Trigger based on user variable

Post by dannybloe »

I added this ticket. As soon as I have some extra time I will look into this.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
greenwitch
Posts: 24
Joined: Saturday 26 May 2018 18:30
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Contact:

Re: Trigger based on user variable

Post 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
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Trigger based on user variable

Post 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
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest