Add reset flag to switch timing options

Use this forum to discuss possible implementation of a new feature before opening a ticket.
A developer shall edit the topic title with "[xxx]" where xxx is the id of the accompanying tracker id.
Duplicate posts about the same id. +1 posts are not allowed.

Moderators: leecollings, remb0

Post Reply
jsiegmund
Posts: 33
Joined: Sunday 14 May 2017 21:13
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Add reset flag to switch timing options

Post by jsiegmund »

Hi there,

I've recently started coding my Domoticz install using DzVents. I really like the simplicity, especially compared to the other methods of scripting. But there's one thing I'm missing that should not be that hard to implement I think.

I'm trying to automate things after a period of inactivity. So you enter a room, light comes on (PIR detection) but it should switch off again after 15 minutes of inactivity (left the room but didn't kill the lights). Perfectly doable of course using a timer script and monitoring the last activity on the PIR, but then I have my "light on" and "light off" code in two different scripts.

What you'd really want is something like:

Code: Select all

device.switchOn()
device.switchOff().afterMin(15)
The problem is that when the PIR detects activity in the meantime, you want to reset that switchOff timer again. So my proposal would be to implement an optional reset flag on the afterMin (and the rest of them) methods. In code:

Code: Select all

device.switchOn()
device.switchOff().afterMin(15, true)
Behavior: when the reset flag is set, afterMin cancels any previously set afterMin events on the same device and replaces those with this one. For even more controlability another option would be to name the reset token using a string so you'd be able to only cancel out specific events by name. Or yet another option would be to have the afterMin return a handle or sorts that can be stored in a persistent var to be used by the same script later on. Multiple ways of getting to the same result.

Even fancier would be to have an inline method execute. So something like:

Code: Select all

device.do( (device) => {
    if (device.state == 'On') then
        device.switchOff()
    end
}).afterMin(15, true)
But I'm not sure LUA / DzVents supports syntax like that.

Let me know your thoughts!
Last edited by jsiegmund on Tuesday 05 September 2017 7:51, edited 1 time in total.
DomoJev
Posts: 19
Joined: Friday 16 June 2017 23:40
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Add reset flag to switch timing options

Post by DomoJev »

I support this request. Makes things much easier!
niki_lauda
Posts: 118
Joined: Saturday 31 August 2013 14:48
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Eindhoven (NL)
Contact:

Re: Add reset flag to switch timing options

Post by niki_lauda »

#metoo :-)
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest