Skip to content

Instantly share code, notes, and snippets.

@Porco-Rosso
Last active November 26, 2025 08:11
Show Gist options
  • Select an option

  • Save Porco-Rosso/4cebfc15eb5ec8bfc03181dd2dacb695 to your computer and use it in GitHub Desktop.

Select an option

Save Porco-Rosso/4cebfc15eb5ec8bfc03181dd2dacb695 to your computer and use it in GitHub Desktop.
onvis switch fix HA
blueprint:
name: Onvis Smartswitch HS2 - event based with disconnect filtering
description: Easily setup your Onvis HS2 Switch v8
domain: automation
input:
onvis_smartswitch:
name: Onvis HS2 Switch
description: Select your Onvis HS2 Switch you want to configure actions for.
selector:
device:
filter:
- model: HS2
multiple: false
button1_sp:
name: Action SP Button 1
default: []
selector:
action: {}
button1_dp:
name: Action DP Button 1
default: []
selector:
action: {}
button1_lp:
name: Action LP Button 1
default: []
selector:
action: {}
button2_sp:
name: Action SP Button 2
default: []
selector:
action: {}
button2_dp:
name: Action DP Button 2
default: []
selector:
action: {}
button2_lp:
name: Action LP Button 2
default: []
selector:
action: {}
button3_sp:
name: Action SP Button 3
default: []
selector:
action: {}
button3_dp:
name: Action DP Button 3
default: []
selector:
action: {}
button3_lp:
name: Action LP Button 3
default: []
selector:
action: {}
button4_sp:
name: Action SP Button 4
default: []
selector:
action: {}
button4_dp:
name: Action DP Button 4
default: []
selector:
action: {}
button4_lp:
name: Action LP Button 4
default: []
selector:
action: {}
button5_sp:
name: Action SP Button 5
default: []
selector:
action: {}
button5_dp:
name: Action DP Button 5
default: []
selector:
action: {}
button5_lp:
name: Action LP Button 5
default: []
selector:
action: {}
trigger_variables:
var_device_id: !input onvis_smartswitch
trigger:
- platform: event
id: B1
event_type: state_changed
event_data:
entity_id: "{{ device_entities(var_device_id)[0] }}"
- platform: event
id: B2
event_type: state_changed
event_data:
entity_id: "{{ device_entities(var_device_id)[1] }}"
- platform: event
id: B3
event_type: state_changed
event_data:
entity_id: "{{ device_entities(var_device_id)[2] }}"
- platform: event
id: B4
event_type: state_changed
event_data:
entity_id: "{{ device_entities(var_device_id)[3] }}"
- platform: event
id: B5
event_type: state_changed
event_data:
entity_id: "{{ device_entities(var_device_id)[4] }}"
action:
- choose:
- conditions:
- condition: trigger
id: B1
- condition: template
value_template: >
{{ (trigger.event.data.new_state is not none) and
(trigger.event.data.new_state.state not in ['unknown','unavailable']) and
(trigger.event.data.old_state is not none) and
(trigger.event.data.old_state.state not in ['unknown','unavailable']) and not
(trigger.event.data.old_state.attributes | default({})).get('restored', false) }}
sequence:
- choose:
- conditions:
- condition: template
value_template: >
{{ (trigger.event.data.new_state.attributes.event_type | default('')) == 'single_press' }}
sequence: !input button1_sp
- conditions:
- condition: template
value_template: >
{{ (trigger.event.data.new_state.attributes.event_type | default('')) == 'double_press' }}
sequence: !input button1_dp
- conditions:
- condition: template
value_template: >
{{ (trigger.event.data.new_state.attributes.event_type | default('')) == 'long_press' }}
sequence: !input button1_lp
- conditions:
- condition: trigger
id: B2
- condition: template
value_template: >
{{ (trigger.event.data.new_state is not none) and
(trigger.event.data.new_state.state not in ['unknown','unavailable']) and
(trigger.event.data.old_state is not none) and
(trigger.event.data.old_state.state not in ['unknown','unavailable']) and not
(trigger.event.data.old_state.attributes | default({})).get('restored', false) }}
sequence:
- choose:
- conditions:
- condition: template
value_template: >
{{ (trigger.event.data.new_state.attributes.event_type | default('')) == 'single_press' }}
sequence: !input button2_sp
- conditions:
- condition: template
value_template: >
{{ (trigger.event.data.new_state.attributes.event_type | default('')) == 'double_press' }}
sequence: !input button2_dp
- conditions:
- condition: template
value_template: >
{{ (trigger.event.data.new_state.attributes.event_type | default('')) == 'long_press' }}
sequence: !input button2_lp
- conditions:
- condition: trigger
id: B3
- condition: template
value_template: >
{{ (trigger.event.data.new_state is not none) and
(trigger.event.data.new_state.state not in ['unknown','unavailable']) and
(trigger.event.data.old_state is not none) and
(trigger.event.data.old_state.state not in ['unknown','unavailable']) and not
(trigger.event.data.old_state.attributes | default({})).get('restored', false) }}
sequence:
- choose:
- conditions:
- condition: template
value_template: >
{{ (trigger.event.data.new_state.attributes.event_type | default('')) == 'single_press' }}
sequence: !input button3_sp
- conditions:
- condition: template
value_template: >
{{ (trigger.event.data.new_state.attributes.event_type | default('')) == 'double_press' }}
sequence: !input button3_dp
- conditions:
- condition: template
value_template: >
{{ (trigger.event.data.new_state.attributes.event_type | default('')) == 'long_press' }}
sequence: !input button3_lp
- conditions:
- condition: trigger
id: B4
- condition: template
value_template: >
{{ (trigger.event.data.new_state is not none) and
(trigger.event.data.new_state.state not in ['unknown','unavailable']) and
(trigger.event.data.old_state is not none) and
(trigger.event.data.old_state.state not in ['unknown','unavailable']) and not
(trigger.event.data.old_state.attributes | default({})).get('restored', false) }}
sequence:
- choose:
- conditions:
- condition: template
value_template: >
{{ (trigger.event.data.new_state.attributes.event_type | default('')) == 'single_press' }}
sequence: !input button4_sp
- conditions:
- condition: template
value_template: >
{{ (trigger.event.data.new_state.attributes.event_type | default('')) == 'double_press' }}
sequence: !input button4_dp
- conditions:
- condition: template
value_template: >
{{ (trigger.event.data.new_state.attributes.event_type | default('')) == 'long_press' }}
sequence: !input button4_lp
- conditions:
- condition: trigger
id: B5
- condition: template
value_template: >
{{ (trigger.event.data.new_state is not none) and
(trigger.event.data.new_state.state not in ['unknown','unavailable']) and
(trigger.event.data.old_state is not none) and
(trigger.event.data.old_state.state not in ['unknown','unavailable']) and not
(trigger.event.data.old_state.attributes | default({})).get('restored', false) }}
sequence:
- choose:
- conditions:
- condition: template
value_template: >
{{ (trigger.event.data.new_state.attributes.event_type | default('')) == 'single_press' }}
sequence: !input button5_sp
- conditions:
- condition: template
value_template: >
{{ (trigger.event.data.new_state.attributes.event_type | default('')) == 'double_press' }}
sequence: !input button5_dp
- conditions:
- condition: template
value_template: >
{{ (trigger.event.data.new_state.attributes.event_type | default('')) == 'long_press' }}
sequence: !input button5_lp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment