Sonoff SwitchMan M5 3C 3 Gang switch with ESPHome

The configuration I provided does all that. It sends events in all these cases. You just need to set up your automations to listen for the right events. The events are esphome.switch_click, esphome.switch_double_click and esphome.switch_long_press. The data of the event will include which switch it is from and which button was used.

So, for example, you could listen to the esphome.switch_long_press event with data of:

device: switch-1
button: left

And your automation will only happen when the left button of switch-1 is long pressed.

1 Like

Based on Jasper123 great script the events of the long_press, double etc can be placed in a automation. For me it was not clear how to trap these events but I finally understood his comments.

Here is screenshot of how it listen to these events.

Hope that helps somebody else.

I somehow prefer to code actions directly in ESPHOME setup rather than firing events to HA and then reacting over there, i.e.

- timing: #short
          - ON for at most 1s
          - OFF for at least 0.05s
        then:
          - if:
              condition: 
                api.connected:
              then:
                - homeassistant.service:
                    service: light.toggle
                    data:
                      entity_id: light.table_lamp
              else:
              - http_request.post: "http://192.168.10.77/light/table_lamp/toggle"

btw,the condition is to go directly to Esphome device if HA is unavailable (fallback option, HA way reacts way faster)

5 Likes

That is nice!

Would it be possible to change Jaspers script (which is great) to use the single press to switch on a light through HA. But when HA is unreachable (I.e. server is offline, wifi is down) to fallback to the local relay?

Sure just check two posts before yours for the solution :wink:

I attempted asking for help a few times and deleted my posts, each time I thought I had it figured, I later got stuck. Iā€™ll like to implement this condition into Jasperā€™s config because Iā€™m getting an error when I do. Iā€™d like to have a fall back to toggle my zigbee hue light of HA goes down. Thanks.

Thank you for sharing this. I agree it is simpler and works well.

I got XNDZā€™s script implemented into Jaspersā€™s and works great, the only downside is that the red ledā€™s are connected to the relays. The double and long press dims and brightens my hue light, awesome. Thanks guys!

Iā€™ll like to know how to power on the relay by default. When thereā€™s an outage (which we experience here often) the M5 would start up being off at default. Iā€™ll rather put this into ESPhome rather than HA automations. Someone please help me with this, thanks.

Set the restore for relay to always on, like this

switch:
  - platform: gpio
    id: relay_1
    name: "light 1"
    pin: 23
    restore_mode: ALWAYS_ON
1 Like