switchOff().afterMin(10)  [Solved]

Easy to use, 100% Lua-based event scripting framework.
Post Reply
pgas37
Posts: 57
Joined: Wednesday 06 December 2017 20:44
Target OS: -
Domoticz version:
Contact:

switchOff().afterMin(10)  [Solved]

Post by pgas37 » Friday 19 January 2018 16:00

I am using dzventz 2.20

The scriptcommand switchOff().afterMin(10) will turn of the switch after ten minutes.
After 10 minutes i want to send a message (domoticz.notify....)

Is it possible to monitor the countdowntimer(call the status)? (When zero [or any given moment between 10 and zero] the message will be send)

thanks for your help

regards
paul

dannybloe
Posts: 1480
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi
Domoticz version:
Location: Ermelo
Contact:

Re: switchOff().afterMin(10)

Post by dannybloe » Saturday 20 January 2018 9:05

In the upcoming 2.4 you should be able to do domoticz.notify().afterMin(10).
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.

pgas37
Posts: 57
Joined: Wednesday 06 December 2017 20:44
Target OS: -
Domoticz version:
Contact:

Re: switchOff().afterMin(10)

Post by pgas37 » Saturday 20 January 2018 12:55

Dannybloe,

thanks for your reply, but ...in the meantime... is it possible to monitor the timer?

if answer == 'yes' then
please provide me with the necessary details
else
I have to wait until?
end

regards
Paul

dannybloe
Posts: 1480
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi
Domoticz version:
Location: Ermelo
Contact:

Re: switchOff().afterMin(10)

Post by dannybloe » Saturday 20 January 2018 17:03

Nope, you can't unfortunately.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.

Wob76
Posts: 129
Joined: Wednesday 19 April 2017 6:31
Target OS: Linux
Domoticz version:
Contact:

Re: switchOff().afterMin(10)

Post by Wob76 » Tuesday 08 May 2018 2:38

@dannybloe post 2.4 is it possible to do .afterMin() and .cancelQueuedCommands() on domoticz.notify() ?

Regards,
Wob

DomoArigato
Posts: 36
Joined: Monday 30 April 2018 13:41
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: switchOff().afterMin(10)

Post by DomoArigato » Tuesday 15 May 2018 21:28

interesting question.
I am just at the same stage. :)

I switch a device on with the .switchOn().forMin(x) command and wanted to get a notification after those x minutes when the device switches off.

Using domoticz BETA 3.9390 and tried to use .afterMin() on the .notify command. But I got this error in the log:
" dzVents: Error (2.4.1): ...r/scripts/dzVents/generated_scripts/test.lua:14: attempt to index a nil value "

Line 14 in my script is: "domoticz.notify('test', 'after one min <<<<<').afterMin(1)"

Any hints on that?

If that is not possible on the .notify command, I would have to try to do something else.

Thanks a lot for any help.

Wob76
Posts: 129
Joined: Wednesday 19 April 2017 6:31
Target OS: Linux
Domoticz version:
Contact:

Re: switchOff().afterMin(10)

Post by Wob76 » Wednesday 16 May 2018 6:32

dannybloe wrote:
Saturday 20 January 2018 9:05
In the upcoming 2.4 you should be able to do domoticz.notify().afterMin(10).
Hi Dannybloe,

Has this made it in yet? Or should we just look at using a switch to delay the action?

Thanks,
Wob

dannybloe
Posts: 1480
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi
Domoticz version:
Location: Ermelo
Contact:

Re: switchOff().afterMin(10)

Post by dannybloe » Wednesday 16 May 2018 7:51

Mm.. I see it is not in there. I've put it on my list (again?). Sorry about that.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.

Sparks
Posts: 1
Joined: Wednesday 16 May 2018 12:37
Target OS: Linux
Domoticz version:
Contact:

Re: switchOff().afterMin(10)

Post by Sparks » Wednesday 16 May 2018 12:44

Maybe I misunderstood:
Why don't you send a notification when the device turned Off ?
...
elseif device.state == 'Off' then
domoticz.notify('Device Off'...etc.)

Wob76
Posts: 129
Joined: Wednesday 19 April 2017 6:31
Target OS: Linux
Domoticz version:
Contact:

Re: switchOff().afterMin(10)

Post by Wob76 » Wednesday 16 May 2018 14:32

dannybloe wrote:
Wednesday 16 May 2018 7:51
Mm.. I see it is not in there. I've put it on my list (again?). Sorry about that.
Thanks
Sparks wrote:
Wednesday 16 May 2018 12:44
Maybe I misunderstood:
Why don't you send a notification when the device turned Off ?
...
elseif device.state == 'Off' then
domoticz.notify('Device Off'...etc.)
I can't speak for the others, what I want to do is delay the message in case the switch returns to its existing state.

For Example, only send a message if the door is left open for more than 5 min, so I would do a domoticz.notify().afterMin(5) as part of the open detection, then if the door closes run a domoticz.notify().cancelQueuedCommands().

I currently have some door\window detection for when my AC is on, but it a bit annoying when I am just opening the door to put something outside etc.

I could do all this with an intermediate switch, have it delayed on\off and it triggers the message, but doing it directly with .notify() would be neater.

dannybloe
Posts: 1480
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi
Domoticz version:
Location: Ermelo
Contact:

Re: switchOff().afterMin(10)

Post by dannybloe » Wednesday 16 May 2018 14:35

Or use a timer in where you check if the lastUpdate of the switch is older than 5 minutes and then send the notification.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.

Wob76
Posts: 129
Joined: Wednesday 19 April 2017 6:31
Target OS: Linux
Domoticz version:
Contact:

Re: switchOff().afterMin(10)

Post by Wob76 » Wednesday 16 May 2018 15:06

dannybloe wrote:Or use a timer in where you check if the lastUpdate of the switch is older than 5 minutes and then send the notification.
The issue with that approach is I need the script to run at time intervals, at the moment it is called by changes in the door/window contacts, and AC switches. So called much less often, maybe if I use a dummy switch that I delay on/off and have it call the script again, but I would need more script changes for it.

I am just thinking now that the .aftermin method would have a drawback of it could cancel any notification, not just this scripts notification.

It's a simple concept, only send a message if the door/switch remains open/on for X, but I keep finding floors with my ideas, I should just pick one.

Sent from my SM-G935F using Tapatalk


DomoArigato
Posts: 36
Joined: Monday 30 April 2018 13:41
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: switchOff().afterMin(10)

Post by DomoArigato » Wednesday 16 May 2018 19:05

Would be great if that might be added.
Solved my issue already by catching the automatic off-switching and then send notification.

@dannybloe: Thanks A LOT for dzVents! Great work! :) makes automation a lot easier.

BTW - any function available in dzVents to put the execute function into a ‚sleep‘ for a certain time? I mean something other then a looong ‚for loop‘

Regards...

Wob76
Posts: 129
Joined: Wednesday 19 April 2017 6:31
Target OS: Linux
Domoticz version:
Contact:

Re: switchOff().afterMin(10)

Post by Wob76 » Thursday 17 May 2018 3:48

OK, so I have added a

'if (device.lastUpdate.minutesAgo >= 5) then" (device being my door\windows)

check around my notification send, just before that I am switching on a dummy delay switch, this switch is set to turn off after a 300 second delay (5 min) and that device is included in my trigger devices.

this is all inside a foreach loop that checks all my doors\windows.

End result is that the script with retrigger every 5 min while a door\window is open, and as long as one of those openings have been open for more than 5 min a message will be sent.

It Tests ok, I'll see how it goes in the wild.

Thanks for the ideas.

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

Re: switchOff().afterMin(10)

Post by waaren » Thursday 17 May 2018 7:40

Wob76 wrote:
Thursday 17 May 2018 3:48

.... , just before that I am switching on a dummy delay switch, this switch is set to turn off after a 300 second delay (5 min) and that device is included in my trigger devices.
Just curious; did you consider the use of a user variable instead of a dummy delay switch ?
Would be nice if you could share your result with us.
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

Wob76
Posts: 129
Joined: Wednesday 19 April 2017 6:31
Target OS: Linux
Domoticz version:
Contact:

Re: switchOff().afterMin(10)

Post by Wob76 » Thursday 17 May 2018 8:01

The advantage of the switch in this case is it I can create it to be momentary, with a configurable time, saves me using any dzVents queues.

I had previously used variables for this kind of thing, but I use Dashitz and wanted to used the states of these variables to shade buttons depending on state, it can't read variables, so I moved to switches, now I just do it for anything that is a simple toggle.

I'll give it a few days to ensure I don't have any bugs, then I'll post, my script is doing a bunch of checks related to my AC, might be a bit hard to just post snippets, not sure if the rest of it is much use, but I'll prob just post the lot.

I did a different approach for my "Motion Detection" script, I use wifi presence to detect when someone (a phone) is home, I then had a script detect if a door\window moves while the house is "empty" this works quite well, but at times the phone connects after the door has been opened, so I wanted to delay that to recheck if someone gets home. Still need to see how long a delay I will need. The loop wouldn't work for this, as it would keep triggering if I had left a window open, i only want it to trigger on a device change, so I just have a few nested ifs, I'll post it also after some testing.

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

Re: switchOff().afterMin(10)

Post by waaren » Thursday 17 May 2018 9:02

Thx for your detailed and clear answer. Looking forward to have a peek at your scripts. Always nice to see how other forum members approach these kind of "small puzzles".
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

Wob76
Posts: 129
Joined: Wednesday 19 April 2017 6:31
Target OS: Linux
Domoticz version:
Contact:

Re: switchOff().afterMin(10)

Post by Wob76 » Friday 18 May 2018 2:43

Still early days, but so far so good. Since this is a little off topic I started a new thread, my scripts are included.

viewtopic.php?f=59&t=23492

Post Reply

Who is online

Users browsing this forum: No registered users and 9 guests