Easy configuration for an Onvis HS2 Smart Button (5-Button)

This blueprint helps you to configure the Onvis HS2 Smart Button.

You need (obviously) an Onvis HS2 Smart Button and a Thread Border Router to use it. After that you can configure actions for a single press, double press or long press for each of the 5 physical buttons on the switch.

Event based:
Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

Old Version:
Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

This version is only compatible with the HS2. If there are any other smart buttons which uses the same syntax for labelíng the buttons it might also work these buttons.

Recent updates:

04.03.2024: I rewrote the blueprint to use more basic events to increase reliability

26.01.2024: fixed a typo which resulted in button 5 double-press and long-press not responding

blueprint:
  name: Onvis Smartswitch HS2 - event based
  description: Easily setup your Onvis HS2 5-Button Smartswitch
  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:
      description: Action Type for single pressing Button 1
      selector:
        action: {}
    button1_dp:
      name: Action DP Button 1
      default:
      description: Action Type for double pressing Button 1
      selector:
        action: {}
    button1_lp:
      name: Action LP Button 1
      default:
      description: Action Type for long pressing Button 1
      selector:
        action: {}
    button2_sp:
      name: Action SP Button 2
      default:
      description: Action Type for single pressing Button 2
      selector:
        action: {}
    button2_dp:
      name: Action DP Button 2
      default:
      description: Action Type for double pressing Button 2
      selector:
        action: {}
    button2_lp:
      name: Action LP Button 2
      default:
      description: Action Type for long pressing Button 2
      selector:
        action: {}
    button3_sp:
      name: Action SP Button 3
      default:
      description: Action Type for single pressing Button 3
      selector:
        action: {}
    button3_dp:
      name: Action DP Button 3
      default:
      description: Action Type for double pressing Button 3
      selector:
        action: {}
    button3_lp:
      name: Action LP Button 3
      default:
      description: Action Type for long pressing Button 3
      selector:
        action: {}
    button4_sp:
      name: Action SP Button 4
      default:
      description: Action Type for single pressing Button 4
      selector:
        action: {}
    button4_dp:
      name: Action DP Button 4
      default:
      description: Action Type for double pressing Button 4
      selector:
        action: {}
    button4_lp:
      name: Action LP Button 4
      default:
      description: Action Type for long pressing Button 4
      selector:
        action: {}
    button5_sp:
      name: Action SP Button 5
      default:
      description: Action Type for single pressing Button 5
      selector:
        action: {}
    button5_dp:
      name: Action DP Button 5
      default:
      description: Action Type for double pressing Button 5
      selector:
        action: {}
    button5_lp:
      name: Action LP Button 5
      default:
      description: Action Type for long pressing Button 5
      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] }}" #device_entities(!input onvis_smartswitch)[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
        sequence:
          - choose:
              - conditions:
                  - condition: template
                    value_template: '{{ trigger.event.data.new_state.attributes.event_type == ''single_press'' }}'
                sequence: !input button1_sp
              - conditions:
                  - condition: template
                    value_template: '{{ trigger.event.data.new_state.attributes.event_type == ''double_press'' }}'
                sequence: !input button1_dp
              - conditions:
                  - condition: template
                    value_template: '{{ trigger.event.data.new_state.attributes.event_type == ''long_press'' }}'
                sequence: !input button1_lp
      - conditions:
          - condition: trigger
            id: B2
        sequence:
          - choose:
              - conditions:
                  - condition: template
                    value_template: '{{ trigger.event.data.new_state.attributes.event_type == ''single_press'' }}'
                sequence: !input button2_sp
              - conditions:
                  - condition: template
                    value_template: '{{ trigger.event.data.new_state.attributes.event_type == ''double_press'' }}'
                sequence: !input button2_dp
              - conditions:
                  - condition: template
                    value_template: '{{ trigger.event.data.new_state.attributes.event_type == ''long_press'' }}'
                sequence: !input button2_lp
      - conditions:
          - condition: trigger
            id: B3
        sequence:
          - choose:
              - conditions:
                  - condition: template
                    value_template: '{{ trigger.event.data.new_state.attributes.event_type == ''single_press'' }}'
                sequence: !input button3_sp
              - conditions:
                  - condition: template
                    value_template: '{{ trigger.event.data.new_state.attributes.event_type == ''double_press'' }}'
                sequence: !input button3_dp
              - conditions:
                  - condition: template
                    value_template: '{{ trigger.event.data.new_state.attributes.event_type == ''long_press'' }}'
                sequence: !input button3_lp
      - conditions:
          - condition: trigger
            id: B4
        sequence:
          - choose:
              - conditions:
                  - condition: template
                    value_template: '{{ trigger.event.data.new_state.attributes.event_type == ''single_press'' }}'
                sequence: !input button4_sp
              - conditions:
                  - condition: template
                    value_template: '{{ trigger.event.data.new_state.attributes.event_type == ''double_press'' }}'
                sequence: !input button4_dp
              - conditions:
                  - condition: template
                    value_template: '{{ trigger.event.data.new_state.attributes.event_type == ''long_press'' }}'
                sequence: !input button4_lp
      - conditions:
          - condition: trigger
            id: B5
        sequence:
          - choose:
              - conditions:
                  - condition: template
                    value_template: '{{ trigger.event.data.new_state.attributes.event_type == ''single_press'' }}'
                sequence: !input button5_sp
              - conditions:
                  - condition: template
                    value_template: '{{ trigger.event.data.new_state.attributes.event_type == ''double_press'' }}'
                sequence: !input button5_dp
              - conditions:
                  - condition: template
                    value_template: '{{ trigger.event.data.new_state.attributes.event_type == ''long_press'' }}'
                sequence: !input button5_lp
1 Like

Hi @Nemesis , can you share some insights on how you connected the HS2 to your thread network?

I have a google nest hub2 as border router and it works fine with Onvis smart plugs and other thread/matter devices in HA.

But I could only connect the the HS2 button with bluetooth via HomeKit integration and then triggered the “set preferred thread credentials” action in the device.

But since then it disappeared from HA completely…

It healed itself, After one hour the button appeared back in HomeKit. For anyone wondering about the process:

  1. Add bluetooth to HA

  2. Connect the Button over BT via HomeKit integration

  3. In device details under COnfiguration press “Provision Preferred Thread Credentails”

  4. Wait. Button disappears from HomeKit integration but after some time it will be back with Thread Status “Kind”

Hi Smetti,

thanks for your tip. Before i added it to the “home”-app on iphone, waited a bit until it is connected to the thread network, deleted it from the home-app and then added it into home-assistant but your solution works way better! Thanks!

I rewrote the blueprint to use the more basic event-handling in home assistant to improve reliability.

I had problems that the button presses were not recognised by the automation but within home assistant. I hope this helps.

Apologies for my ignorance, I’m relatively new to HA.

But what does this blueprint actually do?

I ended up here because I have an HS2, and I imported it into Apple Home and had it setup and working. But then had an issue (think I hit the max number of devices through one HomeKit bridge). So I redistributed my devices into HomeKit through separate bridges, and now my HS2 appears in Apple Home with only 2 buttons shown :confused: they all show in HA still and respond so I thought I’d add this blueprint to see if it would help me?

Ugh nothing worse than it working again and not knowing why! I see all 15 button combos again now :confused:

Thanks for sharing the blueprints.

When trying this one out myself for my own Onvis HS2, only the middle button worked and that one was recognized as Button 5. Turns out that device_entities returns the entities in different orders. For me, it was:

['sensor.onvis_hs2_battery', 'button.onvis_hs2_identify', 'event.onvis_hs2_stateless_programmable_switch_1', 'event.onvis_hs2_stateless_programmable_switch_2', 'event.onvis_hs2_stateless_programmable_switch_3', 'event.onvis_hs2_stateless_programmable_switch_4', 'event.onvis_hs2_stateless_programmable_switch_5', 'sensor.onvis_hs2_thread_capabilities', 'sensor.onvis_hs2_thread_status']

So I had to make a small adjustments to make sure it really only picked up the 5 events:

trigger:
  - platform: event
    id: B1
    event_type: state_changed
    event_data:
      entity_id: "{{ (device_entities(var_device_id) | select('match','event') | list)[0] }}"
  - platform: event
    id: B2
    event_type: state_changed
    event_data:
      entity_id: "{{ (device_entities(var_device_id) | select('match','event') | list)[1] }}"
  - platform: event
    id: B3
    event_type: state_changed
    event_data:
      entity_id: "{{ (device_entities(var_device_id) | select('match','event') | list)[2] }}"
  - platform: event
    id: B4
    event_type: state_changed
    event_data:
      entity_id: "{{ (device_entities(var_device_id) | select('match','event') | list)[3] }}"
  - platform: event
    id: B5
    event_type: state_changed
    event_data:
      entity_id: "{{ (device_entities(var_device_id) | select('match','event') | list)[4] }}"

With this, it works reliably for me.

1 Like

Same issue, seems your fix works perfectly though!