I modified the sensor in this topic to tell me the name of the logged user and use Anchors and Aliases to facilitate the creation of other sensors:
- trigger:
- platform: state
entity_id: light.quarto
to: ["on", "off"]
sensor:
- name: "Quarto Triggered by"
<<: &triggered_by
state: >
{% set c_id = trigger.to_state.context.id %}
{% set c_parent = trigger.to_state.context.parent_id %}
{% set c_user = trigger.to_state.context.user_id %}
{% set light_state = trigger.to_state.state %}
{% set p = states.person | selectattr('attributes.user_id', 'eq', trigger.to_state.context.user_id) | list %}
{% if c_id != none and c_parent == none and c_user == none %}
Physical {{light_state}}
{% elif c_id != none and c_parent == none and c_user != none %}
{{ p[0].attributes.friendly_name|title if p | count == 1 else 'Node Red' }} {{light_state}}
{% elif c_id != none and c_parent != none and c_user == none %}
Automation {{light_state}}
{% else %}
Unknown {{light_state}}
{% endif %}
- trigger:
- platform: state
entity_id: light.sanca_sala
to: ["on", "off"]
sensor:
- name: "Sanca Sala Triggered by"
<<: *triggered_by
- trigger:
- platform: state
entity_id: light.cozinha
to: ["on", "off"]
sensor:
- name: "Cozinha Triggered by"
<<: *triggered_by