Page 1 of 2

switchOff().afterMin(10)  [Solved]

Posted: Friday 19 January 2018 15:00
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

Re: switchOff().afterMin(10)

Posted: Saturday 20 January 2018 8:05
by dannybloe
In the upcoming 2.4 you should be able to do domoticz.notify().afterMin(10).

Re: switchOff().afterMin(10)

Posted: Saturday 20 January 2018 11:55
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

Re: switchOff().afterMin(10)

Posted: Saturday 20 January 2018 16:03
by dannybloe
Nope, you can't unfortunately.

Re: switchOff().afterMin(10)

Posted: Tuesday 08 May 2018 2:38
by Wob76
@dannybloe post 2.4 is it possible to do .afterMin() and .cancelQueuedCommands() on domoticz.notify() ?

Regards,
Wob

Re: switchOff().afterMin(10)

Posted: Tuesday 15 May 2018 21:28
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.

Re: switchOff().afterMin(10)

Posted: Wednesday 16 May 2018 6:32
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

Re: switchOff().afterMin(10)

Posted: Wednesday 16 May 2018 7:51
by dannybloe
Mm.. I see it is not in there. I've put it on my list (again?). Sorry about that.

Re: switchOff().afterMin(10)

Posted: Wednesday 16 May 2018 12:44
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.)

Re: switchOff().afterMin(10)

Posted: Wednesday 16 May 2018 14:32
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.

Re: switchOff().afterMin(10)

Posted: Wednesday 16 May 2018 14:35
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.

Re: switchOff().afterMin(10)

Posted: Wednesday 16 May 2018 15:06
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


Re: switchOff().afterMin(10)

Posted: Wednesday 16 May 2018 19:05
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...

Re: switchOff().afterMin(10)

Posted: Thursday 17 May 2018 3:48
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.

Re: switchOff().afterMin(10)

Posted: Thursday 17 May 2018 7:40
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.

Re: switchOff().afterMin(10)

Posted: Thursday 17 May 2018 8:01
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.

Re: switchOff().afterMin(10)

Posted: Thursday 17 May 2018 9:02
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".

Re: switchOff().afterMin(10)

Posted: Friday 18 May 2018 2:43
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

Re: switchOff().afterMin(10)

Posted: Tuesday 06 July 2021 8:46
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
}

Re: switchOff().afterMin(10)

Posted: Tuesday 06 July 2021 9:10
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.