That only works for the color of the icon displayed in the panel, not for automatic alerting. As you pointed out, that would have to be done by his own automation.
Small improvements:
action:
- service: persistent_notification.create
data_template:
message: >
{% set value = trigger.to_state.state | int %}
{% if value <= 17 %}
{{ trigger.to_state.name }}
![image](/local/battery-empty-white.png)
{% else %}
{{ trigger.to_state.name }}
![image](/local/battery-low-white.png)
{% endif %}
title: >
{% set value = trigger.to_state.state | int %}
{% if value <= 17 %}
Battery Empty
{% else %}
Battery Low
{% endif %}
notification_id: "battery"
Iām trying to check the batteries of some of my Abode sensors.
The attributes are
attribution: Data provided by goabode.com
device_id: 'RF:00751180'
battery_low: false
no_response: false
device_type: GLASS
friendly_name: Basement Window
device_class: connectivity
I tried using something like this
homeassistant:
customize:
binary_sensor.bedroom_keypad:
battery_template_string: >-
{%- if value_json.battery_low -%}
Low
{%- else -%}
Full
{%- endif -%}
But that doesnāt seem to work. Is there a way to easily do what I want?
I threw this together in Dev Tools, Template editor:
Entity: binary_sensor.ozw_network_status
Attribute: isBridgeController true|false
battery_template_string:
{%- if state_attr('binary_sensor.ozw_network_status', 'isBridgeController') -%}
Low
{%- else -%}
Full
{%- endif -%}
and it returned Low.
If I change the template to:
{%- if not state_attr('binary_sensor.ozw_network_status', 'isBridgeController') -%}
it returns Full:
Might help get you on the right path!
I tried something similar. Neither will get it to show up in the UI.
Itās almost like there is something I need to do to tell the UI to add an entity. It seems if the entity is already known to have a battery I can manipulate the value, but doing this wonāt add it.
Iām pretty new to this, so hopefully its just something small Iām missing.
I recall when I started HA, back in June. A long LONG time ago and many, MANY hours of learning, questioning, googling, reading, experimenting, etcā¦
Can you provide more info? What EXACTLY are you trying to do?
Iām thinking maybe you might be needing to create a template sensor or binary_sensor?
The Abode only has one entity? with an attribute battey_low: true | false?
Are you trying to create an automation to alert you when the attribute changes from false to true?
Do you have other battery entities you want to monitor?
I am thinking you might want a binary sensor based on a template like theseā¦
- platform: template
sensors:
living_room_eco_temperature:
friendly_name: Living Room ECO Temperature
value_template: >-
{% if 19.5 < state_attr('climate.living_room', 'temperature')|round(1,"half") < 27.5 %}
false
{% else %}
true
{% endif %}
icon_template: >-
{% if 19.5 < state_attr('climate.living_room', 'temperature')|round(1,"half") < 27.5 %}
hass:none
{% else %}
hass:leaf
{% endif %}
# Allow Automation
allow_automation:
friendly_name: "Allow Automation"
value_template: "{{ is_state('input_boolean.allow_automation_execution', 'on') }}"
# System Ready
system_ready:
friendly_name: "System ready"
value_template: "{{ is_state('input_boolean.system_ready', 'on') }}"
device_class: moving
# South Patio Lux
south_patio_lux_override:
friendly_name: "South Patio Lux Override"
value_template: "{{ states('sensor.lumi_lumi_sen_ill_mgl01_illuminance')|float > states('input_number.outside_lux_level')|float }}"
# Bedroom Lux
bedroom_lux_override:
friendly_name: "Bedroom Lux Override"
value_template: "{{ states('sensor.lumi_lumi_sensor_motion_aq2_illuminance')|float > states('input_number.bedroom_lux_level')|float }}"
# New Sesnsor Lux
new_sensor_lux_override:
friendly_name: "New Sensor Lux Override"
value_template: "{{ states('sensor.lumi_lumi_sensor_motion_aq2_d2f18504_illuminance')|float > 10.0 }}"
You would need the entity_idās for the Abode sensors and then create new template sensors from their attribute battery_low
if you want to use/display those new entities in the UI.
My configuration.yaml has
binary_sensor: !include binary_sensors.yaml
from which the above is shown.
Otherwise, you could just template the condition test in your automationsā¦
BTW, welcome to Home Assistant!
How new to HA are you?
custom:battery-state-card is a nice add-on as is the add-on in this thread but it only triggers on actual battery level threshold which your templated entity would not qualify,
bulk_rename:
- from: ': Battery Level'
- from: Battery Level
- from: Battery
collapse: 5
color_thresholds:
- value: 33
color: red
- value: 66
color: yellow
- value: 100
color: green
entities:
- entity: sensor.vog_l04_battery_level
charging_state:
entity_id: sensor.vog_l04_battery_state
state: charging
icon: 'mdi:flash'
color: yellow
- entity: sensor.zm1701_electronic_deadbolt_door_lock_battery_level
color_thresholds:
- value: 70
color: red
- value: 85
color: yellow
- value: 100
color: green
filter:
include:
- name: entity_id
value: '*_battery_level'
secondary_info: last_updated
sort_by_level: asc
type: 'custom:battery-state-card'
Thanks for some of the info. Iāve been messing around with HA for 4 days so far.
I know i can create a binary_sensor for each of the entities. Abode is a security system, so all my door/window contacts and a few other things would need the same treatment.
Iām not trying to create an automation or anything. Iām literally just trying to get it to show up in the UI for this package. Ideally i would just be able to tell it to use these entities and how to gauge battery levels of them.
So, you will need to create new binary_sensors based on a template of the Abode entiretyās attributeā¦
Comprehendez?
Man, took me more than 4 days just to install HA!!!
Yep. Thanks.
I created the following binary_sensor
and the values seem to be correct. binary_sensor.garage_keypad.battery_low
is a boolean, so this gets set to on
when battery_low
is true
and off
when it is false
. Now Iām just trying to figure out out to get it to show up in the UI. I was under the impression that setting device_class
to battery
would take care of it. Is there something else I need to do?
- platform: template
sensors:
garage_keypad_battery:
device_class: "battery"
friendly_name: "Garage Keypad Battery"
value_template: >-
{{ state_attr("binary_sensor.garage_keypad", "battery_low") }}
Have you made the leap from Lovelace default view which shows everything to your own views? If not, it should be there, somewhere. If you have, add it to an entities card. The entity id should be binary_sensor.garage_keypad_battery
. I presume you can see it in Dev tools, States?
This package dynamically generates a group for battery statuses. I could add it to a card manually if i want but that wonāt help with the notification generation that this package provides. I guess Iām wondering why it doesnāt get picked up when that group is generated.
Package is Battery Alert? Iāve not tried it with a templated sensor like yoursā¦
I see the dilemma nowā¦
Ok, so you need a sensor
not a binary_sensor
ā¦
- condition: template
value_template: >-
{%- set threshold = 40 -%}
{%- for item in states.sensor if (item.attributes.battery_level is defined and item.attributes['battery_level'] | int < threshold) or ("battery" in item.name | lower and ((item.state | int < threshold and item.state|int != 0) or item.state | lower == "low" or item.state | lower == "unknown")) -%}
{%- if loop.first -%}
{{ true }}
{%- endif -%}
{%- endfor -%}
Try thisā¦
sensor:
- platform: template
sensors:
garage_keypad_battery:
device_class: "battery"
friendly_name: "Garage Keypad Battery"
value_template: >-
{% if state_attr("binary_sensor.garage_keypad", "battery_low") %}
Low
{% else %}
Full
{% endif %}
It should work. .
Yep, that will definitely work. I actually opted to add it to package itself. I looked through and got some understanding of how i all worked. I opened a PR here that will make all Abode devices work with this plugin by default. It is here if you have any suggestions https://github.com/notoriousbdg/Home-AssistantConfig/pull/28.
Thanks again for all your help @dbrunt
I did some digging into the code (in particular, example 13) and how the rest of the logic works.
## 13. If a battery attribute requires a template to convert it into a string, use customize to add
## `battery_template_string` with the necessary template. The template result must be a string.
## For example, "Low" will trigger low battery notification).
##
## This example will create a battery sensor that contains "Low" if battery_level
## is less than 2
##
## homeassistant:
## customize:
## sensor.sensor_with_battery_attibute_template:
## battery_template_string: >-
## {%- if value_json.value < 2 -%}
## Low
## {%- else -%}
## Full
## {%- endif -%}
which adds an extra attribute battery_template_string
to the original entity.
So, this should work:
customize:
binary_sensor.bedroom_keypad:
battery_template_string: >-
{%- if state_attr('binary_sensor,bedroom_keypad', 'battery_low) -%}
Full
{%- else -%}
Low
{%- endif -%}
There might be a way to use value_json but Iām not sure how.
Your PR though prevents having to do the above! Good work!