Reading a state attribute value

Hi,

I am still a newbie when it comes to HA so please be gentle with me!

I am using a custom intergration (Wiser Heating Component) and and trying to display a state attribute.

If I look in the developers states under the entity “climate.wiser_xxxx” there are 17 or so state attributes available and the one I’m interested in is “control_output_state” which is either “on” or “off”, basically it tells you when the room is requesting heat.

Is there anyway I can view this attribute directly in lovelace and then convert the value from on/off to show the total amount of time it has been on throughout each day? Ideally I would like to then use this information to log and display in influxdb and grafana.

Create a Template Sensor to report the value of control_output_state. Then use the History Statistics integration to create a sensor that monitors the Template Sensor and reports how much time it is on.

Let me know if you need more help creating these entities.

To display the attribute in Lovelace just use the entities card. It supports displaying attributes.

If you want to display how long it has been on you will have to configure a history stats sensor:

However this only supports entities not attributes, so you will have to configure a template binary sensor to break out the attribute into it’s own sensor.

binary_sensor:
  - platform: template
    sensors:
      wiser_heating_state:
        friendly_name: "Wiser Heating State"
        value_template: >-
          {{ is_state_attr('climate.wiser_xxxx', 'control_output_state', 'on') }}

Which you then might as well just use in the entities card, instead of displaying the attribute.

History Stats sensor, using the above template binary sensor:

sensor:
  - platform: history_stats
    name: Wiser Heating ON today
    entity_id: binary_sensor.wiser_heating_state
    state: 'on'
    type: time
    start: '{{ now().replace(hour=0, minute=0, second=0) }}'
    end: '{{ now() }}'
2 Likes

Thanks I have ago

Do I just create a new entities card in the config file?

There are two options.

  1. Use yaml mode and write your card in lovelace.yaml.
  2. Use the Lovelace UI. Click the vertical three dots icon in the lop right of the UI. Watch the video here:

Ok sensors are working…thank you.

However when I try and and the entity to Lovelace it displays the “On” time as a percentage of an hour, clicking on it to view the graph displays both percentage and value in minutes. How can I just display hours and minutes and not as a percentage?

That’s a floating point value in hours, not a percentage.

If you really want to format it in hh mm you will lose the ability to graph it and it is going to require another template sensor.

See here for an example:

Spoke to soon.

Both the template and sensor created ok and passed the config test but any value always remains at the state off.

The reason I thought it was working was I changed the values to reflect off as my heating isn’t on at the moment just to see if I could get a reading, then changed the template and sensor to ON state turned the heating on and the state didn’t update. If I query the state from the developers STATE option and view the state attributes it shows correctly as being on show why isn’t my binary sensor updating?

Please post code as inline text surrounded by three backticks, not as screenshots.

My guess is that your binary template sensor is not realising it needs to watch the climate entity. Try adding the entity_id (docs):

- platform: template
  sensors:
    wiser_landing_heating_on_state:
      entity_id: climate.wiser_landing
      friendly_name: …

EDIT: Just noticed in the screenshot that the attribute you’re looking at appears to be 'On' not 'on'. That’s likely to be your problem, although I’d encourage adding the entity_id as good practice.

image

2 Likes

Sorry I dont understand “inline text surrounded by three backticks”

This is my config and it appears to be working for the binary sensor now however the history state sensor just returns a value of 0

binary_sensor:

  • platform: template
    sensors:
    wiser_landingxxxxxx_heating_state:
    friendly_name: “Wiser Landing Heating State 0001”
    value_template: >-
    {{ is_state_attr(‘climate.wiser_landing’, ‘control_output_state’, ‘On’) }}

sensor:

  • platform: history_stats
    name: Wiser Landing Heating total time on today
    entity_id: binary_sensor.wiser_landingxxxxxx_heating_state
    state: ‘On’
    type: time
    start: ‘{{ now().replace(hour=0, minute=0, second=0) }}’
    end: ‘{{ now() }}’

This is really starting to frustrate me as I can get it to work for non attribute sensors

Change:

state: 'On'

to:

state: 'on'

The “backticks” suggestion was for formatting code displayed in this forum. If you look at what you posted, it lacks proper formatting. To display formatted code in a post:

  1. Type three consecutive back-quotes ``` on a separate line before your code.
  2. Type three more consecutive back-quotes on a separate line after your code.

The forum’s Editor will understand that you want everything between the two sets of triple back-quotes to be presented as formatted code.

Ok thanks.

Just as I read your reply I noticed the ‘on’ instead of ‘On’ and it’s working.

Thanks all