ESP8266 MQTT switch with local on/off and feedback

Everything about esp8266 and more.
Post Reply
SweetPants
Posts: 2255
Joined: Friday 12 July 2013 21:24
Target OS: Linux
Domoticz version: V4.10007
Location: The Netherlands
Contact:

ESP8266 MQTT switch with local on/off and feedback

Post by SweetPants » Monday 11 June 2018 19:53

Project Scope:

When entering my house I want to be able to switch the light in the halway automatically between sunset and sunrise. So when the door opens, switch On the light for say 1-2 minutes and switch Off again using dzVentz. But I also want to be able to switch on/off the light using the existing wall switch(es).

This could be done using an extra (ESP8266 driven) relay in parallel with the original wall switch, but then you are not able to switch off the lights anymore with the wall switch and this is not suitable when having a hotel circuit (2 or more switches in series)

This could be solved by buying (expensive) wall switches which most of the time do not fit into the wall box or are totally different from the original.

Solution:
I've created an ESP8266 enabled switch that can be switched using MQTT, but also takes the switch wire from the wall switch as an input and do local switching if needed. When the wall switch is toggled, the switch also sends an MQTT update to domoticz to update the current switch state. The module is located in or near the lamp, so in case of a hotel circuit, it also works.

First test looks promising
Ubuntu 16.04.3 LTS, Intel NUC, MySensors 2.3.0-alpha, Pro Mini 3.3/8M RFM69(HW), ESP8266 (SDK2.2.0), Sonoff, RFLink, RFXcom, MQTT, NodeRed, Domoticz Beta (from source)

kimot
Posts: 55
Joined: Saturday 25 November 2017 18:18
Target OS: Raspberry Pi
Domoticz version: v3.8153
Location: Czech Rep.
Contact:

Re: ESP8266 MQTT switch with local on/off and feedback

Post by kimot » Tuesday 12 June 2018 23:05

ESPeasy works the same way without need scripts in Domoticz and works if Domoticz is down too.
Domoticz only sends "events" sunset, sunrise, switch slamp ( for remote control ) etc. Other ESPeasy sends door contact state to first (lamp) ESPeasy
This ESPeasy monitors mechanical switch state too, reports lamp state back to Domoticz and control lamp relay ( with timers if needed )

SweetPants
Posts: 2255
Joined: Friday 12 July 2013 21:24
Target OS: Linux
Domoticz version: V4.10007
Location: The Netherlands
Contact:

Re: ESP8266 MQTT switch with local on/off and feedback

Post by SweetPants » Wednesday 13 June 2018 14:50

kimot wrote:
Tuesday 12 June 2018 23:05
ESPeasy works the same way without need scripts in Domoticz and works if Domoticz is down too.
My solution does that too, no need for scripts, and no need to modify wall switches, just sense the presence of a switch signal, but you need some additional hardware to do that. And how about hotel circuits with two or more wall switches?

Edit: Have a second one running now on a 3 switch hotel circuit. Still looking good
Ubuntu 16.04.3 LTS, Intel NUC, MySensors 2.3.0-alpha, Pro Mini 3.3/8M RFM69(HW), ESP8266 (SDK2.2.0), Sonoff, RFLink, RFXcom, MQTT, NodeRed, Domoticz Beta (from source)

ronschaeffer
Posts: 11
Joined: Monday 11 September 2017 17:13
Target OS: Linux
Domoticz version:
Contact:

Re: ESP8266 MQTT switch with local on/off and feedback

Post by ronschaeffer » Friday 17 August 2018 13:41

Sounds really interesting. Please post some details about your hardware set up to detect the wall switch toggle. Thanks!

SweetPants
Posts: 2255
Joined: Friday 12 July 2013 21:24
Target OS: Linux
Domoticz version: V4.10007
Location: The Netherlands
Contact:

Re: ESP8266 MQTT switch with local on/off and feedback

Post by SweetPants » Friday 17 August 2018 14:30

ronschaeffer wrote:
Friday 17 August 2018 13:41
Sounds really interesting. Please post some details about your hardware set up to detect the wall switch toggle. Thanks!
Schematic: (The circled part converts the wall switch signal to something the ESP can handle
The attachment Feedback_Switch.png is no longer available
Hardware:
Feedback_Switch.png
Feedback_Switch.png (42.61 KiB) Viewed 686 times
Attachments
Hardware.jpg
Hardware.jpg (78.14 KiB) Viewed 682 times
Ubuntu 16.04.3 LTS, Intel NUC, MySensors 2.3.0-alpha, Pro Mini 3.3/8M RFM69(HW), ESP8266 (SDK2.2.0), Sonoff, RFLink, RFXcom, MQTT, NodeRed, Domoticz Beta (from source)

ronschaeffer
Posts: 11
Joined: Monday 11 September 2017 17:13
Target OS: Linux
Domoticz version:
Contact:

Re: ESP8266 MQTT switch with local on/off and feedback

Post by ronschaeffer » Monday 20 August 2018 16:43

Thanks. Have you been happy with the performance?

SweetPants
Posts: 2255
Joined: Friday 12 July 2013 21:24
Target OS: Linux
Domoticz version: V4.10007
Location: The Netherlands
Contact:

Re: ESP8266 MQTT switch with local on/off and feedback

Post by SweetPants » Monday 20 August 2018 18:43

ronschaeffer wrote:
Monday 20 August 2018 16:43
Thanks. Have you been happy with the performance?
What performance? It's just a switch and it takes only a few msec to switch either locally or via MQTT
Ubuntu 16.04.3 LTS, Intel NUC, MySensors 2.3.0-alpha, Pro Mini 3.3/8M RFM69(HW), ESP8266 (SDK2.2.0), Sonoff, RFLink, RFXcom, MQTT, NodeRed, Domoticz Beta (from source)

User avatar
Derik
Posts: 2154
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Re: ESP8266 MQTT switch with local on/off and feedback

Post by Derik » Monday 20 August 2018 23:21

SweetPants wrote:
Monday 11 June 2018 19:53
Project Scope:

When entering my house I want to be able to switch the light in the halway automatically between sunset and sunrise. So when the door opens, switch On the light for say 1-2 minutes and switch Off again using dzVentz. But I also want to be able to switch on/off the light using the existing wall switch(es).

This could be done using an extra (ESP8266 driven) relay in parallel with the original wall switch, but then you are not able to switch off the lights anymore with the wall switch and this is not suitable when having a hotel circuit (2 or more switches in series)

This could be solved by buying (expensive) wall switches which most of the time do not fit into the wall box or are totally different from the original.

Solution:
I've created an ESP8266 enabled switch that can be switched using MQTT, but also takes the switch wire from the wall switch as an input and do local switching if needed. When the wall switch is toggled, the switch also sends an MQTT update to domoticz to update the current switch state. The module is located in or near the lamp, so in case of a hotel circuit, it also works.

First test looks promising

Perhaps look at Tasmota..
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups

SweetPants
Posts: 2255
Joined: Friday 12 July 2013 21:24
Target OS: Linux
Domoticz version: V4.10007
Location: The Netherlands
Contact:

Re: ESP8266 MQTT switch with local on/off and feedback

Post by SweetPants » Tuesday 21 August 2018 8:12

Derik wrote:
Monday 20 August 2018 23:21
SweetPants wrote:
Monday 11 June 2018 19:53
Project Scope:

When entering my house I want to be able to switch the light in the halway automatically between sunset and sunrise. So when the door opens, switch On the light for say 1-2 minutes and switch Off again using dzVentz. But I also want to be able to switch on/off the light using the existing wall switch(es).

This could be done using an extra (ESP8266 driven) relay in parallel with the original wall switch, but then you are not able to switch off the lights anymore with the wall switch and this is not suitable when having a hotel circuit (2 or more switches in series)

This could be solved by buying (expensive) wall switches which most of the time do not fit into the wall box or are totally different from the original.

Solution:
I've created an ESP8266 enabled switch that can be switched using MQTT, but also takes the switch wire from the wall switch as an input and do local switching if needed. When the wall switch is toggled, the switch also sends an MQTT update to domoticz to update the current switch state. The module is located in or near the lamp, so in case of a hotel circuit, it also works.

First test looks promising

Perhaps look at Tasmota..
As said, it's already working fine, so no need for Tasmota
Ubuntu 16.04.3 LTS, Intel NUC, MySensors 2.3.0-alpha, Pro Mini 3.3/8M RFM69(HW), ESP8266 (SDK2.2.0), Sonoff, RFLink, RFXcom, MQTT, NodeRed, Domoticz Beta (from source)

ronschaeffer
Posts: 11
Joined: Monday 11 September 2017 17:13
Target OS: Linux
Domoticz version:
Contact:

Re: ESP8266 MQTT switch with local on/off and feedback

Post by ronschaeffer » Wednesday 22 August 2018 14:13

SweetPants wrote:
Monday 20 August 2018 18:43
ronschaeffer wrote:
Monday 20 August 2018 16:43
Thanks. Have you been happy with the performance?
What performance? It's just a switch and it takes only a few msec to switch either locally or via MQTT
Just meant whether it was working reliably

SweetPants
Posts: 2255
Joined: Friday 12 July 2013 21:24
Target OS: Linux
Domoticz version: V4.10007
Location: The Netherlands
Contact:

Re: ESP8266 MQTT switch with local on/off and feedback

Post by SweetPants » Wednesday 22 August 2018 15:47

ronschaeffer wrote:
Wednesday 22 August 2018 14:13
SweetPants wrote:
Monday 20 August 2018 18:43
ronschaeffer wrote:
Monday 20 August 2018 16:43
Thanks. Have you been happy with the performance?
What performance? It's just a switch and it takes only a few msec to switch either locally or via MQTT
Just meant whether it was working reliably
yup, running since jun 11 and never missed a local or MQTT switch up till now. Have 2 running, working on a third, waiting for some components.
Ubuntu 16.04.3 LTS, Intel NUC, MySensors 2.3.0-alpha, Pro Mini 3.3/8M RFM69(HW), ESP8266 (SDK2.2.0), Sonoff, RFLink, RFXcom, MQTT, NodeRed, Domoticz Beta (from source)

Dlanor
Posts: 103
Joined: Sunday 22 March 2015 17:18
Target OS: Raspberry Pi
Domoticz version:
Contact:

ESP8266 MQTT switch with local on/off and feedback

Post by Dlanor » Wednesday 22 August 2018 21:24

SweetPants wrote: yup, running since jun 11 and never missed a local or MQTT switch up till now. Have 2 running, working on a third, waiting for some components.
Can it also be installed behind a light switch? Dutch version ‘inbouwdoos’?

Domoticz | Dashticz V2 | Raspberry Pi | RFXCOM RFXtrx433E USB | RFlink 433Mhz | SONOFF

SweetPants
Posts: 2255
Joined: Friday 12 July 2013 21:24
Target OS: Linux
Domoticz version: V4.10007
Location: The Netherlands
Contact:

Re: ESP8266 MQTT switch with local on/off and feedback

Post by SweetPants » Thursday 23 August 2018 9:08

Dlanor wrote:
Wednesday 22 August 2018 21:24
Can it also be installed behind a light switch? Dutch version ‘inbouwdoos’?
Depends on the depth of the 'inbouwdoos', but I don't think so, never tried. Also be aware that the ESP antenna is a PCB antenna and known not to be very good, so placing it behind the original wall switch could give problems.
Last edited by SweetPants on Saturday 25 August 2018 12:37, edited 1 time in total.
Ubuntu 16.04.3 LTS, Intel NUC, MySensors 2.3.0-alpha, Pro Mini 3.3/8M RFM69(HW), ESP8266 (SDK2.2.0), Sonoff, RFLink, RFXcom, MQTT, NodeRed, Domoticz Beta (from source)

User avatar
Antori91
Posts: 102
Joined: Sunday 12 February 2017 18:12
Target OS: NAS (Synology & others)
Domoticz version: 4.97&3.5
Location: France
Contact:

Re: ESP8266 MQTT switch with local on/off and feedback

Post by Antori91 » Thursday 23 August 2018 10:49

Hello SweetPants,
Could you publish the ESP8266 code you are using for this?
Domoticz High Availability Cluster: Synology Dz V3.5877 (Main) - Raspberry Dz V4.97 (Backup) - Scripts Node.js
Alarm server: Raspberry - motionEye - iot_ALARM-SVR Node.js
Sensors/Actuators: ESP8266-Arduino
https://github.com/Antori91/Home_Automation

SweetPants
Posts: 2255
Joined: Friday 12 July 2013 21:24
Target OS: Linux
Domoticz version: V4.10007
Location: The Netherlands
Contact:

Re: ESP8266 MQTT switch with local on/off and feedback

Post by SweetPants » Thursday 23 August 2018 22:03

Antori91 wrote:
Thursday 23 August 2018 10:49
Hello SweetPants,
Could you publish the ESP8266 code you are using for this?
Send me a PM. Be aware, this is C code using the ESP SDK (2.2.0) directly, so no Arduino IDE or any other platform involved.
Ubuntu 16.04.3 LTS, Intel NUC, MySensors 2.3.0-alpha, Pro Mini 3.3/8M RFM69(HW), ESP8266 (SDK2.2.0), Sonoff, RFLink, RFXcom, MQTT, NodeRed, Domoticz Beta (from source)

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests