switchOff().afterMin(10)  [Solved]

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

Moderator: leecollings

pgas37
Posts: 99
Joined: Wednesday 06 December 2017 19:44
Target OS: -
Domoticz version:
Contact:

switchOff().afterMin(10)  [Solved]

Post by pgas37 »

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

Re: switchOff().afterMin(10)

Post by dannybloe »

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: 99
Joined: Wednesday 06 December 2017 19:44
Target OS: -
Domoticz version:
Contact:

Re: switchOff().afterMin(10)

Post by pgas37 »

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

Re: switchOff().afterMin(10)

Post by dannybloe »

Nope, you can't unfortunately.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
Wob76
Posts: 110
Joined: Wednesday 19 April 2017 6:31
Target OS: Linux
Domoticz version:
Contact:

Re: switchOff().afterMin(10)

Post by Wob76 »

@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 »

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: 110
Joined: Wednesday 19 April 2017 6:31
Target OS: Linux
Domoticz version:
Contact:

Re: switchOff().afterMin(10)

Post by Wob76 »

dannybloe wrote: Saturday 20 January 2018 8: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: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: switchOff().afterMin(10)

Post by dannybloe »

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 »

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: 110
Joined: Wednesday 19 April 2017 6:31
Target OS: Linux
Domoticz version:
Contact:

Re: switchOff().afterMin(10)

Post by Wob76 »

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

Re: switchOff().afterMin(10)

Post by dannybloe »

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: 110
Joined: Wednesday 19 April 2017 6:31
Target OS: Linux
Domoticz version:
Contact:

Re: switchOff().afterMin(10)

Post by Wob76 »

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 »

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: 110
Joined: Wednesday 19 April 2017 6:31
Target OS: Linux
Domoticz version:
Contact:

Re: switchOff().afterMin(10)

Post by Wob76 »

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

Re: switchOff().afterMin(10)

Post by waaren »

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.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Wob76
Posts: 110
Joined: Wednesday 19 April 2017 6:31
Target OS: Linux
Domoticz version:
Contact:

Re: switchOff().afterMin(10)

Post by Wob76 »

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

Re: switchOff().afterMin(10)

Post by waaren »

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".
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Wob76
Posts: 110
Joined: Wednesday 19 April 2017 6:31
Target OS: Linux
Domoticz version:
Contact:

Re: switchOff().afterMin(10)

Post by Wob76 »

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
Piacco
Posts: 69
Joined: Friday 14 November 2014 9:33
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: switchOff().afterMin(10)

Post by Piacco »

Hi,

I have a script for turning my PC on/off with a toggle switch. Sometimes when my PC is on, I accidentally push the switch and my PC is turned off after 3 min. Is there a possibility to reset this action, by pressing the switch again?

Code: Select all

return 
{
    on = 
    {
        devices = 
        { 
            '$Toggle_Swich_PC',
			
        },
    },

    logging = 
    {
        level = domoticz.LOG_ERROR,
        marker = "PC Boven Aan/Uit"
    },

    execute = function(dz, device)
       dz.log("Script geactiveerd") 
       dz.changedDevices()
                  
            if dz.devices('PC-2').state == 'Off' then
               dz.devices('PC-2').switchOn()
               dz.notify("Domoticz",  "PC Boven is aan", dz.PRIORITY_NORMAL,dz.SOUND_DEFAULT, "" , "telegram")
		    end
		    
	        if dz.devices('PC-2').state == 'On' then
    		   dz.notify("Domoticz",  "PC Boven gaat over 3min uit!!!", dz.PRIORITY_NORMAL,dz.SOUND_DEFAULT, "" , "telegram")
    		   dz.devices('PC-2').switchOff().afterMin(3)
	    end
	end
}
User avatar
waltervl
Posts: 5715
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: switchOff().afterMin(10)

Post by waltervl »

Piacco wrote: Tuesday 06 July 2021 8:46 Hi,

I have a script for turning my PC on/off with a toggle switch. Sometimes when my PC is on, I accidentally push the switch and my PC is turned off after 3 min. Is there a possibility to reset this action, by pressing the switch again?
You have to use function dz.devices('PC-2').cancelQueuedCommands()
The difficult thing is to decide how to know that it has to be canceled. Perhaps make another dummy switch and have that cancel the Queue.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest