Automation dont work

Hi there,
i wrote an automation wich should if-sun goes down and temperature of my solar pool heater goes below pool water temperature → turn off my pump, but it doesnt work as expected.
My code:

alias: POOL Filterpumpe aus
description: ''
trigger:
  - platform: template
    value_template: '{{ state_attr(''sun.sun'', ''elevation'') < 10 }}'
condition:
  - condition: template
    value_template: '{{ state_attr("sun.sun", "rising") == false }}'
  - condition: numeric_state
    entity_id: sensor.temperature_3_2
    below: sensor.temperature_2_2
action:
  - type: turn_off
    device_id: 8b84a7507b98363fc1995c5dcce20589
    entity_id: switch.pumpe_relays_1
    domain: switch
mode: single

where is the error?

What you have described is not exactly what your automation configuration does.

Your automation is more accurately described as follows:

When the sun elevation changes from above 10 to below 10,
if temperature_3_2 is already below temperature_2_2,
then turn off the pump.

The trigger will only fire once in the evening, but if the temperature_3_2 is above the temperature_2_2 at that moment the pump will keep running. A change in temperature_3_2 after the trigger will have no effect.

My setup in these situations where the order of events can be either way, is to set both conditions as triggers and conditions. So either the sun setting or the temp dropping can trigger the automation but both things have to be true for it to fire the action.

This has no double quotes, it has double single quotes.

should it be like this?

alias: POOL Filterpumpe aus
description: ''
trigger:
  - platform: template
    value_template: '{{ state_attr("sun.sun", "elevation") < 10 }}'
  - platform: numeric_state
    entity_id: sensor.temperature_3_2
    below: sensor.temperature_2_2
condition:
  - condition: template
    value_template: '{{ state_attr("sun.sun", "rising") == false }}'
  - condition: numeric_state
    entity_id: sensor.temperature_3_2
    below: sensor.temperature_2_2
action:
  - type: turn_off
    device_id: 8b84a7507b98363fc1995c5dcce20589
    entity_id: switch.pumpe_relays_1
    domain: switch
mode: single

If you are not sure with the tempate, go to Developer Tools → Templates and paste
‘{{ state_attr(“sun.sun”, “rising”) == false }}’
or
‘{{ state_attr(“sun.sun”, “elevation”) < 10 }}’
there. You will see the result.
Your code looks good to me, but i am a newbie :slight_smile:

therefore it must be not in double quotes but in single:

not so:
{{ state_attr("sun.sun","elevation") < 10 }}
but so:
{{ state_attr('sun.sun', 'elevation') < 10 }}

EDIT: upss… both variants seem to work

You should add a third condition for the elevation less than 10. Otherwise you automation can trigger before the sun gets that low.

Yes, basically everything that is a condition, also needs a trigger and vice versa once there is more than one condition to be met.