dzVents - Possible to use a variable for a timed event

Easy to use, 100% Lua-based event scripting framework.
Post Reply
User avatar
rbisschops
Posts: 79
Joined: Monday 12 May 2014 11:20
Target OS: Raspberry Pi
Domoticz version: 2.2563
Location: Schiedam, Netherlands
Contact:

dzVents - Possible to use a variable for a timed event

Post by rbisschops » Tuesday 31 July 2018 13:06

Hi All,

As I'm using dzVents for all my Lua scripts now, i stumbled into a thought, but not sure how to do this or even if it is possible.

I created a script controling my blinds. It lowers the blinds at a fixed time in the morning and raises them in the evening. Both at a fixed time coded in the script as follows:

Code: Select all

return {
    active = true,
    on = {
        timer = {
            'at 07:30',
            'at 17:30'
        }
    },
As we (the wife) wants to be able to influence the timers, I would like to put these in a variable in Domoticz. Is it possible to use the variables for the timed events. So something like:

Code: Select all

timer = at {someVariable}
I know this code won't work, but is put in as an example to explain my thinking :-)

Thanks all for your thoughts.

Ralph
RPi 3B (master): RFXtrx433, Harmony Hub, Z-Wave devices, CoCo units, Hue, Xiaomi Aquara
RPi 2B (slave): P1 connection, MySensors with custom built watermeter sensors on Aquadis+
RPi’s with: Mosquitto MQTT, Home Bridge, Home Assistant (for evaluation only)

TheCondor
Posts: 63
Joined: Thursday 18 June 2015 10:32
Target OS: Linux
Domoticz version:
Contact:

Re: dzVents - Possible to use a variable for a timed event

Post by TheCondor » Friday 03 August 2018 14:44


User avatar
rbisschops
Posts: 79
Joined: Monday 12 May 2014 11:20
Target OS: Raspberry Pi
Domoticz version: 2.2563
Location: Schiedam, Netherlands
Contact:

Re: dzVents - Possible to use a variable for a timed event

Post by rbisschops » Sunday 05 August 2018 9:00

Hi,

That is not exactly what i was lookling for. I want the time set in the domoticz variable to be the trigger. So 7:30 in the variable should be the trigger to kick off the script. For now I have a 15 minute time trigger and check in the script if the domo variable time is the same as the system time. This has some limitations in the time you set in the variable.
RPi 3B (master): RFXtrx433, Harmony Hub, Z-Wave devices, CoCo units, Hue, Xiaomi Aquara
RPi 2B (slave): P1 connection, MySensors with custom built watermeter sensors on Aquadis+
RPi’s with: Mosquitto MQTT, Home Bridge, Home Assistant (for evaluation only)

User avatar
waaren
Posts: 798
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: dzVents - Possible to use a variable for a timed event

Post by waaren » Sunday 05 August 2018 21:02

I guess the solution is to read the content of the var when it changed and with that content calculate what the afterSec should be to be used with an openURL of which the repsonse will trigger the event that will do your required action and do sent the openURL in 24 hours.
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, , dzVents 2.6, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave, Amazon echo

User avatar
rbisschops
Posts: 79
Joined: Monday 12 May 2014 11:20
Target OS: Raspberry Pi
Domoticz version: 2.2563
Location: Schiedam, Netherlands
Contact:

Re: dzVents - Possible to use a variable for a timed event

Post by rbisschops » Monday 06 August 2018 16:26

@waaren: but unfortunately the var does not change that often (its more a setting)
RPi 3B (master): RFXtrx433, Harmony Hub, Z-Wave devices, CoCo units, Hue, Xiaomi Aquara
RPi 2B (slave): P1 connection, MySensors with custom built watermeter sensors on Aquadis+
RPi’s with: Mosquitto MQTT, Home Bridge, Home Assistant (for evaluation only)

randytsuch
Posts: 98
Joined: Sunday 20 March 2016 19:56
Target OS: Raspberry Pi
Domoticz version: Beta
Location: LA, Ca USA
Contact:

Re: dzVents - Possible to use a variable for a timed event

Post by randytsuch » Monday 06 August 2018 17:50

Define the time as a user variable of type string.

Then you can read it into dzvents

randytsuch
Posts: 98
Joined: Sunday 20 March 2016 19:56
Target OS: Raspberry Pi
Domoticz version: Beta
Location: LA, Ca USA
Contact:

Re: dzVents - Possible to use a variable for a timed event

Post by randytsuch » Tuesday 07 August 2018 4:26

Oops, I lied

Make a user variable of type time

Then, if you can do something like this to create local variables with hours and mins, for example.

local thour = domoticz.variables('SpkrStart').time.hour
local tmin = domoticz.variables('SpkrStart').time.min

user variable is name SpkrStart in the user variable page, with value set to whatever time you want to use, ie 19:00

User avatar
waaren
Posts: 798
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: dzVents - Possible to use a variable for a timed event

Post by waaren » Tuesday 07 August 2018 10:05

rbisschops wrote:
Monday 06 August 2018 16:26
@waaren: but unfortunately the var does not change that often (its more a setting)
What you can do is trigger a script on that variable change and use the appropriate API call to delete / add the timer for that the device.
Look at the domoticz API wiki domoticz API wiki for the exact syntaxis of the calls
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, , dzVents 2.6, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave, Amazon echo

User avatar
waaren
Posts: 798
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: dzVents - Possible to use a variable for a timed event

Post by waaren » Tuesday 07 August 2018 18:08

rbisschops wrote:
Monday 06 August 2018 16:26
@waaren: but unfortunately the var does not change that often (its more a setting)
Something like this ?

Code: Select all

--   setTimers.lua

return { 
    on = {   variables   =   {"timer*"}},   -- One time var for On and one for Off 

    execute = function(dz,triggerObject)
        local myDevice    = 1012                      -- myDevice    = idx of myDevice
        local onTimeVar   = "timerTestOn"             -- uservariable of type time, format hh:mm
        local offTimeVar  = "timerTestOff"

        local function  clearTimers(idx)
                local api = dz.settings['Domoticz url'] .. "/json.htm?type=command&param=cleartimers&idx=".. idx
                dz.openURL({ url = api, method = "GET" })
        end

        local function decomposeVarTime(timeVar)
            return dz.variables(timeVar).time.hour, dz.variables(timeVar).time.minutes
         
        end

        local function  setTimers(idx,sethour,setminute,state)
           local command = 0
           if state == "Off" then 
            command = 1
           end
           local api  = dz.settings['Domoticz url'] .. "/json.htm?active=true&command=" .. command .. 
                                                        "&hour=".. sethour ..
                                                        "&min=" .. setminute .. "&param=addtimer" ..
                                                        "&randomness=false&timertype=2;&type=command&days=1234567&idx=" .. idx
           dz.openURL({ url = api, method = "GET" })
        end

        clearTimers(myDevice)
        local hour,minute = decomposeVarTime(onTimeVar)
        setTimers(myDevice,hour,minute)
        hour,minute = decomposeVarTime(offTimeVar)
        setTimers(myDevice,hour,minute,"Off")

    end
}
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, , dzVents 2.6, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave, Amazon echo

randytsuch
Posts: 98
Joined: Sunday 20 March 2016 19:56
Target OS: Raspberry Pi
Domoticz version: Beta
Location: LA, Ca USA
Contact:

Re: dzVents - Possible to use a variable for a timed event

Post by randytsuch » Tuesday 07 August 2018 21:53


User avatar
rbisschops
Posts: 79
Joined: Monday 12 May 2014 11:20
Target OS: Raspberry Pi
Domoticz version: 2.2563
Location: Schiedam, Netherlands
Contact:

Re: dzVents - Possible to use a variable for a timed event

Post by rbisschops » Thursday 09 August 2018 17:01

@waaren: Thx for setting this up. Highly appreciated!
Is it possible to do this:

Code: Select all

dz.variables(timeVar).time.hour, dz.variables(timeVar).time.minutes
As far as I understand from the documentation, its a string (even though its a date var)
What I can't figure out is why you use:

Code: Select all

 on = {   variables   =   {"timer*"}},
This requires one of the variables to change right? Otherwise the script won't fire.

Thx

Ralph
RPi 3B (master): RFXtrx433, Harmony Hub, Z-Wave devices, CoCo units, Hue, Xiaomi Aquara
RPi 2B (slave): P1 connection, MySensors with custom built watermeter sensors on Aquadis+
RPi’s with: Mosquitto MQTT, Home Bridge, Home Assistant (for evaluation only)

User avatar
waaren
Posts: 798
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: dzVents - Possible to use a variable for a timed event

Post by waaren » Thursday 09 August 2018 18:28

rbisschops wrote:
Thursday 09 August 2018 17:01
@waaren: Thx for setting this up. Highly appreciated!
Is it possible to do this:

Code: Select all

dz.variables(timeVar).time.hour, dz.variables(timeVar).time.minutes
As far as I understand from the documentation, its a string (even though its a date var)
yes this works. I tested this with uservars type time


What I can't figure out is why you use:

Code: Select all

 on = {   variables   =   {"timer*"}},
This requires one of the variables to change right? Otherwise the script won't fire.

Thx

Ralph
The idea is that when one uservar is changed a new set of timers (on/off) will be set after the current ones are cleared.
Until the uservar is changed again the timerset will stay active.
That is what I understand was your requirement.
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, , dzVents 2.6, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave, Amazon echo

User avatar
rbisschops
Posts: 79
Joined: Monday 12 May 2014 11:20
Target OS: Raspberry Pi
Domoticz version: 2.2563
Location: Schiedam, Netherlands
Contact:

Re: dzVents - Possible to use a variable for a timed event

Post by rbisschops » Friday 10 August 2018 8:35

waaren wrote:
Thursday 09 August 2018 18:28
rbisschops wrote:
Thursday 09 August 2018 17:01
@waaren: Thx for setting this up. Highly appreciated!
Is it possible to do this:

Code: Select all

dz.variables(timeVar).time.hour, dz.variables(timeVar).time.minutes
As far as I understand from the documentation, its a string (even though its a date var)
yes this works. I tested this with uservars type time
Which version did you test this on (i'm on V3.9639)? I have user vars of typ time in my Domoticz, but when I add the code you propose, I get a nil value.
RPi 3B (master): RFXtrx433, Harmony Hub, Z-Wave devices, CoCo units, Hue, Xiaomi Aquara
RPi 2B (slave): P1 connection, MySensors with custom built watermeter sensors on Aquadis+
RPi’s with: Mosquitto MQTT, Home Bridge, Home Assistant (for evaluation only)

User avatar
waaren
Posts: 798
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: dzVents - Possible to use a variable for a timed event

Post by waaren » Sunday 12 August 2018 16:55

rbisschops wrote:
Friday 10 August 2018 8:35
waaren wrote:
Thursday 09 August 2018 18:28
rbisschops wrote:
Thursday 09 August 2018 17:01
@waaren: Thx for setting this up. Highly appreciated!
Is it possible to do this:

Code: Select all

dz.variables(timeVar).time.hour, dz.variables(timeVar).time.minutes
As far as I understand from the documentation, its a string (even though its a date var)
yes this works. I tested this with uservars type time
Which version did you test this on (i'm on V3.9639)? I have user vars of typ time in my Domoticz, but when I add the code you propose, I get a nil value.
Tested with V4.9796
timeVars.PNG
timeVars.PNG (60.12 KiB) Viewed 82 times
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, , dzVents 2.6, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave, Amazon echo

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest