Skip to content

Instantly share code, notes, and snippets.

@Didgeridrew
Created February 1, 2024 02:09
Show Gist options
  • Save Didgeridrew/b5ba80dcbb6fc0eab7842a6698980074 to your computer and use it in GitHub Desktop.
Save Didgeridrew/b5ba80dcbb6fc0eab7842a6698980074 to your computer and use it in GitHub Desktop.
HA - Trigger Contexts Template Example
alias: zTest Context Templates
description: ""
trigger:
- platform: state
entity_id:
- switch.kitchen_lightswitch
to: "on"
variables:
id: "{{trigger.to_state.context.id}}"
parent: "{{ trigger.to_state.context.parent_id }}"
user: "{{ trigger.to_state.context.user_id }}"
context:
Manual: "{{ parent is none and user is none }}"
Auto: "{{ id is not none and parent is not none }}"
UI: "{{ id is not none and user is not none }}"
type: "{{ (context.items()|selectattr(1, 'eq', True)|first)[0] }}"
condition:
- condition: template
value_template: "{{ type in ['UI', 'Manual' ]}}"
action:
- service: persistent_notification.create
data:
message: |
Type: {{type}}
Context: {{ context }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment