How to use attributes

Hi All,

Hopefully a simple one, I just want to dig out attributes from certain entities, i.e. battery percentages for use in lovelace and node red. An example of one of these entities is

I have tried to set up a template with this and other variations. I don’t get my value returned.

  - platform: template
    sensors:
      kitchen_door_battery:
        value_template: "{{states.binary_sensor.door_window_sensor_158d0002b7ceac_battery_level.state}}"
        friendly_name: Kitchen Door Sensor Battery Level
        unit_of_measurement: '%'
        icon_template: mdi:battery-charging
        

I have had a look around but can’t seem to find the answer.

Cheers

2 Likes

Try:

{{states.binary_sensor.door_window_sensor_158d0002b7ceac.attributes.battery_level}}

Or even better:

value_template: "{{ state_attr('binary_sensor.door_window_sensor_158d0002b7ceac', 'battery_level') }}"

This will raise no warning on HA start if the binary sensor is not initialized.

4 Likes

Thanks,

I will study this.

Cheers,

This was one of the variations I tried.

In NodeRed you can simply read them out with the Debug Node (Set it to show the complete log, not just payload). Then work with the messages as usual.

Instead of creating individual template sensors to display battery level in your frontend, you could use this custom card. I found out about it recently, and it works great. Figured I’d share.

1 Like

I will still create templates for node red and notifications, but I will also investigate this, looks good. I do have some RF sensors as well which only send out a Boolean battery low signal. I haven’t tried a custom card yet and was looking at the bars one for wifi strengths of my tasmota things.

Hi @Tediore,

How do I use a custom card? I think I followed the instructions, i.e. copied the .js file from github into my www folder. I then created a ui-lovelace.yaml file on the root of my hassio (raspberry pi 3) sd card and copied in the config and re-started HA. Should this now show up when I try to add a card or is there more to it?

In Lovelace, click the overflow menu in the upper-right, click Configure UI, click the overflow menu again, and click Raw config editor. Then add the card config under resources:. It should look like this:

resources:
  - url: /local/battery-entity.js?v=0.1
    type: module

After saving that, the card should be immediately available without the need to restart. Alternatively, navigate to /config/.storage/lovelace and add the same config as above. It’s easier to do it the Lovelace way though.

Typically not that easy, I don’t have a resources section there already so i added it manually and saved it but still no custom card.

Ah I see what’s going on. Custom cards doesn’t show up in the UI when you go to add a card, you have to select “manual card” and enter the config yourself. (Forgot to mention that, sorry). So you’d enter something like this:

- type: custom:battery-entity
  entity: sensor.front_door_lock_battery

See here for all the configuration options for this custom card.

Edit: this is how I have it set up as part of an entity card to display multiple entities:

entities:
  - critical: 15
    entity: binary_sensor.front_closet
    type: 'custom:battery-entity'
    warning: 30
  - critical: 15
    entity: zha.lumi_weather_1
    type: 'custom:battery-entity'
    warning: 30
  - critical: 15
    entity: zha.lumi_weather_2
    type: 'custom:battery-entity'
    warning: 30
  - critical: 15
    entity: zha.water_sensor_1
    type: 'custom:battery-entity'
    warning: 30
  - critical: 15
    entity: zha.water_sensor_2
    type: 'custom:battery-entity'
    warning: 30
  - critical: 15
    entity: zha.button_1
    type: 'custom:battery-entity'
    warning: 30
  - critical: 15
    entity: binary_sensor.motion_sensor_motion
    name: Hue motion sensor
    type: 'custom:battery-entity'
    warning: 30
show_header_toggle: false
title: Other sensor battery status
type: entities
2 Likes

All I can say is smashing, I am still at the beginning of my HA journey and loving it. I would be lying if i said i really understand what i am doing but seem to be getting results with help from the community. Thanks :grin:

batteries

Now to get the RF ones looking pretty. Got to capture them first though.

Hi, I also had a question.

I want to look at the value of a attribute. But how I do that?

This what I have for now. But now it looks at the state. And when I fill in the right date I get the results what I want.

{{ states.sensor|selectattr('state','eq','03-02-2021')|map(attribute='name')|join(', ') }}

Here I want to look at het attribute value of “days_until_collection_date”. But I get now results.

{{ states.sensor|selectattr('state.days_until_collection_date)','eq','11')|map(attribute='name')|join(', ') }}

What is wrong?

Hi all,
I have the same issue here:
Sonoff LAN installed (using online), TH10 connected. found the device.
2021-02-26 08_56_48-Window
I can use the switch and turn it on and off, but I did not find out how to get the value of the temperature sensor for the dashboard, or in the end for nabu casa.

Ok, fixed it. When exporting the temperature value:
2021-02-26 11_00_01-Window
sonoff creates a sensor:
2021-02-26 11_01_31-Window
. my fault…

hello I have an attribute that detects the missing level of the Blue of my car, I have configured the template like this but it doesn’t work, what am I wrong?

  - platform: template
    sensors:
      evoque_adblue_level:
        friendly_name: "Rifornire adblue"
        unit_of_measurement: 'Lt'
        value_template: "{{ state_attr('extExhaustFluidVolumeRefillLitresx10') }}"

The template should look something like that:

{{ state_attr('sensor.name_of_the_sensor', 'name_of_the-attribute') }}