@NotoriousBDG If my findings are accurate, Install Instructions 13. in battery_alert.yaml should be amended…
Yep that appears to have worked, thank you very much for your time and persistence.
Ian
You’re most welcome! I learned a lot in this exercise…
You also helped me to learn a lot, thanks again.
Out of interest, I have been experimenting, this code also works, they issue was the additional spaces that were in front of Full and Low. Good old YAML spacing
customize:
camera.blink_front_door_2:
battery_template_string: >-
{%- if value_json.value == 'ok' -%}
Full
{%- else -%}
Low
{%- endif -%}
Really? Does MQTT look like this then?
{
"name": "Living Room Battery",
"state_topic": "homeassistant/sensor/living_room_battery/state",
"value_template": "{%- if value_json.value == 'ok' -%}
Full
{%- else -%}
Low
{%- endif -%}",
"icon": "mdi:battery",
"unique_id": "living_room_battery",
"json_attributes_topic": "homeassistant/sensor/living_room_battery/attributes"
}
Documentation item 13 does not have indents either…
## homeassistant:
## customize:
## sensor.sensor_with_battery_attibute_template:
## battery_template_string: >-
## {%- if value_json.value < 2 -%}
## Low
## {%- else -%}
## Full
## {%- endif -%}
No ends up as:
{
"name": "blink Front Battery",
"state_topic": "homeassistant/sensor/blink_front_door_2_battery/state",
"value_template": "{%- if value_json.value == 'ok' -%} Full {%- else -%} Low {%- endif -%}",
"icon": "mdi:battery",
"unique_id": "blink_front_door_2_battery",
"json_attributes_topic": "homeassistant/sensor/blink_front_door_2_battery/attributes"
}
Ooopps, the hazards of coping and pasting
My indentation must have triggered line returns… Interesting!
Must remember that one! Live & learn…
This package is phenomenal. It caught all my zwave blind, remote, and lock battery levels. Even electric car battery and phones. I also have Wyze sensors and once I let it run the “create battery sensor from attributes” automation to create them I am now unable to send/receive the notification and getting the following log error:
2021-01-05 12:26:03 INFO (MainThread) [homeassistant.components.automation.battery_persistent_notification] battery_persistent_notification: Running automation actions
2021-01-05 12:26:03 ERROR (MainThread) [homeassistant.helpers.condition] Error during template condition: UndefinedError: 'None' has no attribute 'attributes'
edit: I noticed that the error is only on the persistent and clear automation. I looked into those and saw it references the group of batteries that the package makes. I had that automation turned off. After manually executing it, the group was updated and now I receive notifications again. I’ll leave that one on.
Now to remove batteries I don’t care about. Thanks!
First, let me thank you for this script. It is something that should be IMO a part of the core HA system.
I’ve got it running and everything seems to be working fine, I’m just struggling with one thing. I have a few entities that contain ‘Battery’ in their name, but they don’t really represent battery percentage (or level) value. That includes entity called sensor.sm_g965f_charger_type
(is it the word ‘charger’ that triggers its inclusion?).
Anyway, I’d like to exclude these entities from being processed by the script. I can’t use battery_sensor_creation_disabled
, because they are not generated by the script. And I can’t find counterpart of this configuration element for real entities. Is that even possible, or is there a chance that it could be added? Or is there some other way how this could be done?
Thanks!
Just add your real entity & the new attribute flag for battery-alert to your customize section in configuration.yaml.
I have my customize: broken out into customize.yaml
I’ve added those attribute flags there like so…
configuration.yaml:
####################################################################
# Configure a default setup of Home Assistant (frontend, api, etc) #
####################################################################
default_config:
homeassistant:
customize: !include customize.yaml
customize.yaml:
sensor.coffee_machine:
templates:
theme: ''
icon_color: 'if (state == ''Off'') return ''slategray''; if (state == ''Not Ready'')
return ''#FFBF00''; if (state == ''Ready'') return ''lime''; if (state == ''Brewing'')
return ''orangered'';'
person.daniel_brunt:
entity_picture: /local/images/Cobra.jpeg
binary_sensor.ecolink_garage_door_tilt_sensor:
device_class: garage_door
switch.mimolite_switch:
icon: hass:power
device_type: garage
sensor.vog_l04_battery_health:
battery_alert_disabled: true
sensor.vog_l04_battery_level:
battery_alert_disabled: true
sensor.vog_l04_battery_state:
battery_alert_disabled: true
sensor.vog_l04_charger_type:
battery_alert_disabled: true
sensor.browser_mod_2d3872d4_795db051:
battery_alert_disabled: true
battery_sensor_creation_disabled: true
sensor.browser_mod_6eba5467_e33aed8e:
battery_alert_disabled: true
battery_sensor_creation_disabled: true
sensor.browser_mod_ae7bcb81_077da789:
battery_alert_disabled: true
battery_sensor_creation_disabled: true
device_tracker.life360_daniel_brunt:
battery_alert_disabled: true
battery_sensor_creation_disabled: true
sensor.brunt_win10_battery_level:
battery_alert_disabled: true
battery_sensor_creation_disabled: true
sensor.brunt_win10_battery_remaining:
battery_alert_disabled: true
battery_sensor_creation_disabled: true
sensor.canon_mg7500_series_yellow:
icon: mdi:water
templates:
hs_color: "return [255,255,0]; \n"
binary_sensor.4in1_pir_sensor_sensor:
device_class: motion
light.garage_light:
device_class: light
Thanks, that’s what I did:
sensor.sm_g965f_charger_type:
battery_alert_disabled: true
And in the Developer/States view I can see that the attribute was correctly set:
But I still see it among the sensors being monitored (it is in the list displayed after I click on Battery Status
label created by the recommended Lovelace yaml snippet).
Do I perhaps need to somehow manually remove the sensor from the list of monitored entities?
Ah, I see. Thanks!
If the package is creating an MQTT sensor that you don’t want then add battery_sensor_creation_disabled:
Hello all,
I have not been working with the HA for very long. I just have a question.
I cannot set a time anywhere when testing for the status of the batteries. When does this happen? Is it true that if the battery level falls below a certain percentage that a message is passed on?
Thank you for your response.
Persistent notifications default to every 1/4 hour…
battery_alert.yaml
:
################################################
## Automation
################################################
automation:
- alias: battery_persistent_notification
initial_state: 'on'
trigger:
- platform: time_pattern
minutes: '/15'
seconds: 00
- platform: state
entity_id:
- input_number.battery_alert_threshold_min
- input_number.battery_alert_threshold_max
Yes, if between min_alert and max_alert thresholds…
Hello everyone,
First thanks @NotoriousBDG for this, it’s great and I hope one day something like this will be implemented in the core of HA.
I do have one question, maybe because I haven’t completely understood how this whole system works.
In the group.battery_status, I have many duplicates. All my aqara sensors appear twice, first the zigbee2mqtt entity, and second the mqtt entity created by this script.
Is it intended ? Looking at the automation code for the group, it seems to pick up every entity with anything related to battery (attributes, icon, name, id, etc)
Does the system need it own entity to work ?
Or can I just ask him to not create a sensor for those entities that already have one ?
Thanks
I recall there was a change in HA core sometime in 2020 that autogenerated battery entities for the xiaomi integration… you can disable them if you want - AFAIK they are only used in the config->integrations-> devices page. Or delete the package created ones and use the auto ones.
I’ve got the package generated ones for my xiaomi integration and auto generated ones for my other zigbee - they all show in the battery group
Hello I added the Battery_allert.yaml. However, my Homamatic devices only show 2% battery. Where or do I have to adjust something so that the values are displayed correctly