Math variables occasionally not mathing

Simple ones are occasionally failing, like if light is on=1, light is off =0. Throwing off a whole bunch of rules as a result..

I would start by checking the Rule Logs to better understand what’s happening.

If that doesn’t help, can you provide more details about the specific issues you’re running into with examples including relevant details (eg. Rule Screenshot, Rule Logs, what you expected to happen, what actually happened).

:ring_buoy: Effective Ways to Seek Help and Troubleshoot

It’s variables occasionally not updating. For instance if a light turns on its 1 if off 0, occasionally it will hang on 1, breaking other things. This is what I see more often.

This is still an occasional thing. I tried changing else statements, did not help. Occasionally the variables just don’t update. Various ones. String, numerical. Etc.

Happy to look into this. The most useful next step is still a specific example, which Josh outlined here:

One concrete case is enough. Pick a single variable that hung, then share a screenshot of the rule that should have updated it, the Rule Logs from that run, what you expected, and what it actually showed. Without that we’re guessing, and it’s hard to tell a configuration issue from something on our side.

You see here when it’s off. It didn’t set to zero instead set to 1 (which it already was).

Thanks, that log is the example we needed.

At 5:02:55 AM the rule triggered because Headboard switch went off, but the IF still treated it as on and set $DICBedLight to 1. The off events at 5:00 and 5:06 went to ELSE and set 0 as expected.

The IF does not use the event that just fired. It re-reads the last known switch state. That re-read can still say on for a moment after an off event, so the variable stays 1. Downstream rules then look wrong even though the math itself is fine.

The simplest change to your existing rule is to point the IF at the event, not the device: check that the Context Variable $context.event.value is on (instead of Headboard switch is on). Then/Else can stay 1 and 0.

If you want a more compact rule, drop the IF and set $DICBedLight with an expression like:

equalText($context.event.value, 'on') ? 1 : 0

Do not set the numeric variable directly from $context.event.value. That is 'on' / 'off', not 1 / 0.