Simplifying automation for heater: seeking alternative to template binary_sensor

Hi everyone,

I have set up an automation for a heater in my parents’ house that turns climate.woonkamer_airco off if the current temperature has reached the target temperature - 0.5 degrees for longer than 30 minutes.

I’ve been able to achieve this with a template binary_sensor, but I am trying to find a simpler way to do this. It’s such a simple request, but disproportionally difficult to implement. Does anyone know of a simpler method?

I’m hoping to teach my dad, who knows his way around computers, to create basic automations himself. Templating isn’t something that will be easy to teach.

Simpler solutions that did not work

  • Numeric state trigger: Not possible without template sensors. The numeric state trigger only accepts numbers and helpers as above and below values. Templates are not supported and there is no way to use a state attribute as one of these values.

  • Template trigger: Not possible as for: cannot be used with template triggers.

How I solved it

Template binary sensor

  - binary_sensor:
      - name: Woonkamer airco target reached
        state: >
          {{ state_attr('climate.woonkamer_airco', 'current_temperature') 
          | float(0) >= (state_attr('climate.woonkamer_airco', 'temperature') | float(0) - 0.5) }}
        availability: "{{ state_attr('climate.woonkamer_airco', 'current_temperature') | is_number }}"

Automation:

alias: Turn woonkamer airco off when target is reached
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.woonkamer_airco_target_reached
    for:
      hours: 0
      minutes: 30
      seconds: 0
    to: "on"
condition:
  - condition: state
    entity_id: climate.woonkamer_airco
    state: heat
action:
  - service: climate.turn_off
    data: {}
    target:
      entity_id: climate.woonkamer_airco
mode: single

It’s not hard to do, but with the complexity that the automation editor and helpers allow for, perhaps I missed an easier way to do this. I really dislike needing to make template sensors for very simply things. It makes everything so messy and harder to understand.

To be fair, it’s not a “very simple thing”. You have a climate entity that doesn’t expose either of the numbers you want to use as a state, and the requirement for a 0.5°C offset in the comparison.

Set up three template sensors (I only use two, but might as well do all of them), and the automation is a lot simpler:

template:
  - sensor:
      - name: woonkamer_current_temperature
        unique_id: 961c501d-1201-41eb-a668-bb350d9b9be1
        unit_of_measurement: "°C"
        state: "{{ state_attr('climate.woonkamer_airco', 'current_temperature') }}"
        device_class: temperature

      - name: woonkamer_target_temperature
        unique_id: ece80bd4-9337-42d9-85d2-3d11809e9aac
        unit_of_measurement: "°C"
        state: "{{ state_attr('climate.woonkamer_airco', 'temperature') }}"
        device_class: temperature

      - name: woonkamer_target_temperature_offset
        unique_id: 883209a5-9e08-4954-a49e-aaf0f42f14d1
        unit_of_measurement: "°C"
        state: "{{ states('sensor.woonkamer_target_temperature')|float(0) - 0.5 }}"
        device_class: temperature

automation:
  - alias: Turn woonkamer airco off when target is reached
    id: 804db597-ee86-4333-9567-57ae277fb4ab
    trigger:
      - platform: numeric_state
        entity_id: sensor.woonkamer_current_temperature
        above: sensor.woonkamer_target_temperature_offset
        for:
          minutes: 30
    condition:
      - condition: state
        entity_id: climate.woonkamer_airco
        state: heat
    action:
      - service: climate.turn_off
        target:
          entity_id: climate.woonkamer_airco

Alternatively, look into the Generic Thermostat?

It makes the automation a lot simpler, but choosing this path overall still requires a similar amount of knowledge about template sensors and templates.

The generic thermostat doesn’t really apply to my use case (yet), but it also doesn’t simplify things. The aircon is loud, but temperatures are accurate. It’s so well calibrated, however, that temperatures tend to hover just under the target rather than overshooting for a long time. Hence the need to subtract 0.5 degrees.