I do have a device called “AC_AUTOMATIC_TEST_LED” which I want to switch on automatically under the following condition:
“AC_AUTOMATIC_TEST_LED” shall get switched ON if “AUTOMATIC_TEST_ON_OFF_SWITCH = ON” AND “SF_Power_total < -2000”
The code below work half way only.
It does switch the device on if there is a certain sequence only.
a) This sequence works:
“SF_Power_total < -2000” (threshold reached)
“AUTOMATIC_TEST_ON_OFF_SWITCH” = ON
b) This sequence does not work:
“AUTOMATIC_TEST_ON_OFF_SWITCH” = ON
“SF_Power_total < -2000” (threshold not yet reached)
“SF_Power_total < -2000” (threshold reached)
What can I do to make “b” work too?
configuration: {}
triggers:
id: “2”
configuration:
itemName: AC_AUTOMATIC_TEST_ON_OFF_SWITCH
state: ON
previousState: OFF
type: core.ItemStateChangeTrigger
conditions:
The rule will only trigger if the trigger condition is met, so the Switch Item changed it’s state from OFF to ON.
The Action will only be performed if the BUt Only If Condition is met, so the Number has to be less than -2000.
So either build a second rule or add some stuff to your rule:
This will result in many ON commands (whenever Switch is ON and Number changes to less than -2000), so maybe add another But Only If, that is, the Switch Item AC_AUTOMATIC_TEST_LED state is OFF
Just to elaborate on @Udo_Hartmann’s example. The rule only attempts to run based on the triggers. Your a) works because the rule is triggered by the Switch changing. At that time your condition was true and the actions ran.
Your b) doesn’t work because changes to the Number Item do not trigger the rule to run. The only time the rule ran was when the switch changed and at that time the condition was false. If you want the rule to run if the number changes after the switch changes to ON, you must trigger the rule when the number changes too.
Very much like you did before. Trigger the rule when the SF_Power_total changes. In the condition check to see if SF_Power_total is < -100 and optionally when the switch is ON. For the action command the switch to OFF.
All rules follow this pattern.
Trigger: Something happens (in this case the SF_Power_total changes)
Condition: Check to see if we need to do something (in this case SF_Power_total < -100 and the switch is ON)
Action: Do something (in this case command the Item to OFF)
It’s definitely possible but it means you need to get into Timers which is going to become much more complicated. At a high level:
trigger the rule when SF_Power_total changes
no conditions
in the Action you need to choose “run a script” and create code that does the following (Blockly is an option)
if SF_Power_total is < -100, the switch is ON, and a Timer doesn’t already exist create a Timer for 20 seconds which commands the switch to OFF
if SF_Power_total is < -100 and the switch is ON and the Timer does exist, exit doing nothing
if SF_Power_total is < -100, the switch is OFF and the Timer exists or SF_Power_total >= -100, cancel the timer.