Combining the 3 modes of the sonoff zigbee button (SNZB-01) in 1 file

Hi there,

I managed to use my sonoff button so I can control (toggle) 3 items, but I created 3 separate files for that. Is it possible to combine these into 1 file ?
I have my configuration slpit up so my automations are in a separate folder, but I like 1 file to control the button instead of 3.
My files :
hk_schakelaar_zithoek_one.yaml

alias: zithoek schakelaar 1 click
trigger:
  - platform: event
    event_type: zha_event
    event_data:
      command: 'toggle'
      device_ieee: 00:12:4b:00:21:35:ae:22

condition: []
action:
  - data: {}
    entity_id: input_boolean.hk_sfeerverlichting
    service: input_boolean.toggle
mode: single

hk_schakelaar_zithoek_double.yaml :

alias: zithoek schakelaar 2 click
trigger:
  - platform: event
    event_type: zha_event
    event_data:
      command: 'on'
      device_ieee: 00:12:4b:00:21:35:ae:22

condition: []
action:
  - data: {}
    entity_id: switch.sonoff_hk_grootlicht_voor
    service: switch.toggle
mode: single

hk_schakelaar_zithoek_long.yaml :

alias: zithoek schakelaar long press
trigger:
  - platform: event
    event_type: zha_event
    event_data:
      command: 'off'
      device_ieee: 00:12:4b:00:21:35:ae:22

condition: []
action:
  - data: {}
    entity_id: switch.sonoff_hk_grootlicht_achter
    service: switch.toggle
mode: single

Thanks for the help in advance!

Well these are all automations, so you can just put them in one file. Check out

on the nifty details.

@Plaatjesdraaier

Use the “Choose” action with trigger templates as conditions…

trigger:
- platform: event
  event_type: zha_event
  event_data:
    device_ieee: 00:12:4b:00:21:35:ae:22
action:
- choose:
  - conditions:
    - '{{ trigger.event.data.command == "toggle" }}'
    sequence: 
      - service: input_boolean.toggle
        entity_id: input_boolean.hk_sfeerverlichting
  - conditions:
    - '{{ trigger.event.data.command == "on" }}'
    sequence:
      - service: switch.toggle
        entity_id: switch.sonoff_hk_grootlicht_voor
  - conditions:
    - '{{ trigger.event.data.command == "off" }}'
    sequence:
      - service: switch.toggle
        entity_id: switch.sonoff_hk_grootlicht_achter
mode: single

There is also a blueprint that does this: ZHA - Sonoff Zigbee Switch

2 Likes

Thank you! That was exacly what I was looking for. (I try to avoid blueprints)