Temperature automation not triggering with device and template

Hello everyone,

I know that this question has already been asked several times and I have really tried many of the solutions described, but none of them work for me, although I have really tested many methods.

I have broken the task down to a minimum. As soon as a temperature sensor goes below 19 degrees during the day, a radiant heater should be switched on.

The problem: the automation is not triggered!

Attempt 1 via device:

alias: TEST
description: “”
triggers:
  - type: temperature
    device_id: b4c4cf81b145450bce0f5f00176d5b9c
    entity_id: b08172f72103f37c3d4df4d1f4c02e01
    domain: sensor
    trigger: device
    below: 19
conditions:
  - condition: sun
    before: sunset
    after: sunrise
actions:
  - type: turn_on
    device_id: 03a6d229cb32012bd8bc885266c86e9c
    entity_id: 971c63d8905b6786c06aec11845acd53
    domain: switch
mode: single

Attempt 2 via template:

alias: test 2
description: “”
triggers:
  - trigger: template
    value_template: “ {{ states('sensor.t202_temperature') | int < 19}}”
conditions:
  - condition: sun
    before: sunset
    after: sunrise
actions:
  - type: turn_on
    device_id: 03a6d229cb32012bd8bc885266c86e9c
    entity_id: ec22bcf5ed2c13cc70bae5081d878bea
    domain: switch
  - action: notify.mobile_app_samsung_s23
    metadata: {}
    data:
      message: Radiant heater switched on
      title: Automation triggered
mode: single

Both wont trigger. I understood, that the reason might be, that the temperature at night will go below 19 degrees, and that the value on sunset maybe below 19 so that it will not cross again…

But there must be a solution… Can anyone help?

Add a sunrise trigger as well as a temp below 19 condition.

Both automatations wont also work if i delete the sunrise condition. I only added it to show that the value might drop under 19 in the night.

alias: TEST
description: ""
triggers:
  - type: temperature
    device_id: b4c4cf81b145450bce0f5f00176d5b9c
    entity_id: b08172f72103f37c3d4df4d1f4c02e01
    domain: sensor
    trigger: device
    below: 19
conditions: []
actions:
  - type: turn_on
    device_id: 03a6d229cb32012bd8bc885266c86e9c
    entity_id: 971c63d8905b6786c06aec11845acd53
    domain: switch
mode: single

Also no trigger even is the temperaure is below 19.

Don’t reinvent the wheel. Use a generic thermostat helper.

Don’t delete anything. Just add the additional trigger and condition.

In attempt 1 or 2?

Either. They are both functionally the same.

Like this?

alias: Heizstrahler einschalten
description: ""
triggers:
  - trigger: template
    value_template: " {{ states('sensor.t202_temperatur') | int < 19}}"
  - trigger: sun
    event: sunrise
    offset: 0
conditions:
  - condition: sun
    before: sunset
    after: sunrise
actions:
  - type: turn_on
    device_id: 03a6d229cb32012bd8bc885266c86e9c
    entity_id: ec22bcf5ed2c13cc70bae5081d878bea
    domain: switch
mode: single

Just tried. No trigger. The temperature is below 19 and the template is true.

Where’s the temperature condition?

Did the sun just rise?

No, sun rised about 8 hours ago. Temperature is 18,7.

The temperature condition is in the template?

value_template: " {{ states('sensor.t202_temperatur') | int < 19}}"

Template results “true” in developer tools.

But that is not how template triggers work. Template triggers only trigger when they go from false to true. If its value is already true at the time the automation is loaded, it will not trigger until it goes false and then back to true again.

Thank you for that info. That explains, why it wont trigger.

Any idea how i can get it to work without crossing the value?

alias: test 2
description: “”
triggers:
  - trigger: state
    entity_id: sensor.t202_temperature
    not_to:
      - unknown
      - unavailable
conditions:
  - condition: sun
    before: sunset
    after: sunrise
  - condition: numeric_state
    entity_id: sensor.t202_temperature
    below: 19
actions:
  - type: turn_on
    device_id: 03a6d229cb32012bd8bc885266c86e9c
    entity_id: ec22bcf5ed2c13cc70bae5081d878bea
    domain: switch
  - action: notify.mobile_app_samsung_s23
    metadata: {}
    data:
      message: Radiant heater switched on
      title: Automation triggered
mode: single

As soon as the the sensor next updates this will run. If the temperature is below 19 and it is daytime the heater will turn on.

Have you thought about how you want to turn it off?

As Magnus said, a better way to do this is:

Then all you have to do is set the temperature and turn on the thermostat at sunrise (and off at sunset if that is what you want) with an automation.

1 Like

Thank you Guys! Problem solved. Great support!