Arduino RELAY switches over WiFi, controlled via HASS / MQTT, comes with OTA Support

Great. I would need:
Scene Low Speed
switch 3 off
switch 2 off
switch 1 on
Scene Med Speed
switch 3 off
switch 1 off
switch 2 on
Scene fast speed
switch 1 off
switch 2 off
switch 3 on

Switch 4 is independent as it is for the lights.

Thanks olegunnar the scenes are a great idea!

Dear erickjoaquin

Thank you for the work you did on this, itā€™s been very helpful and a really straight forward copy and paste to get my esp8266 devices up and running on HASS.
In an attempt to reduce the wifi in my house and get more things hardwired I have been trying to modify your code to work with the ethernet shield W5100 but have not been very successful. Do you by any chance have any relays connected through ethernet and would you be so kind as to share that code with us?

Guys, you ought to save yourself the custom programming work and try the TASMOTA firmware for wemos D1 (primarily for sonoff but compatible with wemos). It uses MQTT messaging, as well as controls for relays, switches, buttons, sensors.

BTW, if you need to control mains operated device, I assume ceiling fan is, get yourself the sonoff product.

Edit: sorry for fat fingers. typos corrected. :slight_smile:

What about for a diy sprinkler system what would you suggest? The new Sonoff 4ch Pro?

@marksev1 Funny you ask, have a look at this topic that I wrote just yesterday.

1 Like

@erickjoaquin

Thank you for this. I just combined it with the Bruh Multi Sensor code to add a relay board to my multisensor.

+1

can you please share hardware pics and 1 pic focusing on pins?

Hi,
Can anyone help me to add home assistant support (mqtt etc.) in this code so that I could use it in home assistant as well:

here is demo video:

Hi lessmann,

my apologies for the very late response, i was away on break and the mrs will not allow me to touch any keyboard while away on holiday.

I have not tried the direct fix connection so, i could not really share any experience on that. Hopefully someone from the community can chip in on this.

nonetheless, in my opinion, it should be very straight forward (i maybe wrong), all you will need to do:

  • replace the wifi connectivity routine, with a direct dhcp client session to secure an IP address for your ethernet shieldā€¦

Have a look on this for reference:
https://www.arduino.cc/en/Tutorial/DhcpAddressPrinter

  • remove the OTA and WIFI libraries
  • retain the MQTT/pubsub lib and routines
  • also remove any OTA related lines.

Good luck!
Cheers
Erick

@olegunnar: Thanks for the update on erickjoaquinĀ“s project. IĀ“ve used it on an ESP8266 controller and it is working very well.

Unfortuantly when the ESP is powered on it publish a wifi-network you can connect to. You cannot do anything on the network but maybe if you have better IT-skills than me you could ā€œhackā€ into the entire home-network. So my question is how do I disable the ESP to publish a wifi-network?

Use the following experiences as guide:

http://www.esp8266.com/viewtopic.php?p=16816

and

Thanks got it working. I just put WiFi.mode(WIFI_STA); after WiFi.begin(ssid, password);

That discussion has fueled in me the desire to realize a kind of gateway for my systems!
Foreword: For about a week I entered the world of HA and I purchased a Raspberry Pi Zero W which the Chomecast audio driver and, through Broadlink RM Pro, both the air conditioner and the iRobot Roomba as well as have set the temperature detection always through RM Pro.
That being said, I have the motors and light switches of the Nice SPA and are piloted by radio-control knobs, so I would like to realize a kind of spartan gateway using this project by piloting relays directly with the keys of a radio control. Doable?
Sorry for my bad English! : P

Thanks for posting this. Iā€™m just starting out with HA and this setup was perfect for my sonā€™s chameleon enclosure. Is there an easy way to add or include a DHT11 or 22 to the Arduino Sketch? I have tried to merge the sketches but Iā€™m not sure where to add certain parts.

Nice work!

Hi Kevin,

I have not done the merging in the past, but it should be straight forward.

With my Relay sketch post (or best using @olegunnarā€™s code , you can easily identify the block of codes belonging to which purpose (function) (OTA, RELAY, WIFI).

Analyse the sketch used by the project below to add in all the DHT related codes (init, setup, loop) to the Relay sketch. Note that you will not need to replicate the MQTT initialization part as it is already created in the original code above. (e.gā€¦ you will need to introduce the DHT topic as per below approach.)
.

Good luck!
Erick

It should be do-able. there are lots of projects shared by the HA community on how to do bits and pieces of what you would like to achieve. Use the forum search function to look for projects similar to yours. Start with Broadlink RM.

cheers
Erick

The search function has been my best friend on this project. Thanks for the info, it is very helpful. If I get it working I will share it with the group.
Thanks again for the help.

Thanks so much for this. I had a dual relay box set up using Blynk and have struggled with the code to get it to work under HA. I actually gave up : )

This works perfectly and is also very educational too
Cheers

1 Like

Another Thanks.
Donā€™t know if I will add switches to my set up, but is really good to have the option there.

Thanks for all the help

Hi all,

Erick, you did a wonderful job here. I did rewrite/extend it a bit:

  • added DHT11 temp/humidity sensor
  • modified the sketch, so the relays are handled dynamicall based on the input array

Code is here: https://github.com/V1pr/Arduino/blob/master/ESP8266_HASS_MQTT_Relay/ESP8266_HASS_MQTT_Relay.ino

3 Likes