Skip to content

Instantly share code, notes, and snippets.

@julienma
Last active May 26, 2026 19:51
Show Gist options
  • Select an option

  • Save julienma/f0b91992d2c89ca3852a77dc2ddc34eb to your computer and use it in GitHub Desktop.

Select an option

Save julienma/f0b91992d2c89ca3852a77dc2ddc34eb to your computer and use it in GitHub Desktop.
Home Assistant blueprint for Sonoff MINI-ZB2GS & MINI-ZB2GS-L detached relay mode
blueprint:
name: Sonoff MINI-ZB2GS / MINI-ZB2GS-L detached relay mode
description: >
Use the Zigbee2MQTT device trigger payload (toggle_l1 / toggle_l2).
If relay is OFF: turn relay ON, wait briefly, then turn target ON.
If relay is ON: toggle target.
domain: automation
author: Adapted for MINI-ZB2GS
input:
zb2gs_device:
name: MINI-ZB2GS device
description: SONOFF MINI-ZB2GS / MINI-ZB2GS-L in Zigbee2MQTT
selector:
device:
filter:
- manufacturer: SONOFF
model: Zigbee dual-channel smart switch
- manufacturer: SONOFF
model: MINI-ZB2GS
- manufacturer: SONOFF
model: MINI-ZB2GS-L
multiple: false
switch_l1:
name: Relay switch entity L1
description: Relay entity for channel L1
selector:
entity:
filter:
domain: switch
multiple: false
switch_l2:
name: Relay switch entity L2
description: Relay entity for channel L2
selector:
entity:
filter:
domain: switch
multiple: false
target_l1:
name: Target(s) controlled by L1
selector:
target:
entity:
domain:
- light
- switch
target_l2:
name: Target(s) controlled by L2
selector:
target:
entity:
domain:
- light
- switch
triggers:
- domain: mqtt
device_id: !input zb2gs_device
type: action
subtype: toggle_l1
trigger: device
- domain: mqtt
device_id: !input zb2gs_device
type: action
subtype: toggle_l2
trigger: device
variables:
action: "{{ trigger.payload | default('', true) }}"
relay_l1: !input switch_l1
relay_l2: !input switch_l2
actions:
- choose:
# -------- L1 --------
- conditions:
- condition: template
value_template: "{{ action == 'toggle_l1' }}"
sequence:
- choose:
- conditions:
- condition: template
value_template: "{{ is_state(relay_l1, 'off') }}"
sequence:
- service: switch.turn_on
target:
entity_id: !input switch_l1
- delay: "00:00:00.200"
- service: homeassistant.turn_on
target: !input target_l1
default:
- service: homeassistant.toggle
target: !input target_l1
# -------- L2 --------
- conditions:
- condition: template
value_template: "{{ action == 'toggle_l2' }}"
sequence:
- choose:
- conditions:
- condition: template
value_template: "{{ is_state(relay_l2, 'off') }}"
sequence:
- service: switch.turn_on
target:
entity_id: !input switch_l2
- delay: "00:00:00.200"
- service: homeassistant.turn_on
target: !input target_l2
default:
- service: homeassistant.toggle
target: !input target_l2
mode: single
@panther7

panther7 commented May 26, 2026

Copy link
Copy Markdown

Hi, small update.

Added support for custom actions.

Why? I need some more actions like scenes. :)

blueprint:
  name: Sonoff MINI-ZB2GS / MINI-ZB2GS-L detached relay mode
  description: >
    Use the Zigbee2MQTT device trigger payload (toggle_l1 / toggle_l2).
    If relay is OFF: turn relay ON, wait briefly, then turn target ON.
    If relay is ON: toggle target. Target devices and custom actions are optional.
  domain: automation
  author: Adapted for MINI-ZB2GS

  input:
    zb2gs_device:
      name: MINI-ZB2GS device
      description: SONOFF MINI-ZB2GS / MINI-ZB2GS-L in Zigbee2MQTT
      selector:
        device:
          filter:
            - manufacturer: SONOFF
              model: Zigbee dual-channel smart switch
            - manufacturer: SONOFF
              model: MINI-ZB2GS
            - manufacturer: SONOFF
              model: MINI-ZB2GS-L
          multiple: false

    switch_l1:
      name: Relay switch entity L1
      description: Relay entity for channel L1
      selector:
        entity:
          filter:
            domain: switch
          multiple: false

    switch_l2:
      name: Relay switch entity L2
      description: Relay entity for channel L2
      selector:
        entity:
          filter:
            domain: switch
          multiple: false

    target_l1:
      name: Target(s) controlled by L1
      description: Optional – devices/entities controlled by channel L1
      default: {}
      selector:
        target:
          entity:
            domain:
              - light
              - switch

    target_l2:
      name: Target(s) controlled by L2
      description: Optional – devices/entities controlled by channel L2
      default: {}
      selector:
        target:
          entity:
            domain:
              - light
              - switch

    action_l1:
      name: Action on L1 toggle (optional)
      description: Actions executed on every L1 toggle (runs after target entity control)
      default: []
      selector:
        action: {}

    action_l2:
      name: Action on L2 toggle (optional)
      description: Actions executed on every L2 toggle (runs after target entity control)
      default: []
      selector:
        action: {}

triggers:
  - domain: mqtt
    device_id: !input zb2gs_device
    type: action
    subtype: toggle_l1
    trigger: device

  - domain: mqtt
    device_id: !input zb2gs_device
    type: action
    subtype: toggle_l2
    trigger: device

variables:
  action: "{{ trigger.payload | default('', true) }}"
  relay_l1: !input switch_l1
  relay_l2: !input switch_l2
  target_l1_var: !input target_l1
  target_l2_var: !input target_l2

actions:
  - choose:
      # -------- L1 --------
      - conditions:
          - condition: template
            value_template: "{{ action == 'toggle_l1' }}"
        sequence:
          - if:
              - condition: template
                value_template: "{{ target_l1_var | length > 0 }}"
            then:
              - choose:
                  - conditions:
                      - condition: template
                        value_template: "{{ is_state(relay_l1, 'off') }}"
                    sequence:
                      - service: switch.turn_on
                        target:
                          entity_id: !input switch_l1
                      - delay: "00:00:00.200"
                      - service: homeassistant.turn_on
                        target: !input target_l1
                default:
                  - service: homeassistant.toggle
                    target: !input target_l1
          - choose: []
            default: !input action_l1

      # -------- L2 --------
      - conditions:
          - condition: template
            value_template: "{{ action == 'toggle_l2' }}"
        sequence:
          - if:
              - condition: template
                value_template: "{{ target_l2_var | length > 0 }}"
            then:
              - choose:
                  - conditions:
                      - condition: template
                        value_template: "{{ is_state(relay_l2, 'off') }}"
                    sequence:
                      - service: switch.turn_on
                        target:
                          entity_id: !input switch_l2
                      - delay: "00:00:00.200"
                      - service: homeassistant.turn_on
                        target: !input target_l2
                default:
                  - service: homeassistant.toggle
                    target: !input target_l2
          - choose: []
            default: !input action_l2

mode: single

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment