FHEM Forum

FHEM => Automatisierung => Thema gestartet von: Paul Guijt am 07 September 2023, 12:13:33

Titel: Execute after 2 hours, without sleep?
Beitrag von: Paul Guijt am 07 September 2023, 12:13:33
Hi all,

Two hours after a notify triggered, I want FHEM to do something else.

What is the neatest way to do that? Sleep is depreciated, isn't it?

BW,
Paul
Titel: Aw: Execute after 2 hours, without sleep?
Beitrag von: betateilchen am 07 September 2023, 12:19:03
Hello Paul, sleep is not deprecated, but it is not the prefered solution for your task.

Simply use an at-device which will be defined inside your notify:

define n1 notify <anyTrigger> doFhemTask1; define tempat at +02:00:00 doFhemTask2_after_two_hours
Titel: Aw: Execute after 2 hours, without sleep?
Beitrag von: DL8EI Ralph am 07 September 2023, 12:30:09
Another idea is to use a DOIF with a wait for 2 h ?
Titel: Aw: Execute after 2 hours, without sleep?
Beitrag von: betateilchen am 07 September 2023, 12:37:04
Zitat von: DL8EI Ralph am 07 September 2023, 12:30:09Another idea is to use a DOIF

"If I don't have any idea, how to solve it in an easy, simple and correct way, I can always try to use a damn DOIF and get crazy."
(Unknown FHEM user)

BTW: There are no DOIF devices in any of my FHEM installations. Guess, why...
Titel: Aw: Execute after 2 hours, without sleep?
Beitrag von: rudolfkoenig am 07 September 2023, 12:39:17
...sleep is not deprecated...There is a FHEM command called sleep, which is not deprecated, and can be used to emulate the perl function sleep.
The perl function sleep remains deprecated, as FHEM is suspended for the duration of this sleep.
Titel: Aw: Execute after 2 hours, without sleep?
Beitrag von: Paul Guijt am 07 September 2023, 15:18:48
I got so many
1: WARNING: sleep without additional commands is deprecated and blocks FHEMdriving me crazy, as I couldn't trace them ...

That may be a topic in itself. Or even a Wiki entry.
Titel: Aw: Execute after 2 hours, without sleep?
Beitrag von: herrmannj am 07 September 2023, 15:48:43
Show your code pls
Titel: Aw: Execute after 2 hours, without sleep?
Beitrag von: TomLee am 07 September 2023, 16:23:50
You're probably doing a sleep without a following FHEM command.

E.g.:
fhem("sleep 3");
fhem("...");
fhem("sleep 3");
...

This results in the message:
1: WARNING: sleep without additional commands is deprecated and blocks FHEM

Zitat von: commandrefsleep
[EN DE]

    sleep <sec|timespec|regex> [<id>] [quiet]

    sleep followed by another command is comparable to a nameless at or notify, it executes the following commands after waiting for the specified time or an event matching <regex>. The delay can be given
        in seconds, with millisecond accuracy, as you can specify decimal places,
        as a timespec (HH:MM or HH:MM:SS or {perlfunc})
        or as a regex (devicename or devicename:event)

    A sleep with an <id> will replace a sleep with the same <id> and can be canceled by cancel. When called in a notify/at/etc, then nonempty return values of the following commands are logged to the global logfile with loglevel 2.
    If quiet is specified, then skip this logging.

    Example:
        define n3 notify btn3.* set lamp on;;sleep 1.5;;set lamp off
        define a3 at +*00:05 set Windsensor 1w_measure;; sleep 2 quiet;; get Windsensor 1w_temp
    Note: a sleep not followed by any command will block FHEM, is deprecated, and it issues a WARNING in the FHEM log.