Autor Thema: Multiple IF statements in a notify define statement  (Gelesen 751 mal)

Offline jacko

  • New Member
  • *
  • Beiträge: 18
Multiple IF statements in a notify define statement
« am: 02 Januar 2022, 11:38:12 »
I want to test for a particular state after a timeout but am having problems. Any help would be appreciated.

This is my problem code:
define n_Door_ajar_timeout notify DoorSwitch \
IF ([DoorSwitch:&STATE] eq "on") \
   (defmod a_ajar_timeout at +00:00:10 \
   IF ([DoorState:&STATE] eq "moving") \
      (set DoorState ajar)\
)

The purpose of the command is to use the DoorSwitch to create an event that starts a timer (see below). If after a timeout period (10 secs here) the DoorState hasn't changed to open or closed (ie is still "moving"), then the DoorState needs to revert to ajar.

The problem is that I get a perl error in the logfile:
Zitat
2022.01.02 09:21:19 1: ERROR evaluating {if(moving eq "moving"){fhem('set DoorState ajar')}}: Bareword "moving" not allowed while "strict subs" in use at (eval 2080) line 1.
2022.01.02 09:21:19 3: a_ajar_timeout: Bareword "moving" not allowed while "strict subs" in use at (eval 2080) line 1.

FYI, There is another notify that sets the DoorState to moving when the door switch is pressed (the use of [DoorSwitch:&STATE] here works OK)
attr DoorSwitch event-on-change-reading status
define n_Switch_ajar notify DoorSwitch \
IF ([DoorSwitch:&STATE] eq "on" and [DoorState:&STATE] eq "ajar") \
   (set DoorState moving)

In the Command Ref for the IF command there is an example of a second IF statement in a define but the comparison is with a number not a string. It looks like the use of "Reading State" [DoorState:&STATE] in the second IF statement needs a different syntax?

What am I doing wrong?
Is there an alternative way of achieving this?

Many thanks in advance.

 

decade-submarginal