Shelly 2PM Gen4 Zigbee Detatched Switched Mode - Working!

Hey all,

With Shelly’s recent firmware v2 for the Shelly 2PM Gen4, they now fire an event for switch input changes when you have it in ‘detached switch mode’ and joined to Zigbee.

While it’s not an actual status (is that the right word?) that can be polled, this is better than nothing.

I purchased a couple to try out last week after I saw that v2 Firmware was being rolled out. I’m using the ZBT-1 for Zigbee with ZHA. Literally got the Shelly module connected today.

I’ve got a helper virtual device input boolean thing that tries to represent the physical switch state, however there is a chance this can get out of sync if HA misses the events from the 2PM.

Ideally it would be a state that HA can poll from the 2PM, but until that happens, here is my automation that updates the helper virtual device when ever I flick the switch. There might be a smarter/faster way to do this, if there is, I’m always happy to learn. Anyway, I have additional automations that fire when the virtual device is changed by this.

alias: Physical Light Switch - Switch 1
description: ""
triggers:
  - event_type: zha_event
    event_data:
      device_id: number_taken_from_event_listener
      endpoint_id: 3
      cluster_id: 6
      command: attribute_updated
    context: {}
    trigger: event
conditions: null
actions:
  - choose:
      - conditions:
          - condition: template
            value_template: "{{ trigger.event.data.args.value == 1 }}"
        sequence:
          - action: input_boolean.turn_on
            metadata: {}
            target:
              entity_id: input_boolean.room_light_virtual_switch
            data: {}
      - conditions:
          - condition: template
            value_template: "{{ trigger.event.data.args.value == 0 }}"
        sequence:
          - action: input_boolean.turn_off
            metadata: {}
            target:
              entity_id: input_boolean.room_light_virtual_switch
            data: {}
mode: single

When I was watching the events, Cluster ID and Endpoint ID were different for Switch Input 2. But same data.

I can’t comment on the reliability of this thing yet, its only been in for a few hours. But these seem like a good value way to retrofit existing light switches for smart lights that must be always on. This room didn’t have neutral at the switch, so the module itself is in the roof.

One thing I learnt while testing this - make sure you disable the factory reset capability on the switch input before you go flicking it like crazy :sweat_smile:

This is normal for all detached switches & battery powered remotes / scene switches. The switch only monitors its relay & the “switch” entities you saw before putting it in detached mode are essentially the relay’s state.

Now that you’ve enabled detached mode, you’ve decoupled the input so it can only send events. If you turn on a smart bulb from the switch & turn it back off from HA, then your virtual_switch helper will be out of sync and still show as On.

Rather than trying to keep the switch in sync with a helper, why not read the state of the smart bulb directly?

So, the plan is to put in a momentary switch that toggles the state of the wifi bulbs, eliminating the need for the helper.

Basically in this instance it triggers a timer for the second relay via HA, if light helper is on > 1min, turn on relay 2 (which is an exhaust fan) and switch it off 5 mins after switching the light helper off.

Somewhere a Shelly dev said they’re going to look at reporting the input as a separate thing, but for now this light is only controlled by a physical switch, it’s in the toilet, no body wants an app for that lol

BTW, I feel I need to raise this, it is incorrect.

Using Shelly integration over HTTP, the input is a separate device with its true state. It does not rely on events.

I’m also 90% certain there are/were zwave modules that do this.

So the capability is there, just not with Zigbee on these devices yet