Automation not running as expected

Hallo,

I have created the automation in the image below.

If temperature top buffer less than 60°C

Only if

SOC Battery house > 98

6:30 h before Sunet

Then

Switch on heating rod

So, what happens.

If the battery is charged (SCO > 98%) and it is more than 6:30 before sunset, and the temperature falls below 60°, it is switched on. Ok, so far

If the temperature falls below 60°C and SOC < 98°, it is not switched on, ok. If SOC rises to > 98% and the temperature is still < 60°C, it is not switched on. Why not?

The following should actually happen

Switch on if Temp <60° and SCO>98% and if it is 6:30 min before sunset.

What went wrong?

Thanks

BR

Haase

https://photos.app.goo.gl/VfkNKyvXEH9mdCHg6

An automation trigger is an event, not a condition.

In other words, your automation will fire when the temperature changes from above 60°C to below 60°C.

Once the temperature is below 60°C it won’t fire again until it rises above 60°C and falls again.

Automations #1: trigger only fires when it changes from not true to true

Edit: Please post code as preformatted text (</> in the toolbar).

Hallo,

ok, thanks.
How can I realiaze that e.g. every 5 min it shall be checked?
The solution I think is, I will add a 2nd automation anch change the condition, if temp is below 60° to only is and if SOC > 98 to trigger event. Running both in paralel is an or function and should cover both.

Thanks

BR
Haase

Hi.
Add trigger

    trigger:
     - platform: time_pattern
       minutes: "/5"

You can also add additional, second entity state trigger to your automation: SOC Battery house > 98.

Thanks to having 2 triggers, your automation will start on ANY following events:

  • If temperature drops below 60 degrees
  • If battery level will be above 98%

However, if any of your triggers will execute after 6:30, it won’t start (and it won’t wait till next day), so time_pattern trigger every X minutes seems to be better option for a trigger.

Hello,
thanks for the feedback.
I have 2 questions. One, explicitly about my problem, a general one

  1. When I add the lines of code that Vlad has written, a second condition appears, see picture attached. Question: Is it switched on after 5 minutes or is it checked after 5 minutes whether the conditions are fulfilled and switched on after this check?
  2. General question: If I have two switch-on conditions, condition A and condition B. Are these linked with “AND” or “OR”? So, do both have to occur or one?
    Thank you
    Haase

It will check every 5 min

In general, time pattern triggers are a kludge. There’s no reason to keep checking on a fixed interval if some set of conditions are true. Instead, you only need to trigger when any of those conditions change. That will make your automation both more responsive and consume fewer resources. A win-win.

When you want multiple things to be true at the same time, the concept which szymon alluded to is often referred to as “matching triggers and conditions”. Meaning, if you want something to happen when 3 things become true, then you should add all three as separate triggers, and also add all three as separate conditions. That way, once any one of the 3 become true, the automation will then check if all the others are already true, and will only execute the actions if they are.

In your case, you want 3 triggers:

  • SOC rises above 98%
  • midnight
  • Temperature drops below 60°

And you want 3 conditions:

  • SOC > 98%
  • More than 6:30 before sunset (i.e. between midnight and 6:30 before sunset)
  • Temperature < 60°

Note that I choose midnight as a trigger because I’m assuming that is the earliest time that you’d consider being “before sunset” instead of “after sunset”

Hello,

I don’t quite understand the time pattern yet. Below is a BSP. I have the automation, “Heating element down on”. It should switch on when the bottom buffer drops below 35 degrees and only between 6 am and 10.30 pm. So, for example, if the temperature falls below 35 degrees at 4.30 pm, it would not be switched on at 6.30 am. So, the system should check every 5 minutes whether the condition is fulfilled.

Now I have implemented it like this. It looks as if the automation switches on after 5 minutes, no matter what the values/conditions are. Take a look at the pictures in the link. Tem. buffer is 41 degrees, the part switches on, as trigger “time patter”

What went wrong?

Thanks
Haase

https://photos.app.goo.gl/d6UgyWhqQunH98CT9

Without seeing full code it’s hard to tell.

Please paste the YAML code. From the automation screen, click the three dots top-right. Then Edit as YAML. Then copy/paste the code in here formatted as code using the </> button.

If it looks like this:

alias: Pump restart
trigger:

  • platform: state
    entity_id: switch.aquarium_pump_plug
    to: “off”

…try again until it looks like this:

alias: Pump restart
trigger:
  - platform: state
    entity_id: switch.aquarium_pump_plug
    to: "off"

In general, as @mekaneck said above, checking every X minutes is a poor way to run automations, but until we have the code you’re not likely to get better suggestions. Images are not fun to work with.

Hello,

below the code. Every 5 min the conditions shall be checked. Depending on the result, it shall be switched, but it is switched after 5 min independent from the conditions. Why
THX

alias: Heizstab unten ein
description: ""
trigger:
  - platform: numeric_state
    entity_id:
      - sensor.km2_40a36bcb5a44_temperature_sensor_3
    for:
      hours: 0
      minutes: 3
      seconds: 20
    below: 35
  - platform: time_pattern
    minutes: /5
condition:
  - condition: time
    before: "22:30:00"
    after: "06:00:00"
action:
  - type: turn_on
    device_id: f9d2fdc8229c874c6fe63ad2eb894d03
    entity_id: 3fc3369a4aefcfadaa6592e51c7a5927
    domain: light
mode: singl

Your triggers fire independently. Triggers are “OR”; conditions are “AND” (unless otherwise configured). That says:

  • Trigger when the temp goes from above to below 35 and stays there for 3m20; and also trigger every five minutes.
  • If it’s “daytime”, turn the light on.

No it isn’t: the conditions are that it’s after 06:00 and before 22:30.

I think you want:

alias: Heizstab unten ein
description: ""
trigger:
  - platform: numeric_state
    entity_id:
      - sensor.km2_40a36bcb5a44_temperature_sensor_3
    for:
      hours: 0
      minutes: 3
      seconds: 20
    below: 35
  - platform: time
    at: "06:00:00"
condition:
  - condition: time
    before: "22:30:00"
    after: "05:59:59"
  - condition: numeric_state
    entity_id: sensor.km2_40a36bcb5a44_temperature_sensor_3
    below: 35
action:
  - type: turn_on
    device_id: f9d2fdc8229c874c6fe63ad2eb894d03
    entity_id: 3fc3369a4aefcfadaa6592e51c7a5927
    domain: light
mode: single

That will trigger when the temp drops and at 06:00, check that it’s cold and daytime, and turn the light on.

You need the 06:00 trigger in case it’s already cold by that time (if that’s what you want).

Hello,

So, the automation should do the following:

When temperature buffer down switch on, but only between 6:00am and 10:00 pm

So, the temperature can also fall below 35°C at 04:30am e.g. Then the part must switch on at 06:00. The triggers and conditions should therefore be checked every 5 minutes and depending on the result of this check it should be switched on.

How do you do this?

That’s what my code above does, except for the “every 5 minutes” bit.

Don’t check every 5 minutes: check for the temperature dropping, check for it being 06:00.

You don’t “check triggers” — triggers fire by themselves. Here’s what my version does If the temperature falls below 35°C at 04:30:

  1. 04:30:00: Temperature drops below 35°C. System notices, but doesn’t do anything yet.
  2. 04:33:20: First trigger fires as it’s been cold for 3m20s. Action is blocked by the conditions because it’s not after 06:00.
  3. 06:00:00: Second trigger fires because of the time. Both conditions pass (cold and after 06:00) so the light is turned on.

See? No need for an “every 5 minutes” check.

Hello,
I understand how it works, good idea. Thanks!

Scenario 1: Temp > 35° at 6:00 am: Does not switch
Scenario 2: Temp < 35° at 4:30 am e.g. trigger “<35” would switch but condition “before 6 am” prevents this. At 06:00 am Trigger time=06:00am switches because both conditions are met
Scenario 3: Temp < 35° after 06:00 am. Trigger Tem<35° switches, both conditions are fulfilled.
Yes, we don’t need to check the triggers and conditions every 5 minutes here, but I’m interested in whether this is possible and if so, how.

Thank you

Haase