Task with "Only if switch is... (optional)" / "if already" using an expression. How to use?


#1

1) Give a description of the problem
I am using Keen vents, and to save battery I’m trying to activate them as little as possible. Because of the internal mechanisms for setting vent values, I can’t rely on command optimization to prevent sending redundant commands. For example, if I setLevel to 100, it may read 98, 99, or 100. So I’m using an expression in my setLevel action to only set the level if it’s too far away from the target:

image

But even though the expression evaluates as true, the level is not set. I’m not sure why… How should I format my expression?

2) What is the expected behaviour?
When the current [$device : level] is less than 97, then the [$device : level] should be set to 100.

3) What is happening/not happening?
Per the trace below, the device level is 80, 80 is less than 97, so the expression evaluates to true, but then the action is not completed: “Skipping setLevel as switch is not true”

**4) Post a Green Snapshot of the piston!

5) Attach logs after turning logging level to Full
12/9/2022, 1:37:01 PM +406ms
+6ms ╔Received event [Upstairs Landing].thermostatOperatingState = heating with a delay of 110ms, canQueue: true, calledMyself: false
+24ms ║RunTime initialize > 23 LockT > 1ms > r9T > 2ms > pistonT > 1ms (first state access 14 m:20 7 16)
+27ms ║Runtime (10499 bytes) initialized in 2ms (v0.3.114.20220928_HE)
+28ms ║╔Execution stage started
+44ms ║║Comparison (decimal) 74.1 is_less_than_or_equal_to (integer) 77 = true (1ms)
+45ms ║║Condition #3 evaluated true (15ms)
+52ms ║║Comparison (enum) heating is_any_of (string) fan only,heating = true (1ms)
+54ms ║║Condition #4 evaluated true (8ms)
+55ms ║║Condition group #1 evaluated true (condition changed) (25ms)
+62ms ║║Calculating (integer)80 < (integer)97 >> (boolean)true
+69ms ║║Skipping setLevel as switch is not true
+74ms ║║Executed virtual command wait [10000] (0ms)
+100ms ║║Requesting wake up at Fri, Dec 9 2022 @ 1:37:11 PM PST (in 9999ms) for 30 (st:31)
+104ms ║╚Execution stage complete. (75ms)
+238ms ║Setting up scheduled job for Fri, Dec 9 2022 @ 1:37:11 PM PST (in 9961ms)
+245ms ╚Event processed successfully (239ms)


#2

The only if is is for saying the switch is on or off, so you cannot use it for a general if as you are doing.

You should have and if before the with block with your expression and only issue the with block if this nest if is true.


#3

OK, thanks for the info. That was my work-around, and of course, that works.

Any reason it allows me to enter an expression if I can’t use it?


#4

It likely in the ide should not allow an expression as the possible values are to be on/off only.

The expression is to say only change the level if the switch is on or off.