Hello all,
Could someone help me figure out why I would be getting push notifications that have a title but body has no entities in it?
Essentially, what is happening is that I’ll get a notification of a device being an issue and it is correct. However, after I go fix the device which takes the unavailable entities sensor to 0, I get another notification that has no entities in it. (So a blank one)
Below is my automation. I haven’t been able to look at the persistent notification just yet so I’m not sure if it is doing the same thing or if it still looks fine. I just noticed this behavior on my phone recently.
Below is the automation I am using to call the sensor.—> I have verified that the sensor does have a value of 0.
alias: (ACTION- AUTOMATIC- SECURITY- NOTIFICATION) Unavailable Entities Notification
description: >-
Create persistent notification if there are unavailable entities, dismiss if
none.
trigger:
- platform: state
entity_id: sensor.unavailable_entities
to: null
condition:
- condition: template
value_template: |
{{ is_number(trigger.from_state.state)
and is_number(trigger.to_state.state) }}
action:
- if:
- condition: numeric_state
entity_id: sensor.unavailable_entities
below: 1
then:
- service: persistent_notification.dismiss
data:
notification_id: unavailable_entities
else:
- service: persistent_notification.create
data:
title: Unavailable Devices
message: |-
- {{ expand(state_attr('sensor.unavailable_entities','entity_id'))
|map(attribute='name')|join('\n- ') }}
notification_id: unavailable_entities
- service: script.text_notify
data:
who: parents
title: Unavailable Devices
message: >-
{{
expand(state_attr('sensor.unavailable_entities','entity_id'))|map(attribute='name')|join('\n')
}}
group: null
tag: null
Additionally, here is my package where I have only made changes to the individual entity area and select attr filters.
###################################################################################################
## Package - Unavailable Entities Sensor
## Count and list entities with a state of unavailable, unknown, or none (null)
## See README for customization options.
## https://github.com/jazzyisj/unavailable-entities-sensor/blob/main/README.md
###################################################################################################
# NOTE: Home Assistant v2021.12 required. For older versions please see README
# REQUIRED - This is the template sensor
template:
- sensor:
- name: "Unavailable Entities"
unique_id: unavailable_entities
icon: "{{ 'mdi:alert-circle' if states('sensor.unavailable_entities')|int(0) > 0 else 'mdi:check-circle' }}"
unit_of_measurement: entities
state: >
{% if state_attr('sensor.unavailable_entities','entity_id') != none %}
{{ state_attr('sensor.unavailable_entities','entity_id')|count }}
{% endif %}
attributes:
entity_id: >
{% if state_attr('group.ignored_unavailable_entities','entity_id') != none %}
{% set ignore_seconds = 3600 %}
{% set ignore_ts = (now().timestamp() - ignore_seconds)|as_datetime %}
{% set entities = states|rejectattr('domain','in',['group','button','automation','scene','script'])|selectattr('state','in',['unavailable','unknown','none'])|list %}
{% set buttons = states.button|selectattr('state','eq','unavailable')|list %}
{{ (entities + buttons)
|rejectattr('entity_id','in',state_attr('group.ignored_unavailable_entities','entity_id'))
|rejectattr('entity_id','search','keymaster')
|rejectattr('entity_id','search','weatherbit_')
|rejectattr('entity_id','search','media_player')
|rejectattr('last_changed','ge',ignore_ts)
|rejectattr('entity_id','search','weatheralerts_')
|rejectattr('entity_id','search','octoprint_')
|rejectattr('entity_id','search','westonspc_')
|map(attribute='entity_id')|list }}
{% endif %}
# REQUIRED - Add any entities you do not wish to monitor in this group.
# IMPORTANT - This group MUST exist even if empty for sensor template to render.
group:
ignored_unavailable_entities:
entities:
- sensor.unavailable_entities # prevent template loop warnings?
- binary_sensor.garage_door_access_control_barrier_sensor_low_battery_warning
- binary_sensor.garage_door_access_control_barrier_sensor_not_detected_supervisory_error
- binary_sensor.garage_door_access_control_barrier_unattended_operation_has_been_disabled_per_ul_requirements
- binary_sensor.garage_door_home_security_tampering_product_cover_removed
- binary_sensor.garage_door_low_battery_level
- light.desk_lamp
- sensor.gym_active_app
- sensor.gym_active_app_id
- sensor.living_room_active_app
- sensor.living_room_active_app_id
- sensor.master_bedroom_active_app
- sensor.master_bedroom_active_app_id
- select.living_room_channel
- select.gym_channel
- select.master_bedroom_channel
- sensor.weatheralerts_alert_3_last_changed
- sensor.weatheralerts_alert_4_last_changed
- sensor.weatheralerts_alert_5_last_changed
- sensor.weatheralerts_alert_3_most_recent_active_alert
- sensor.weatheralerts_alert_4_most_recent_active_alert
- sensor.weatheralerts_alert_5_most_recent_active_alert
- sensor.washer_last_complete
- sensor.pirateweather_precip
- sensor.front_door_motion_away_count
- sensor.lightning_near_home_lightning_azimuth
- sensor.lightning_near_home_lightning_distance
- sensor.holiday
# OPTIONAL - filter template loop warnings from the Home Assistant log.
logger:
filters:
homeassistant.components.template.template_entity:
- "Template loop detected while processing event"
# OPTIONAL Example automation to demonstrate how you can utilize this sensor
# SEE Automation.yaml
If I have an entity or rejectattr (i.e. deleted entities and this file hasn’t been updated to match) that isn’t in my home assistant setup anymore, could that be causing this issue?