Shelly Detached Switch

I moved 61 Shelly 1’s and 2.5’s to ESPHome, and did it all over the air… Here is how:

1 Like

Don’t suppose anyone uses node red to turn on and off their detached switch? If so, care to explain how you achived this?

I might (stress the might part) be able to help you. By detached do you mean not connected to the device you want to control or do you mean you want to control the shelly switch from another switch?

Sorry I read the thread. I do this with some sonoff zigbee switches so it would be the same.

Here is my flow if anyone needs it. I use mqtt but the logic would apply for anything. You could also make a virtual switch tie that to the shelly and have that operate the bulbs. I use virtual switches for a lot of automations I want Alexa to trigger.

[{"id":"9d982b8b1088451d","type":"tab","label":"Master Bathroom Lights","disabled":false,"info":""},{"id":"501dbd44d7f0f55c","type":"debug","z":"9d982b8b1088451d","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":570,"y":40,"wires":[]},{"id":"5bd591cf01076c74","type":"inject","z":"9d982b8b1088451d","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"zigbee2mqtt/Master toilet switch","payload":"turn_on","payloadType":"str","x":170,"y":400,"wires":[["a324b443a8acd66c"]]},{"id":"d5c043c6c4242b54","type":"api-call-service","z":"9d982b8b1088451d","name":"powder  room light purple","server":"1f07ad34.678b53","version":3,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.powder_room_light","data":"{\"brightness\":255,\"transition\":\"4\",\"rgb_color\":[119, 82, 189]}","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":590,"y":380,"wires":[[]]},{"id":"def521c3f108fcbb","type":"api-call-service","z":"9d982b8b1088451d","name":"master bath ceiling light Orange","server":"1f07ad34.678b53","version":3,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.master_bath_ceiling_light","data":"{\"brightness\":255,\"transition\":\"4\",\"rgb_color\":[255,117,5]}","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":610,"y":260,"wires":[[]]},{"id":"efdb572997220a90","type":"mqtt out","z":"9d982b8b1088451d","name":"","topic":"zigbee2mqtt/Master toilet bulb 1/set","qos":"0","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"84f5ff262b0ec2db","x":900,"y":120,"wires":[]},{"id":"4fb3130acb79fc6f","type":"mqtt in","z":"9d982b8b1088451d","name":"","topic":"zigbee2mqtt/Master toilet switch","qos":"2","datatype":"auto","broker":"84f5ff262b0ec2db","nl":false,"rap":true,"rh":0,"inputs":0,"x":150,"y":120,"wires":[["4308673c31cc3a61"]]},{"id":"ab8a7f7d2f1dbb54","type":"change","z":"9d982b8b1088451d","name":"payload.state","rules":[{"t":"delete","p":"payload.linkquality","pt":"msg"},{"t":"move","p":"payload.state","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":410,"y":120,"wires":[["2ec672f0b7531cbe"]]},{"id":"4308673c31cc3a61","type":"json","z":"9d982b8b1088451d","name":"","property":"payload","action":"","pretty":false,"x":310,"y":80,"wires":[["ab8a7f7d2f1dbb54"]]},{"id":"2ec672f0b7531cbe","type":"change","z":"9d982b8b1088451d","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"ON","fromt":"str","to":"{\"state\":\"ON\",\"brightness\":254,\"xy_color\":{\"x\":0.624,\"y\":0.363}}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":620,"y":120,"wires":[["efdb572997220a90","501dbd44d7f0f55c"]]},{"id":"a324b443a8acd66c","type":"api-call-service","z":"9d982b8b1088451d","name":"master bath shower Light","server":"1f07ad34.678b53","version":3,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.master_bath_shower_light","data":"{\"brightness\":255,\"transition\":\"4\",\"rgb_color\":[0,0,255]}","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":590,"y":320,"wires":[[]]},{"id":"a6ce1afc29c9285a","type":"debug","z":"9d982b8b1088451d","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":750,"y":540,"wires":[]},{"id":"ad573dac691bca16","type":"mqtt out","z":"9d982b8b1088451d","name":"","topic":"zigbee2mqtt/Master Ceiling light/set","qos":"0","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"84f5ff262b0ec2db","x":895,"y":646,"wires":[]},{"id":"b43d6559158a9d85","type":"mqtt in","z":"9d982b8b1088451d","name":"","topic":"zigbee2mqtt/Master Bath Ceiling Light switch","qos":"2","datatype":"auto","broker":"84f5ff262b0ec2db","nl":false,"rap":true,"rh":0,"inputs":0,"x":175,"y":646,"wires":[["a1364c809560b053"]]},{"id":"6a46414d815ea753","type":"change","z":"9d982b8b1088451d","name":"payload.state","rules":[{"t":"delete","p":"payload.linkquality","pt":"msg"},{"t":"move","p":"payload.state","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":570,"y":700,"wires":[["90c77bc97bc74c85"]]},{"id":"a1364c809560b053","type":"json","z":"9d982b8b1088451d","name":"","property":"payload","action":"","pretty":false,"x":410,"y":700,"wires":[["6a46414d815ea753"]]},{"id":"90c77bc97bc74c85","type":"change","z":"9d982b8b1088451d","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"ON","fromt":"str","to":"{\"state\":\"ON\",\"brightness\":254,\"xy_color\":{\"x\":0.624,\"y\":0.363}}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":580,"y":620,"wires":[["ad573dac691bca16","a6ce1afc29c9285a"]]},{"id":"7dd75e7f0f9cf5f6","type":"mqtt out","z":"9d982b8b1088451d","name":"","topic":"zigbee2mqtt/Master Bath shower light bulb/set","qos":"0","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"84f5ff262b0ec2db","x":905,"y":829,"wires":[]},{"id":"23fdbdd5dec74ab5","type":"mqtt in","z":"9d982b8b1088451d","name":"","topic":"zigbee2mqtt/Master Shower Light","qos":"2","datatype":"auto","broker":"84f5ff262b0ec2db","nl":false,"rap":true,"rh":0,"inputs":0,"x":135,"y":829,"wires":[["ef63de97427da165"]]},{"id":"327d3812d3cdf3a2","type":"change","z":"9d982b8b1088451d","name":"payload.state","rules":[{"t":"delete","p":"payload.linkquality","pt":"msg"},{"t":"move","p":"payload.state","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":470,"y":883,"wires":[["7d4aa66468737a7f","5ba22099bfaab449"]]},{"id":"ef63de97427da165","type":"json","z":"9d982b8b1088451d","name":"","property":"payload","action":"","pretty":false,"x":290,"y":883,"wires":[["327d3812d3cdf3a2"]]},{"id":"7d4aa66468737a7f","type":"change","z":"9d982b8b1088451d","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"ON","fromt":"str","to":"{\"state\":\"ON\",\"brightness\":254,\"xy_color\":{\"x\":0.136,\"y\":0.04}}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":505,"y":829,"wires":[["7dd75e7f0f9cf5f6"]]},{"id":"5ba22099bfaab449","type":"link out","z":"9d982b8b1088451d","name":"To Shower Time","links":["ef30ec88de82db53"],"x":755,"y":920,"wires":[]},{"id":"1f07ad34.678b53","type":"server","name":"Home Assistant","version":1,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true},{"id":"84f5ff262b0ec2db","type":"mqtt-broker","name":"","broker":"10.0.0.134","port":"1883","clientid":"","usetls":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"turn_on","birthMsg":{},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"sessionExpiry":""}]

Hi,
I am trying to do same with a Sonoff device since I don’t like the Shelly being on the WiFi. In your experience, are you able to replicate the “detached” mode of action that Shelly uses or is it a bit more involved in your Node-Red flow?
Any advice would be great. I am trying to turn a dumb light toggle switch into a smart one that can also be controlled with a motion detector even when the physical switch is in the off position.
Thank you so much.

It would work fine. Mine are completely detached so there sonoff is kinda a virtual switch. This could be done easily in node red without mqtt. I think my example flow I posted might have been sonoff mini zigbee switches. Wire it up normally exept run constant power to the bulbs. Some one else did a setup that worked manually also but I have not tried it.

If you have trouble I can give you a hand.

Craig

1 Like

Thank you kindly good sir. I may take you up on the help request at a later date. :pray:

Thanks for the reply, for some reason i wasnt notified so its taken me a while to get back around to it and unfortuantly didnt get a chance to try the mqtt route.

Basicly I was using a shelly wall switch to control 6 shelly led ceiling lights. To keep things connected and responsive meant the wall switch had to be deactivated so it didnt stop the power to the lights. I messed around so much trying to figure it out, as the delay between the binarary sensor which keeps the state of the deactivated switch took anywhere from 5 seconds up to 40+ to respond. Though at some point in the past it was instant.

I found this post which instantly sorted it which was a setting inside of the shelly switch.

3 Likes

stumbled across this thread…maybe my issue is on a similar vein

So I’ve got Shelly1 test bench setup to control lights…and controlling a light via Home Assistant/Node red…all good…

Then I added a smart bulb into the mix…detached the switch in button settings and am now able to switch on light via voice, light switch (basically a toggle) and have even got some times of day set to set the brightness of said smart bulb

BUt here is the odd thing…If HASS gets restarted for any reason, this single light is turning on…but I’m not sure why…power hasn’t cycled…which would normally cause a bulb to turn on…so I’m a little lost…so wondering if there is a way to stop this from happening…I know some newer bulbs have ability to set power state after power failure but that isn’t the cause here as power to the shelly and therefore the bulb is never changing

Not sure how you have configured your exact Node Red setup, but I’d guess that when HA reboots, the node registers a state change and calls your toggle or turn_on service or whatever you have in your flow. You may be able to prevent this by going into your events: state node and check the boxes to ignore previous states that are unknown/unavailable/don’t exist. For anyone else who has lights changing state due to automatic polling, make sure to also check the box to ignore state change event when current state equals previous state.

Dragging this one back up from the depths. I have a Shelly Plus 2PM in detached mode. As I understand it, this will result in events being fired for the detached switch, but I require an “entity” to represent the events so I can share it over to my HomeKit setup (where my automations take place). Is it possible to get a detached shelly switch over to Homekit? I do this now with some other Shelly’s using the Mongoose OS, but they don’t have support for the 2PM yet.

Just enable the input detected entity. It’s disabled by default on the shelly device in HA as it wouldn’t typically needed outside of detached mode.

I end up with an occupancy sensor in that case :frowning: works well enough. But I also get a “configurable switch” that has 22 buttons and no idea which one is which

I’ve been trying to come up with a solution for a fail-safe smart switch for Shelly smart bulbs, and I’ve found one way that may work for some. Given that the Shelly has a web interface, I will set up a Shelly or other smart switch to only give input to HA, short the cable that goes to the lamp so that it’s always on, then in the rare case that HA is down, simply use the web interface for the Shelly smart bulb.
Yes, I know, this is not what OP wanted. It’s also not what I wanted. Ideally, I’d like the smart switch to check if HA did actually react, then if it didn’t, physically turn on and off the light. While this is not impossible, I don’t know how to achieve that yet. I guess we’ll need a custom firmware and some kind of confirmation from HA to that firmware that, “yes, I got that info”.
While I’d love that solution, simply using the smart bulb web interface in an emergency would be a good temporary solution. It helps if all your smart bulbs have static IP addresses and you write them down.

I am also struggling to get the detached input working with Node Red and MQTT.
Using mainly (16) Shelly’s 4PM pro, there are a lot of inputs to control but I found the build in integration a bit flacky so trying to make one good working setup to copy many times over.
Looking at the MQTT explorer I can see the /events/rpc/ topic feeding me whole line with data. I assume I will need to ‘filter out’ the input:x actions and use them to toggle the output relais.
There are some template for HA example but since I am just starting with Node Red I would grateful for some Flow examples. I checked the one above from iscraigh ut those are for Zigbee and I cant find a way to convert them for my use.

Example line of the rpc topic:
{"src":"shellypro4pm-ec62608a2910","dst":"shellypro4pm-storage-bedroom-2/events","method":"NotifyEvent","params":{"ts":1679924241.30,"events":[{"component":"input:0", "id":0, "event":"single_push", "ts":1679924241.30}]}}

A note to help others may be: People suggested you can enable and unhide the detached inputs in HA. This is only possible when the switch function is not set to button (took me a while) I use momentary
switches and nothing came up.

I’m not spotting the binary sensor. It’s a Shelly Plus 1.

I’d need to see the full names of all of the sensors, several are being cut short in your screenshot.

The truncated one ends with switch_0_device_temperature

I was advised to use detached mode with the Shelly’s auto_off timer feature, which seems to be working well as a momentary switch triggering garage door controller.

I too can’t find the detached input binary_sensor. This is a Shelly Plus 1. After having detached the input, I deleted the existing integration and created it again to be sure everything would be regenerated. But the integration doesn’t create any binary_sensor for the input. What am I doing wrong?

I’m just using the switch entity.

switch.shellyplus1_garagedoor_switch_0