Skip to content

Instantly share code, notes, and snippets.

@stek29
Created February 3, 2025 01:35
Show Gist options
  • Save stek29/20850b18e07f94ab33e535bd5815aacf to your computer and use it in GitHub Desktop.
Save stek29/20850b18e07f94ab33e535bd5815aacf to your computer and use it in GitHub Desktop.
Home Assistant Blueprint to Trigger actions on Zigbee2MQTT events
---
blueprint:
name: Zigbee2MQTT Action Trigger
description: Trigger an action when a Zigbee2MQTT event occurs.
domain: automation
input:
event_entity:
name: Event Entity
description: "Select the Zigbee2MQTT event entity that will trigger this automation. It should have an `event_type` attribute, which will be checked for conditions."
selector:
entity:
filter:
- domain: event
integration: mqtt
to_event_types:
name: Target Event Types
description: "Comma-separated list of event types for the new state. Leave empty to match any event type."
default: ""
from_event_types:
name: Previous Event Types
description: "Comma-separated list of event types for the previous state before transition. Leave empty to match any event type."
default: ""
not_to_event_types:
name: Excluded Target Event Types
description: "Comma-separated list of event types to ignore for the new state. Leave empty to allow all."
default: ""
not_from_event_types:
name: Excluded Previous Event Types
description: "Comma-separated list of event types to ignore from the previous state before transition. Leave empty to allow all."
default: ""
action:
name: Action to Perform
description: "Define the action to execute when the trigger and conditions are met."
selector:
action:
variables:
var_to_event_types: !input to_event_types
var_from_event_types: !input from_event_types
var_not_to_event_types: !input not_to_event_types
var_not_from_event_types: !input not_from_event_types
triggers:
- platform: state
entity_id: !input event_entity
conditions:
- condition: template
value_template: >
{% set to_list = var_to_event_types.split(',') if var_to_event_types else [] %}
{% set from_list = var_from_event_types.split(',') if var_from_event_types else [] %}
{% set not_to_list = var_not_to_event_types.split(',') if var_not_to_event_types else [] %}
{% set not_from_list = var_not_from_event_types.split(',') if var_not_from_event_types else [] %}
{{
(to_list | length == 0 or trigger.to_state.attributes.event_type in to_list)
and (trigger.to_state.attributes.event_type not in not_to_list)
and (from_list | length == 0 or trigger.from_state.attributes.event_type in from_list)
and (trigger.from_state.attributes.event_type not in not_from_list)
}}
actions: !input action
mode: single
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment