Battery state level from Hue motion sensor

I want to read battery state level from my Hue motion sensor (image attached).
The entity-id is ‘binary_sensor.vardagsrum_sensor_motion’
I dont get it working … here is my code:

  - platform: template
    sensors:
      vardagsrum_sensor_battery:
        entity_id: binary_sensor.vardagsrum_sensor_motion
        friendly_name: 'Vardagsrum motion sensor batteri'
        value_template: '{{state_attr("binary_sensor.vardagsrum_sensor_motion", "battery")}}'
        unit_of_measurement: percent

Battery State

I change it to this … but still no battery value

  - platform: template
    sensors:
      vardagsrum_motion_battery:
        friendly_name: 'Vardagsrum sensor battery'
        value_template: '{{state_attr("binary_sensor.vardagsrum_sensor_motion", "battery")}}'
        unit_of_measurement: percent

Where is the error?

Are you sure it is called battery?

In the image you posted, it refers to it as battery level.

Go to Developer Tools > States, find binary_sensor.vardagsrum_sensor_motion, look in its attributes and confirm if it is named battery level (or maybe battery_level). Change your template to match the correct name:

        value_template: '{{state_attr("binary_sensor.vardagsrum_sensor_motion", "battery level")}}'

Thanks … you solved my problem
Have a nice day!!!

1 Like

Glad to hear it solved the problem.

Please mark my previous post with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has an accepted solution. It also helps others with a similar question to find the answer.

OK … done

I just moved my Hue Motion Sensor from Hue to ZHA. I see a battery entity, but no battery level is being reported. Maybe it takes a while for first report?

it’s defnitely not an attribute of the sensor anymore.

does battery still work? i’m on 113.2

here is the battery sensor

(21st November 2020).

Thanks for that.

I’ve just used it and had to use:
“battery_level” in place of “battery level”
and
‘%’ (including single quotes) in place of percent.

Example from my configuration.yaml …

# ... Outside
      hue_motion_sensor_outdoor_battery_level:
        friendly_name: "Hue Motion Sensor Temperature Outside Battery Level"
        value_template: '{{state_attr("binary_sensor.hue_motion_sensor_outdoor_motion", "battery_level")}}'
        unit_of_measurement: '%'

Does that work for you with the Hue Motion sesnor with ZHA (not using the Hue integration)? It does not for me

It work well with a Philips Hue motion sensor. I don’t know what ZHA is so I can’t answer. I’m new to this and I’m using Home Assistant on a Raspberry Pi 3b.

I am very new here. Have been looking a lot on the net for 2 days and am now trying something.
I think I have the same problem, but I really don’t know where my mistake is.
please. See also attachment.

I think your syntax is incorrect. Try commenting out line 32 (battery_levels) in your configuration file.

battery_levels is an invalid domain name (sensor, light, switch, etc are all domain names).

In your configuration.yaml file, look for a domain name called sensor: because that’s where you should put all sensor definitions including the Template Sensor you just created.

If it doesn’t have an existing sensor: domain then rename battery_levels: to sensor: and that should eliminate the cause of the error.

Thanks @All … very helpful for me …

Sensor Include in configuration.yaml to keep configuration.yaml as lean as possible

sensor: !include_dir_list sensors/

Create File for my Hue Motion Sensors with nice Battery Icons in sensors/battery/Battery Hue Motion Sensors.yaml

platform: template
sensors:
  motion_deko_usm_battery_level:
    friendly_name: 'Motion Deko USM battery level'
    value_template: '{{state_attr("binary_sensor.motion_deko_usm_motion", "battery_level")}}'
    icon_template: '{%- if state_attr("binary_sensor.motion_deko_usm_motion", "battery_level") <= 5 %}mdi:battery-outline{%- elif state_attr("binary_sensor.motion_deko_usm_motion", "battery_level") >= 95 %}mdi:battery{% else %}mdi:battery-{{(state_attr("binary_sensor.motion_deko_usm_motion", "battery_level")|float / 10)|round*10}}{%- endif %}'
    unit_of_measurement: '%'
  motion_pia_buro_battery_level:
    friendly_name: 'Motion Pia Büro battery level'
    value_template: '{{state_attr("binary_sensor.motion_pia_buro_motion", "battery_level")}}'
    icon_template: '{%- if state_attr("binary_sensor.motion_pia_buro_motion", "battery_level") <= 5 %}mdi:battery-outline{%- elif state_attr("binary_sensor.motion_pia_buro_motion", "battery_level") >= 95 %}mdi:battery{% else %}mdi:battery-{{(state_attr("binary_sensor.motion_pia_buro_motion", "battery_level")|float / 10)|round*10}}{%- endif %}'
    unit_of_measurement: '%'