Temp out of range for thermostat settings

i am trying to get HA to notify me when my thermostat reads a current_temperature that is +3 degrees of my target_temp_high or -3 degrees or my target_temp_low. my action works just fine and i have no conditions, so it’s just a trigger issue. i am including the entities of the thermostat along with the yaml code of the non-working trigger.

Entity: climate.thermostat
State: heat_cool
Attributes
hvac_modes:
  - "off"
  - heat_cool
  - cool
  - heat
min_temp: 40
max_temp: 99
fan_modes:
  - "on"
  - auto
  - diffuse
preset_modes:
  - none
  - away
  - hold
current_temperature: 72
temperature: null
target_temp_high: 75
target_temp_low: 72
current_humidity: 31
fan_mode: auto
hvac_action: heating
preset_mode: hold
fan_action: running
permanent_hold: true
dr_phase: -1
friendly_name: THERMOSTAT
supported_features: 411
trigger:
  - platform: state
    entity_id:
      - climate.thermostat
    attribute: current_temperature
    to: target_temp_high +5
  - platform: state
    entity_id:
      - climate.thermostat
    attribute: current_temperature
    to: target_temp_low -5

You can’t do that. See: https://www.home-assistant.io/docs/automation/trigger/#numeric-state-trigger

You will have to use template triggers. https://www.home-assistant.io/docs/automation/trigger/#template-trigger

1 Like

Like this:

trigger:
  - platform: template
    value_template: >
      {{ state_attr('climate.thermostat', 'current_temperature') >=
         state_attr('climate.thermostat', 'target_temp_high') + 5 }}
  - platform: template
    value_template: >
      {{ state_attr('climate.thermostat', 'current_temperature') <=
         state_attr('climate.thermostat', 'target_temp_low') - 5 }}

Note I’m using >= and <= not ==, because the current_temperature might go past the thresholds between updates without landing on the exact value.

thank you, both! i understand the concept of how the template trigger works, but i’m still get failing traces when i manually run the automation. for testing, i have inverted the temp variables, so instead of +5 on the target_temp_high, i am using -5, and vice verse. am i missing something, like a dedicated template somewhere that this is supposed to be linking to? i’ve never used templates before, that i am aware of, but it feels like i’m now missing another piece of a puzzle.

Show the complete automation. If you trigger manually, you’re only running the action part, which you haven’t shown us.

It’s not a puzzle, and there’s no “linking”: although the code looks complicated, my template triggers above (before your inversion) say:

  • watch the current temperature and the high target attributes: as soon as current temperature is 5°C or more above the high target, fire!
  • watch the current temperature and the low target attributes: as soon as current temperature is 5°C or more below the low target, fire!

oh, ok, thank you for your confirmation of the trace not working in this manner. i thought that running the automation manually and then checking the traces would show if the “when” would have activated. the action, listed as “Then Do” works just fine. it works every time i manually run. but it did that before i had your code, so it seems the trace is a useless button for manually checking something.

so i guess you just gotta let it be and hope the automation triggers naturally. if it doesn’t trigger naturally, it doesn’t seem like the trace can show anything. so it either works and the trace can confirm it worked, or it doesn’t work and the trace cannot show you anything. no manual run allows the trace to work. thats sad. seems pointless.

the next time i can confirm that the automation should have triggered and does trigger, i’ll mark your answer as the solution. thank you again.

this did not work. i forced a failure of the furnace, so the thermostat still read correctly but could not tell the furnace to heat/cool. the automation did not trigger. i did change from +/- 5 to +/- 1 for this test.

included is the automation i have, minus the email address for my notification, and a screenshot of the thermostat not within temp.

alias: Thermostat Out-Of-Range
description: ""
trigger:
  - platform: template
    value_template: >-
      {{ is_state_attr('climate.thermostat', 'current_temperature') >=
      is_state_attr('climate.thermostat', 'target_temp_high') + 1}}
  - platform: template
    value_template: >-
      {{ is_state_attr('climate.thermostat', 'current_temperature') <=
      is_state_attr('climate.thermostat', 'target_temp_low') - 1}}
action:
  - service: notify.xxxxxxxxxxxxxxxxxxxx_xxxxxxxxxxxxxx_xxx
    data:
      target: [email protected]
      title: Thermostat
      message: The thermostat is out-of-range
    enabled: true
mode: single

Your “this” isn’t the same as mine. You’re using is_state_attr instead of state_attr, so the template will always fail. Why did you change my suggestion?

i think i changed that, and forgot it change it back, when i was doing my initial testing using the trace function. i’ll do the forced fail again and see now that i’ve removed the “is_” from the command, all four locations.