Skip to content

Instantly share code, notes, and snippets.

@AlexxIT
Created July 28, 2020 10:01
Show Gist options
  • Save AlexxIT/99ff662fe26e1db9afe27f2a4dd492e8 to your computer and use it in GitHub Desktop.
Save AlexxIT/99ff662fe26e1db9afe27f2a4dd492e8 to your computer and use it in GitHub Desktop.
Home Assistant Context Example
automation:
- trigger:
platform: numeric_state
entity_id: switch.sonoff_th
value_template: >-
{% if states.switch.sonoff_th.context.user_id and states.switch.sonoff_th.state == 'on' %}
1{% else %}0{% endif %}
above: 0
action:
service: persistent_notification.create
data:
message: "Включился юзером"
- trigger:
platform: numeric_state
entity_id: switch.sonoff_th
value_template: >-
{% if states.switch.sonoff_th.context.id == states.automation.every_munute.context.id and states.switch.sonoff_th.state == 'on' %}
1{% else %}0{% endif %}
above: 0
action:
service: persistent_notification.create
data:
message: "Включился автоматизацией"
- alias: every_munute
trigger:
platform: time_pattern
minutes: "*"
action:
service: homeassistant.toggle
entity_id: switch.sonoff_th
@AlexxIT
Copy link
Author

AlexxIT commented Jul 28, 2020

platform: numeric_state используется потому что platform: state не поддерживает шаблоны, а platform: template реагирует вообще на все события в системе.

@mmegaromm
Copy link

Для начинающих пользователей как этим воспользоватся?)

@notabene00
Copy link

{% if trigger.to_state.context.user_id and trigger.to_state.state == 'on' %}

тоже будет работать?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment