When defining a new style template sensor, it isn’t possible to self reference the sensor in the icon template. A related issue referring to the old style has been logged and resolved before. By not allowing this, the only alternative is to create an intermediate helper sensor, which seems unnecessary.
I logged an issue before (58056), which was closed and locked. The solution suggested doesn’t work and causes an infinite loop. Thus, there is no way to have the icon template update based on the sensor’s own status change.
What I expected to work:
template:
- trigger:
- platform: event
event_type: amcrest
event_data:
event: CallNoAnswered
payload:
action: Start
binary_sensor:
name: Doorbell Rang
icon: "{{ 'mdi:bell-ring-outline' if is_state('binary_sensor.doorbell_rang', 'on') else 'mdi:bell-outline' }}"
state: true
auto_off: 5 # seconds
What was suggested, but causes an infinite loop:
- trigger:
- platform: event
event_type: amcrest
event_data:
event: CallNoAnswered
payload:
action: Start
- platform: state
entity_id: binary_sensor.doorbell_rang
to: ~
binary_sensor:
name: Doorbell Rang
# icon: mdi:bell-outline
icon: "{{ 'mdi:bell-ring-outline' if is_state('binary_sensor.doorbell_rang', 'on') else 'mdi:bell-outline' }}"
state: true
auto_off: 5 # seconds
This is the current issue: Template loop detection breaks useful self references in templates · Issue #39932 · home-assistant/core (github.com).
I would really like to avoid having to create a template sensor from a template sensor.