FHEM Forum

FHEM => English Corner => Thema gestartet von: alex am 13 September 2017, 19:35:36

Titel: [solved] How to perform a command after 30 seconds
Beitrag von: alex am 13 September 2017, 19:35:36
I need some help with the following challenge. I want to set an alarm on the refrigirator when the door is opened for longer than 30 seconds (or whatever time).
I've mounted a homematic doorsensor on the frig called door_koelkast and it works off course perfectly when I create a normal notify for this.
But now I only want a message to be sent when the door is open longer than 30 seconds. Probably it can be done with a DOIF statement but I can't figure it out yet.

Currently I have the following defined:
define deur_koelkast CUL_HM 5403C3
attr deur_koelkast IODev HMLAN1
attr deur_koelkast IOgrp vccu:HMLAN1
define di_koelkast DOIF ([deur_koelkast:open]) (set pushover msg "koelkast staat nog open")

Any suggestions to get the 30 seconds in here?

Thanks,
Alex
Titel: Antw:How to perform a command after 30 seconds
Beitrag von: Otto123 am 13 September 2017, 19:46:56
Hi Alex,

with DOIF like thisdefine di_koelkast DOIF ([deur_koelkast:"open"]) (set pushover msg "koelkast staat nog open")
attr di_koelkast do resetwait
attr di_koelkast wait 0,30

The DOIF will be triggered with the Event open from the device deur_koelkast - may be, you have to check this on behalf of the Event Monitor.
The Timer will be reset, if the door is closed in a time lower than 30 sec.

Enjoy
Otto
Titel: Antw:How to perform a command after 30 seconds
Beitrag von: alex am 13 September 2017, 22:27:04
Hello Otto,

Thanks for the help. I assume it had to be (30,0 instead of 0,30):

attr di_koelkast do resetwait
attr di_koelkast wait 30,0


This causes the command to be executed 30 seconds after the door has been opened, but it doesn't reset. So even if I close the door within the 30 seconds, it still sends the command.

any thoughts?

Thanks,
Alex
Titel: Antw:How to perform a command after 30 seconds
Beitrag von: Otto123 am 13 September 2017, 22:42:05
Sorry, of course you have to use only attr di_koelkast wait 30 you have only one command. I copied this and I have two  ;)
To reset the wait Timer, the state of the DOIF must changed, the condition must be false. Sometimes I don't understand the DOIFs behavior  ;D

We could change the trigger from event only to check the statedefmod di_koelkast DOIF ([deur_koelkast] eq "open") (set pushover msg "koelkast staat nog open")

crossing the fingers
Otto
Titel: Antw:How to perform a command after 30 seconds
Beitrag von: MadMax-FHEM am 13 September 2017, 22:56:37
What about watchdog?

As I understand watchdog that's exactly what it should do?

But just as idea, I never used watchdog...

When I do things like that I "defmod" an "at" for the timeout and call a function in myUtils that checks again...

If still the case I do what has to be done...
...otherwise I (the function) does just nothing (maybe an entry in the log)...

I know my (actual) "solution" is crap but it works and is (actually) the least thing to be changed...
...other nicer things to do... ;)

Regards, Joachim
Titel: Antw:How to perform a command after 30 seconds
Beitrag von: Otto123 am 13 September 2017, 23:57:40
Sorry, my proposal is going the wrong direction, it's only extending the waiting time for cmd_1
I have tested this:
defmod di_koelkast DOIF ([deur_koelkast] eq "open") (set pushover msg "koelkast staat nog open") DOELSEIF ([deur_koelkast] eq "closed")()
If the door is closed, the DOIF is going to cmd_2 and no Message is send.
Titel: Antw:How to perform a command after 30 seconds
Beitrag von: alex am 14 September 2017, 15:14:13
No problem Otto, already learned a lot playing around with the DOIF function.
But looking at the Watchdog function as Joachim (Thanks for mentioning!) mentions than I think that is a better function to use in this case. Didn't had time to try it yet but will let you know what comes out of it.

Thanks,
Alex
Titel: Antw:How to perform a command after 30 seconds
Beitrag von: alex am 14 September 2017, 17:14:30
Yes, the watchdog function definitely solves my question. I have now the following:

define wd_koelkast watchdog deur_koelkast:open 00:00:30 deur_koelkast:closed set pushover msg "koelkast staat nog open"
attr wd_koelkast autoRestart 1
Titel: Antw:How to perform a command after 30 seconds
Beitrag von: MadMax-FHEM am 14 September 2017, 21:25:30
HURRAY! ;)

So then mark the thread as solved rename e.g.:

[solved] How to perform a command after 30 seconds

Bye, Joachim