ESP8266 MQTT switch with local on/off and feedback Topic is solved

Everything about esp8266 and more.

Moderator: leecollings

Post Reply
SweetPants

ESP8266 MQTT switch with local on/off and feedback

Post by SweetPants »

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
kimot
Posts: 104
Joined: Saturday 25 November 2017 17:18
Target OS: Raspberry Pi / ODroid
Domoticz version: v3.8153
Location: Czech Rep.
Contact:

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

Post by kimot »

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 )
RPi2 Domoticz v 4.10717
10 x Sonoff Basic - ESPeasy
1 x Wemos D1 - ESPeasy
1 x Shelly Plus Plug S
1 x Sonoff S26 - ESPeasy
1 x Shelly 1
1 x MySensors HC-SR04
1 x MySenosrs wifi gateway
1 x RFLink
4x Cam IPC-T240H
SweetPants

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

Post by SweetPants »

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
ronschaeffer
Posts: 12
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 »

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

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

Post by SweetPants »

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
Feedback_Switch.png
Hardware:
Hardware.jpg
ronschaeffer
Posts: 12
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 »

Thanks. Have you been happy with the performance?
SweetPants

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

Post by SweetPants »

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
Derik
Posts: 1601
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

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

Post by Derik »

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

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

Post by SweetPants »

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
ronschaeffer
Posts: 12
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 »

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

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

Post by SweetPants »

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.
Dlanor
Posts: 67
Joined: Sunday 22 March 2015 16:18
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

ESP8266 MQTT switch with local on/off and feedback

Post by Dlanor »

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| Zigbee | SONOFF
SweetPants

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

Post by SweetPants »

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.
User avatar
Antori91
Posts: 136
Joined: Sunday 12 February 2017 17:12
Target OS: NAS (Synology & others)
Domoticz version: 4.10717
Location: France
Contact:

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

Post by Antori91 »

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

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

Post by SweetPants »

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.
srushti
Posts: 7
Joined: Monday 10 August 2020 13:29
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post by srushti »

SweetPants wrote: 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
Feedback_Switch.png
Hardware:
Hardware.jpg
Hello,
I am facing the same issue and I want to update the status of the switch on domoticz when I toggle a wall switch. I am unable to access the Feedback_switch.png and hardware.jpg provided in this quote. Can you please provide me with the same and any additional information will be helpful.
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests