- 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 %}
{% set mmw_state = states("binary_sensor." + trigger.to_state.attributes.friendly_name + "_mmw_presence")
if states.binary_sensor
| selectattr('entity_id', 'search', trigger.to_state.attributes.friendly_name|lower)
| map(attribute='entity_id')
| select('search', '_mmw_presence')
| list | count == 1 else states("binary_sensor." + trigger.to_state.attributes.friendly_name + "_movement") %}
{% if c_id != none and c_parent == none and c_user == none %}
Físico {{light_state}} {{mmw_state}}
{% elif c_id != none and c_parent == none and c_user != none %}
{{ p[0].attributes.friendly_name|title if p | count == 1 else 'unknown' }} {{light_state}} {{mmw_state}}
{% elif c_id != none and c_parent != none and c_user == none %}
{% if mmw_state == "on" %}
Scene {{light_state}} {{mmw_state}}
{% else %}
Automação {{light_state}} {{mmw_state}}
{% endif %}
{% else %}
Desconhecido {{light_state}} {{mmw_state}}
{% endif %}
- trigger:
- platform: state
entity_id: light.cozinha
to: ["on", "off"]
sensor:
- name: "Cozinha Triggered by"
<<: *triggered_by
- trigger:
- platform: state
entity_id: light.arthur
to: ["on", "off"]
sensor:
- name: "Arthur Triggered by"
<<: *triggered_by
- trigger:
- platform: state
entity_id: light.lavanderia
to: ["on", "off"]
sensor:
- name: "Lavanderia Triggered by"
<<: *triggered_by
- trigger:
- platform: state
entity_id: light.banheiro
to: ["on", "off"]
sensor:
- name: "Banheiro Triggered by"
<<: *triggered_by
- trigger:
- platform: state
entity_id: light.suite
to: ["on", "off"]
sensor:
- name: "Suite Triggered by"
<<: *triggered_by
1 Like