Automate on device attribute change

Relative HA newby. Just getting starting with automations.

I’d like to create an automation that triggers when my air condition blower turns on. I can see in my device’s list of attributes that it has a fan_state attribute:

Entity - climate.2gig_technologies_ct101_thermostat_iris_cooling_1
Attributes - fan_state: Idle

fan_state turns to ‘Running’ when the AC is on.

So how do I use this attribute in a trigger?

OK, so I found a couple of posts that suggest setting up a sensor, so this is what I came up with:

sensor:
  - platform: template
    sensors:
      upstairs_blower:
        value_template: "{{ states.climate.2gig_technologies_ct101_thermostat_iris_cooling_1.attributes.fan_state }}"
        friendly_name: "Upstairs Blower"

But now I get this error:

Invalid config for [sensor.template]: invalid template (TemplateSyntaxError: expected token ‘end of print statement’, got ‘gig_technologies_ct101_thermostat_iris_cooling_1’) for dictionary value @ data[‘sensors’][‘upstairs_blower’][‘value_template’]. Got ‘{{ climate.2gig_technologies_ct101_thermostat_iris_cooling_1.attributes.fan_state }}’. (See ?, line ?).

Any clues?

if you want to use that as a trigger, just extract the result. You can do this a number of ways. If you don’t care about having a template, you can just go straight to the trigger.

- alias: Fan blower automation
  trigger:
    - platform: template
      value_template: "{{ is_state_attr('climate.2gig_technologies_ct101_thermostat_iris_cooling_1', 'fan_state', 'Running') }}"
  action:
    ...

If you’re dead set on your template, it should be working. I don’t see anything out of order with your syntax. Which leads me to believe that the number 2 after the dot in the climate.2… name is causing problems. Coding languages do not handle numbers as object names. You should rename that object or access the attribute through the state_attr(’’,’’) method.

Thanks Petro! I utilized state_attr to eliminate the error.

sensor:
  - platform: template
    sensors:
      upstairs_blower:
        value_template: "{{ is_state_attr('climate.2gig_technologies_ct101_thermostat_iris_cooling_1', 'fan_state', 'Running') }}"
        friendly_name: "Upstairs Blower"

How can I get this sensor to display on my front end? I want to make sure it’s correctly reflecting the current state of the blower before I try working it into an automation.

LOL! Nevermind. I just restarted HA and now I see it.

image

1 Like

OK, next thing (goodness, I’m so needy!) :rofl:

It appears that my sensor ONLY updates when I restart HA. I added a scan_interval, but it doesn’t look like it’s updating the sensor status:

sensor:
  - platform: template
    scan_interval: 5
    sensors:
      upstairs_blower:
        value_template: "{{ state_attr('climate.2gig_technologies_ct101_thermostat_iris_cooling_1', 'fan_state') }}"
        friendly_name: "Upstairs Blower"

Adding polling intensity to my zwave config seemed to help.

climate.hvac_1_cooling_1:
  ignored: false
  polling_intensity: 2
climate.hvac_1_heating_1:
  ignored: false
  polling_intensity: 2

I have a few binary sensors set up to look at the commands of the thermostat.

  - platform: template
    sensors:
      heat_on:
        value_template: >-
          {%if is_state_attr('climate.hvac_1_heating_1', 'operating_state', 'Heating')
              -%}
          True
          {%- else -%}
          False
          {%- endif %}
        friendly_name: "Heating Command"

  - platform: template
    sensors:
      cool_on:
        value_template: >-
          {%if is_state_attr('climate.hvac_1_cooling_1', 'operating_state', 'Cooling')
              -%}
          True
          {%- else -%}
          False
          {%- endif %}
        friendly_name: "Cooling Command"

  - platform: template
    sensors:
      fan_on:
        value_template: >-
          {%if is_state_attr('climate.hvac_1_heating_1', 'fan_state', 'Running')
              -%}
          True
          {%- else -%}
          False
          {%- endif %}
        friendly_name: "Fan Command"

Check this post for info on polling:

Thanks! Can you be more specific on exactly where you placed that? I tried adding it under zwave: in my configuration.yaml but I got an error.

I have a zwave_device_config. yaml file in my homeassistant directory referenced in configuration.yaml:

zwave:
  device_config: !include zwave_device_config.yaml

Check the configuration section of the Z-Wave install page:

Thanks! It didn’t set up the include and the separate yaml file when I installed HA. I was missing the device_config: keyword.

Is the default polling (60000 I believe?) supposed to poll all zwave devices once a minute? Or once an hour? Because I watched my OZW_Log for two hours and all I saw were temperature change notifications from my thermostat sensor.

milliseconds. Once every minute.

So I should see device activity in the OZW_Log every minute?