The entity_id of those battery sensors don’t have the entity_id that I expect to see. They should be sensor.fib_smoke_sensor1_battery, sensor.fib_smoke_sensor2_battery, sensor.fib_smoke_sensor3_battery, etc. I only have 1 zwave device on a z-stick, and it’s not exhibiting this behavior. I’m suspecting that has something to do with the object_id being different than what I see on my system.
@Tomahawk, can you run this automation on your system then trigger a state change on your smoke sensors? This automation should create a persistent notification for each smoke sensor showing the entity_id and the object_id from the event. If my theory is correct, you’ll see an object_id of brannalarm for all 3 of them.
- alias: object_id_notification
trigger:
- platform: event
event_type: state_changed
condition:
- condition: template
value_template: "{{ trigger.event.data is not none }}"
- condition: template
value_template: "{{ trigger.event.data.new_state is not none }}"
- condition: template
value_template: "{{ trigger.event.data.new_state.attributes is not none }}"
- condition: template
value_template: "{{ trigger.event.data.old_state is not none }}"
- condition: template
value_template: "{{ 'fib_smoke_sensor' in trigger.event.data.entity_id }}"
action:
- service: persistent_notification.create
data_template:
title: "{{ trigger.event.data.entity_id }}"
notification_id: "{{ trigger.event.data.entity_id }}"
message: >
entity_id = {{ trigger.event.data.entity_id }}
object_id = {{ trigger.event.data.new_state.object_id }}
If you’re referring to the jinja template in step 10 of the install instructions, you paste that in http://hassio.local:8123/dev-template. The right hand side will show yaml code that you can use to create a group (Group - Home Assistant). The group yaml goes in your Home Assistant config and not in the package.
Added unique_id to disambiguate sensors with duplicate names
Added source info to mqtt config topic
Consider friendly names and entity_ids that end with _bat as a battery sensor (needed for rflink battery sensors)
Consider entities with icon of battery, battery-alert, or battery-unknown as a battery sensor regardles of its name
Consider entity_ids containing battery as a battery sensor
Changed
Reduce code duplication using yaml anchors and references
Changed MQTT topic to be based on entity_id
Improve method of filtering non-battery devices that have battery in their name. Detection is now based on icon rather than keywords.
@Tomahawk, this version should fix your issue. You’ll need to install the latest package, restart, force your smoke and flood sensors to update, then restart one more time. I’ve fixed the issue by setting the unique_id on the MQTT sensor to the object_id of the source sensor. Please let me know if this version fixes your issue.
@Wim_L, those sensors should be identified as batteries with this latest version. Please try and let me know how it goes.
Works fine. I am getting the battery sensors as expected!
Just one thing that makes me scratch my head. When it comes to the technical naming conversions for the new battery level sensors. Witch as fare I understand is derived from the original sensors friendly name(?)
For (my) case having the same friendly name on all smoke (brannalarm) sensors, the new battery level sensors are getting their name from friendly name and a number behind as the new sensors technical name. That makes me wonder, which new battery level sensor goes to which original sensor?
Maybe when creating the new battery level sensors, just use the original sensor technical name and add “_ZBAT”, “_BATLEV” or something….
Apologies, I completely neglected to mention how to address that. MQTT seniors don’t offer a way to create different entity_id and friendly name in an automated way. The way I addressed the issue was to set the unique_id to the object_id of the source entity, which is more meaningful when you have duplicate friendly names.
To fix your issue, all you have to do is change the entity_id and/or name in entity_registry.yaml, then restart. The unique_id should make it obvious to see where they came from so you can give them better names.
Please, someone can explainme how to use the file battery_alert.yaml?
I have many xiaomi sensors, and to know the status battery i have for each one a sensor… and file begins turn very big. I was reading the topic, where in the beginning, you use a input_boolean, then sensor and at the end and automation, like this:
Later @NotoriousBDG, takes a very good code, that maybe make easy the first option, but i dunno how put in HA.
How to delete old mqtt cache data for battery. As I used the new battery_alert.yaml. This time it shows correct battery level, however it also show the old battery level (which is not correct look like old cache) from mqtt.
example show:
diana_owntrack_battery: 20 <== this is wrong and keep showing all the time.
diana_iphone_battery: 47 <== this is right
The jinja template doesn’t list entities/sensors with battery_level as an attribute, does the package read/include sensors with battery_level as an attribute in alerts?
jinja template:
battery_status:
name: Battery Status
icon: mdi:battery-charging
entities:
{%- for item in states.sensor if (
(
not is_state_attr(item.entity_id, 'battery_alert_disabled', true)
) and (
is_state_attr(item.entity_id, 'device_class', 'battery')
) or (
is_state_attr(item.entity_id, 'icon', 'mdi:battery')
) or (
is_state_attr(item.entity_id, 'icon', 'mdi:battery-alert')
) or (
is_state_attr(item.entity_id, 'icon', 'mdi:battery-unknown')
) or (
'battery' in item.entity_id | lower
and item.attributes.icon is defined
and 'battery' in item.attributes.icon | lower
) or (
'battery' in item.name | lower
and item.attributes.icon is defined
and 'battery' in item.attributes.icon | lower
) or (
(item.entity_id | lower).endswith('_bat')
) or (
(item.name | lower).endswith('_bat')
)
) %}
- {{ item.entity_id }}
{%- endfor -%}
Yes, that’s expected behavior. It does not show entities that have battery levels stored as attributes. There is an automation in the package that automatically creates stand-alone battery sensors for each entity that has battery_level attributes. The jinja code shows them instead of the ones with battery attributes.