So, sorry itâs taken so long for someone to provide you an answer. I was actually Googling this and searching the forums and found this, but obviously no one had responded. I eventually figured it out, so here goes:
Using a Shelly in Detached Switch mode within Home Assistant to drive automations:
First, you need to have your Shelly configured and actually in Detached Switch mode. This is the mode where the Input (your wall switch) and the Relay (what actually turns your appliance on/off) are detached. This allows you to do things like provide constant power to an appliance (say because you put Smart Bulbs into the sockets) but want the switch on the wall to actually control the lights (or something totally unrelated like some automated blinds). Check your Shelly docs to configure this (itâs under the switch, settings, button type).
Secondly, this tutorial is going to have to make an assumption that youâre running MQTT on your Shelly (this is what Iâm doing), as it gives you a lot of control over the Shelly itself. If youâre running Shelly for HASS or the built-in integration, youâll have to look elsewhere, sorry.
UPDATE: See my post below if youâre using the native Shelly Integration, as itâs easy then.
Finally, one last assumption is that your Shelly is WORKING in Home Assistant with MQTT already. If itâs not working in MQTT and youâve done your definitions for switches and sensors, then this isnât going to help. Go back and get that working, then come here and itâll make a lot more sense.
On the Shelly, there are two different topics that will be leveraged:
shellies/shellyswitch25-123456/input
shellies/shellyswitch25-123456/relay
The input topic is tied to the state of the wall switch/button (on/off).
The relay topic is tied to the state of the actual appliance (on/off).
So, in my mind, you want to create a SENSOR for the input and a SWITCH for the relay in HA.
You canât physically control the input from HA, you can only report on what it is (sensor), but you CAN control the state of the relay, so it should be a switch.
So, hereâs how you define each of them in HA, in your appropriate .yaml file:
The Switch:
- platform: mqtt
unique_id: shelly_light
name: "Shelly Light"
icon: mdi:lightbulb
state_topic: "shellies/shellyswitch25-123456/relay/1"
command_topic: "shellies/shellyswitch25-123456/relay/1/command"
payload_on: "on"
payload_off: "off"
retain: false
Now the Binary Sensor:
- platform: mqtt
unique_id: shelly_light_switch
name: "Shelly Light Switch"
payload_on: "1"
payload_off: "0"
device_class: "power"
state_topic: "shellies/shellyswitch-123456/input/1"
Now that you have a binary sensor defined, you can trigger automations off of it.
You can find other device_class types here: https://www.home-assistant.io/integrations/binary_sensor/