Stumped using a State Attribute as a Trigger in an Action

I want to be alerted when my thermostat changes its “hvac_action” attribute. This would be heating to idle, idle to heating, cooling to idle, idle to cooling. There are only these three values: heating, idle, cooling. I’m simply interested in any change of the attribute.

I’ve fiddled and fiddled, but every attempt results in errors from the configuration validator. As it sits now (see below) the validator complains about an invalid use of value template. Note that Blockquote inserted dots where I have dashes in my code. I feel like I’m dancing around the answer and just can’t quite nail it down.

- alias: NOTIFICATION Furnace Mode Changes
  trigger:
    platform: state
    entity_id: climate.trane_corporation_model_tzemt524aa21ma_mode
    value_template: >
      {{ trigger.to_state.attributes.hvac_action !=
         trigger.from_state.attributes.hvac_action }}
  action:
    - service: notify.clicksend_bkk
      data:
        message: 'Furnace action {{ state_attr("climate.trane_corporation_model_tzemt524aa21ma_mode","hvac_action") }}, Temp: {{ state_attr("climate.trane_corporation_model_tzemt524aa21ma_mode","temperature") }}'

Other stuff I monkeyed with…

Tried using platform:template as the trigger with:

"{{ state_attr('climate.trane_corporation_model_tzemt524aa21ma_mode', 'hvac_action') }}"

Also tried this as a value_template at one time…

  value_template: >
    {{ state_attr('climate.trane_corporation_model_tzemt524aa21ma_mode', 'hvac_action') in ['idle','heating','cooling'] }}

…and this…

  value_template: {{ state_attr('climate.trane_corporation_model_tzemt524aa21ma_mode', 'hvac_action') }}

You shouldn’t need the value template.
You are just looking at a change.

Though a value template on the same line should be quoted

Maybe a bit roundabout but possibly beneficial in other ways:

Create a template sensor based on that attribute. Then just use a regular state trigger on that sensor.

Just need to make sure that the template updates if the Trane changes attribute without changing state.

The template needs to be a condition…

- alias: NOTIFICATION Furnace Mode Changes
  trigger:
    platform: state
    entity_id: climate.trane_corporation_model_tzemt524aa21ma_mode
  condition:
    condition: template 
    value_template: >
      {{ trigger.to_state.attributes.hvac_action !=
         trigger.from_state.attributes.hvac_action }}
  action:
    - service: notify.clicksend_bkk
      data_template:
        message: 'Furnace action {{ state_attr("climate.trane_corporation_model_tzemt524aa21ma_mode","hvac_action") }}, Temp: {{ state_attr("climate.trane_corporation_model_tzemt524aa21ma_mode","temperature") }}'

You also need data_template in the action.

(I’m assuming your templates are right, I haven’t checked them)

Thanks to everyone who replied. @anon43302295 - using the value template as a condition instead of doing it in the trigger seems like the answer. The config is valid at least. Haven’t run good tests to make sure it works properly yet. But getting a valid config is step one.

Thanks again.

1 Like