Z-Wave device battery level

No, same unsafe message:

{{ states.zwave["__32"].attributes.battery_level }} -> “Error rendering template: SecurityError: access to attribute ‘__32’ of ‘DomainStates’ object is unsafe.”

In that case I have no idea. It could be a bug.

This is the only thread that comes up on google so far I’ve found that has reference to the problem I’m having. It seems related to having a double underscore preceding any other values.

Hi everyone,

This thread it about a year old, but since it best describes the problem I have, I will ask here again :slight_smile:

Does anyone have a working template for “getting” the battery_level “out” so that it can be added to a group and be used in automations (for zwave devices)

I have this (more) zwave devices and I would like to “fetch” the battery_level and present it in a group, but I can’t get it to work.

The template for that should be: {{ states.zwave.hallway_pir.attributes.battery_level }}

1 Like

Use this script/package: Howto create battery alert without creating a template for every device

2 Likes

Thanks @fanaticDavid :slight_smile:

My bad ! - I created the template under binary_sensors.yaml – sooo placing them in sensors did the trick :wink:

Thanks @fanaticDavid for pointing me in the right direction.
If you want a battery icon that adapts to the battery level, you can use this config:

  garage_sensor_battery:
    friendly_name: 'Garage Batteri'
    value_template: >-
      {%- if states.zwave.aeotec_zw120_door_window_sensor_gen5 -%}
        {{ states.zwave.aeotec_zw120_door_window_sensor_gen5.attributes.battery_level }}
      {%- else -%}
        'unknown'
      {%- endif -%}
    icon_template: >-
      {%- if states.zwave.aeotec_zw120_door_window_sensor_gen5 -%}
        {% set battery_level =  states.zwave.aeotec_zw120_door_window_sensor_gen5.attributes.battery_level|int('unknown') %}
        {% set battery_round = (battery_level|int / 10)|int * 10 %}
        {% if battery_level == 'unknown' %}
          mdi:battery-unknown
        {% else %}
          {% if battery_round >= 100 %}
            mdi:battery
          {% elif battery_round > 0 %}
            mdi:battery-{{ battery_round }}
          {% else %}
            mdi:battery-alert
          {% endif %}
        {% endif %}
      {%- else -%}
        'unknown'
         mdi:battery-unknown
      {% endif %}
    unit_of_measurement: '%'
    entity_id: zwave.aeotec_zw120_door_window_sensor_gen5

or you can just set the device_class to ‘battery’ as below:

 office_pir_battery:
      friendly_name: 'office_pir_battery'
      unit_of_measurement: '%'
      device_class: battery
      value_template: >-
       {{ state_attr('zwave.office_pir','battery_level') }}
1 Like

I have been using this package and it seems to work pretty well. Had to tweak it a little for my notification and front end needs, but no complaints so far. Great work by the creator.

2 Likes

Nice :slight_smile:

Thanks for this! Simple and easy… exactly what I needed. :slight_smile:

Yes, but with Lovelace out really consider if you need to create such template sensors now…

You can easily get full battery level GUI display and notifications without a single template sensor and the burden that brings.

Please do tell how?

Try this

https://sharethelove.io/monster-cards/devices-with-low-battery

Works good for me.

Stuff like this drives me crazy! I love Home Assistant, and I easily configured a template and got its working to check battery of my Z-wave devices but … SmartThings gives me battery by default and Motion as sensors that are usable as triggers. SmartThings provides these items to the Integration as well! I am tempted in just using SmartThings as a Z-wave hub of sorts until this is all sorted out. If we can pull all of these other sensors when we join a device, Battery and Motion should also be available. No Wonder Tasmota is so popular with the HA crowd… Cheers!

Is there a way to refresh the battery level? For instance my Schlage door lock died but the battery level was showing as 68%.

So now the state is “dead” but the battery level still shows at 68%…

In the zwave control panel select your lock and then the lock.whatever entity, and select Refresh Entity that will update the battery level.

Do you need to manually refresh the entity to update the battery level or is this just when it fails to refresh on its own?

Thanks.

I believe you can modify the cache to have it refresh on it’s own. You’d have to add the RefreshOnWakeUp flag.

1 Like