Can someone explain automation condition checking?

Hi
I am brand new to HA. I setup an automation script that is supposed to switch on the geyser (WiFi switch) when the battery SOC is above 50% and it is later than 11am.
What I am trying to understand is :

  1. what if the battery hits 50% at 1pm, will the trigger fire?
  2. If the geyser is switched OFF manually for some reason, BUT the conditions to switch it on are then met 10 minutes later, will HA switch the geyser on again?

thanks.

You create 2 triggers:

  • numeric with battery above 50
  • timer at 11am
    and 2 conditions
  • battery above 50
  • time at 11

yes

Only if the battery was less then 50, and becomes > 50

1 Like

thanks for helping!
Therein lies the problemā€¦what I am understanding is that once the condition has been met ONCE, HA will not evaluate that condition again?

it will check it every time you cross from less then 50 to more then 50. But it has to fall below 50 and more then 50 again for it to trigger again.

1 Like

the conditions are checked when and only when the trigger for the automation occurs (goes from false to true). if the condition(s) arenā€™t met at that exact moment then the automation actions arenā€™t going to run. And the condition wonā€™t be checked again until the next trigger occurs.

If you want there to be more checking of the condition outside of your original trigger then you need to create another trigger that matches the conditions of the condition as noted above.

you may also need to add a second (or more) condition that matches the conditions of your original trigger.

1 Like

OK, so perhaps someone can help then setup the automation logic :
The geyser must switch on when the SOC is > 50, it is after 11am AND the power draw from the grid is < 500W.
If the grid draw is> 500 the geyser much switch off (even if SOC > 50)
If the grid draw drops below 500 again (and SOC is still > 50) the geyser must switch on again

in English : I want the geyser to only use solar power and as soon as the HA detects that grid is being used the geyser must be switched off. It has the lowest load priorty

hi. yes, this is now sounding like what I have to do. HA does not seem to do persistent monitoring of a condition.

Persistent monitoring is only for triggers.

If a trigger occurs then the conditions are checked.

So if you want to monitor three things, time, soc and power, use three triggers. Then sort out the logic in the conditions.

2 Likes

Hi
is that 3 triggers in the SAME automation or 3 separate triggers in 3 different automations?

Lastly : are the ā€œWHENā€ conditions OR or AND? So would my trigger ā€œSOC > 50 , Grid Power < 500ā€ require BOTH to be met or either to be met in order for the action to take place?

by default, conditions (WHEN) are and. You can explicitly make them and by using the and condition, you can also use the or condition. Making it possible to mix and match and and or.

1 Like

Donā€™t confuse triggers with conditions.

1 Like

you probably have two triggers to turn the geyser ON (first automation):

  • SOC rises over 50% or
  • it turns 11

and three conditions with that automation:

  • it is between 11 and midnight (or whenever your latest time is) and
  • your SOC is over 50% and
  • grid power is over 500

But then you probably also want to turn it OFF again (in a second automation) when

  • Grid Power drops below 500 or
  • SOC goes below 50%
  • your latest time arrives

if you want a condition with that one it would be that the geysir is already turned on.

1 Like

Yes, I have not listed the OFF trigger but your assumption is 100%

FYI to all who assisted : I found a much better solution. My PV systems exposes a ā€˜state changeā€™ trigger on the battery SOC. Thus I set a trigger to monitor the state from ā€œAny Stateā€ to ā€œAny Stateā€. Under the Conditions I then add in the SOC & Grid power rules. This way the trigger is fired almost continually as the battery charges and discharges and thus its state changes.

1 Like

I know you said you used a different method and itā€™s working but to answer your question for next timeā€¦

three triggers in one automation

you can also add the trigger(s) to switch it off to the same automation but it may make it harder to read therefore making maintenance a bit harder. So making two automations - one for on & one for off - might make more sense. Some people have an unhealthy compulsion to cram everything into one huge unwieldy automation. But thatā€™s personal preference.

I DO have a separate ON & OFF automation - would be very tricky otherwise to manage!

1 Like

If you want a trigger that fires ā€˜continuallyā€™, just use a time pattern trigger.

1 Like

Time pattern triggers are rarely the best choice. Even triggering on all state changes and putting in a condition is a better option. e.g.

trigger:
  - platform: state
    entity_id: sensor.battery_soc
    not_to:
      - unavailable
      - unknown
condition:
  - condition: numeric_state
    entity_id: sensor.battery_soc
    above: 50
4 Likes

The ā€œnot_to:ā€ part is really smart. :grinning: