WTH - Booleans update 'too often'

I ‘regularly’ find myself writing automations that look like (paraphrased and YAML hand-written):

trigger:
  entity_id: power_level
  above: 50
condition:
  _some_boolean: off
action:
  service: input_boolean.turn_on
  entity_id: _some_boolean

trigger:
  entity_id: power_level
  below: 20
condition:
  _some_boolean: on
action:
  service: input_boolean.turn_off
  entity_id: _some_boolean

trigger:
  entity_id: _some_boolean
  state: on
  for: 00:02:00
action:
  notify....

(i.e.: Track power level. If the power level of the washing machine has been above 50W for a few minutes, it’s probably running. if it’s below 20W, it’s probably idle. Notify that it is running, but only if it hasn’t been notified before).

If there were an action input_boolean.turn_on_if_off and input_boolean.turn_off_if_on (or something less of a monstrosity :slight_smile:), it would make creating the first automation easier (no need to check if boolean is off before turning it on). The first automation can be called a few times in quick succession, because of varying power levels used by the washing machine.

Above 50 for … 2 minutes should fix it?
I believe it’s no a problem with the booleans but with the automation coding if I’m honest…

No, because the trigger gets called again at every power level change, killing the for. Perhaps I could use the parallel automation mode, but then the action gets called a lot.

What about input_boolean.toggle?

1 Like

I can’t use input_boolean.toggle every time the power level is reported, I think… I mean, when it is ‘high’ the boolean needs to turn on, and when it is low, it needs to be turned off. Powel level reports come every few seconds.

But your automations only trigger when the power level crosses the specified threshold, for the specified time.

Toggle does exactly what you asked for. Turn off if on, turn on if off.

Ok. That might be true.
But I still don’t see this as a wth topic and the proposed solution (to slow down the booleans) I not something I like.
Most probably want booleans to be instantaneous and slowing it down will affect other automations.

What about the thresholds? Can’t you set it higher than 50? Say 100 when the washing machine is really on?
Or the below lower?

Another option is to condition that it can’t turn off if it has been turned on within the last hour (assuming the washing machine runs for about or more than an hour).

As I see it there are other solutions to the problem that is better and more accurate than slowing the booleans.

So, assuming I write this:

trigger:
  platorm: numeric_state
  entity_id: power_level
  above: 50
  for: 00:02:00
...

And then these values come in:

Time: 00:00:01
Power: 50.5

Time: 00:00:30
Power: 51

Time: 00:01:00
Power: 52

then the action is called at 00:02:01?

According to the docs, it should…

Hmmm, looks like I mis-read that. Several times…

Numeric state triggers only when threshold is crossed. So, my bad. Closing this!

2 Likes

We’ve all been there… I had two similar moments this morning messing with input_selects, so I know exactly where you’re coming from. :smiley:

even if that weren’t the case, on -> on actions are suppressed by home assistant. So turning on an input boolean that is on essentially has no effect.