Can't get binary sensor to show an entity attribute

Hi,

I am trying to make something display on my dashboard based on whether a thermostat in my heatmiser system is calling for heat in a given zone. The thermostat has an attribute called hvac_action.

If I examine the entity climate.utility_room_neo in developer tools I can see:

hvac_modes:
  - heat_cool
min_temp: 5
max_temp: 35
friendly_name: Utility Room Neo
supported_features: 1
current_temperature: 19.7
temperature: 24
hvac_action: heating

The attibute hvac_action changes to idle when the heating is off in that zone.

I created a binary sensor using this code:

binary_sensor:

  - name: "Utility Is Heating"
    unique_id: utility_is_heating
    state: >
      {{ 
        is_state('states.climate.utility_room_neo.attributes.hvac_action', 'heating')
      }}

My understaning of the above is that the binary sensor called utility_is_heating should be ON when the attribute hvac_action is ‘heating’ and OFF the rest of the time.

Howver, if I go to developer tools->template and enter:

'{{ states.climate.utility_room_neo.attributes.hvac_action }}'

the resulting output is:

Result type: string
'heating'

but the value of binary_sensor.utility_is_heating is OFF

Can anyone tell me what I’m doing wrong please?

Thanks

You have mashed up the is_state() function and state object method. The function expects an entity ID and a state as arguments. You have provided a string-ified version of the attribute path for your state object and a state.

Just use the is_state_attr() function and supply the correct arguments; entity ID, attribute name, value:

binary_sensor:
  - name: "Utility Is Heating"
    unique_id: utility_is_heating
    state: >
      {{ is_state_attr('climate.utility_room_neo', 'hvac_action', 'heating') }}

Thanks for your reply. Looking at the documentation I see what you mean - is_state_attr is what I should be using. However I still can’t seem to get this to report correctly.

Code in my templates.yaml is:

binary_sensor:

  - name: "Utility Is Heating"
    unique_id: utility_is_heating
    state: >
      {{ 
        {{ is_state_attr('climate.utility_room_neo', 'hvac_action', 'heating') }}
      }}

Developer Tools → Template → Template Editor

{{ is_state_attr('climate.utility_room_neo', 'hvac_action', 'heating') }}

Returns the folllowing result:

Result type: boolean
true
This template listens for the following state changed events:

Entity: climate.utility_room_neo

Developer->States->binary_sensor.utility_is_heating returns

state: unavailable

I assume I’m doing something blindingly obvious wrong, because if I go to a UI created dashboard, add an Entity card and pick binary_sensor.utility_is_heating, not only is the status Unavailable, I also have a warning message that says:

This entity is no longer being provided by the template integration. If the entity is no longer in use, delete it in settings.

I don’t suppose you can see anything that jumps out as obviously wrong? I’m sure it’s something simple but I just can’t see it :frowning:

    state: >
        {{ is_state_attr('climate.utility_room_neo', 'hvac_action', 'heating') }}

Way too many template braces there. Remove the outer or inner pair of {{ }}.

You are an absolute superstar - thank you kindly :slight_smile:

Working code / solution as follows:

binary_sensor:

  - name: "Utility Is Heating"
    unique_id: utility_is_heating
    state: >
      {{ 
        is_state_attr('climate.utility_room_neo', 'hvac_action', 'heating')
      }}