Get a specific attributes on an entity

Hi guys,

New to HASS and struggling with something that would appear to be quite basic.

I have an entity with the following attributes:

{
  "battery_level": 100,
  "friendly_name": "Brightness",
  "node_id": 2,
  "unit_of_measurement": "lux"
}

I want a view to show me batteries of my devices so want to access the battery_level of the object above. I tried this:

batteries:
  name: Batteries
  view: yes
  icon: mdi:battery-charging-100
  entities:
    - sensor.fibaro_system_fgms001_motion_sensor_luminance_2.battery_level

But it doesn’t seem to work. Help? :smiley:

You need to create a sensor template like this:

- platform: template
  sensors:
    fibaro_sensor:
      value_template: '{{ states.sensor.fibaro_system_fgms001_motion_sensor_luminance_2.attributes.battery_level }}'
      unit_of_measurement: '%'
5 Likes

Thanks devdelay: it works!

Anyone knows whats is wrong in my config?
I can’t get the template option work in hass (last version)…

sensor:
  - platform: yr
    monitored_conditions:
      - symbol
      - windSpeed
      - humidity
      - temperature
      - precipitation
      - fog

  - platform: miflora
    mac: C4:7C:8D:62:A8:B7
    name: Bonsai
    force_update: false
    median: 3
    monitored_conditions:
      - moisture
      - light
      - temperature
      - conductivity
      - battery

  - platform: template
    sensors:
      QTBattery_level:
        value_template: '{{ states.sensor.temperature_158d0001a2c2c7.attributes.battery_level }}'
        unit_of_measurement: '%'


Failed config
      sensor.template:
        platform: template
        sensors: [source /home/homeassistant/.homeassistant/configuration.yaml:57]
          QTBattery_level: [source /home/homeassistant/.homeassistant/configuration.yaml:58]
            unit_of_measurement: %
            value_template: {{ states.sensor.temperature_158d0001a2c2c7.attributes.battery_level }}

    Successful config (partial)
      sensor.template:

Try with lower case letters:

- platform: template
    sensors:
      qtbattery_level:
        value_template: '{{ states.sensor.temperature_158d0001a2c2c7.attributes.battery_level }}'
        unit_of_measurement: '%'

Solved… Tks :slight_smile:

I’m new to HA and any sort of programming. I have a Dyson 360 Eye and want to extract the attributes from it. These include battery, status, position and more.
Do I have to set up a platform: template in sensors.yaml for each attribute, or can I list them in some way under a single platform? Similar to s3Pol’s example for platform: yr? If so what is the formatting for this please?
Thanks very much for any advice.