homeassistant:
input_boolean:
battery_notifications:
name: Notificações da bateria
initial: 'on'
icon: 'mdi:battery-charging-wireless'
sensor:
- platform: template
sensors:
p_cozinha_battery_level:
friendly_name: Porta cozinha
unit_of_measurement: '%'
value_template: >-
{%- if states.binary_sensor.door_window_sensor_158d00018354d0.attributes.battery_level %}
{{ states.binary_sensor.door_window_sensor_158d00018354d0.attributes.battery_level|round }}
{% else %}
{{ states.sensor.door_sensor.state }}
{%- endif %}
icon_template: >
{% set battery_level = states.sensor.door_sensor.state|default(0)|int %}
{% set battery_round = (battery_level / 10) |int * 10 %}
{% if battery_round >= 100 %}
mdi:battery
{% elif battery_round > 0 %}
mdi:battery-{{ battery_round }}
{% else %}
mdi:battery-alert
{% endif %}
p_principal_battery_level:
friendly_name: Porta principal
unit_of_measurement: '%'
value_template: >-
{%- if states.binary_sensor.door_window_sensor_158d00015a954e.attributes.battery_level %}
{{ states.binary_sensor.door_window_sensor_158d00015a954e.attributes.battery_level|round }}
{% else %}
{{ states.sensor.door_sensor.state }}
{%- endif %}
icon_template: >
{% set battery_level = states.sensor.door_sensor.state|default(0)|int %}
{% set battery_round = (battery_level / 10) |int * 10 %}
{% if battery_round >= 100 %}
mdi:battery
{% elif battery_round > 0 %}
mdi:battery-{{ battery_round }}
{% else %}
mdi:battery-alert
{% endif %}
Automação para receber os alertas:
automation:
- alias: Alerta Para Substituir a Bateria dos Sensores
initial_state: true
trigger:
platform: numeric_state
entity_id:
- sensor.p_cozinha_battery_level
- sensor.p_principal_battery_level
below: 5
condition:
- condition: template
value_template: '{{ states.input_boolean.battery_notifications.state == "on" }}'
action:
- service: notify.my_pushbullet
data_template:
message: 'Alerta! {{ trigger.from_state.attributes.friendly_name }} necessita de ser substituída, apenas tem {{ trigger.from_state.state }}% de bateria restante!!'