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

I something simular with an electric car charger, where different relay combinations changes the charging current. There I use one scene for every mode, and I turn on the scenes from an automation.
If the fan can be destroyd if the releay combination is wrong, I would do it in the arduino, since you can turn on that relay from frontend. If you need to do it from arduino let me know

Here is how I’ve set up my scenes

- name: ev1_off
  entities:
    switch.ev1_r1:
      state: on
    switch.ev1_r2:
      state: on
    switch.ev1_r3:
      state: on
    switch.ev1_r4:
      state: on
- name: ev1_10
  entities:
    switch.ev1_r1:
      state: on
    switch.ev1_r2:
      state: on
    switch.ev1_r3:
      state: off
    switch.ev1_r4:
      state: on
- name: ev1_16
  entities:
    switch.ev1_r1:
      state: off
    switch.ev1_r2:
      state: on
    switch.ev1_r3:
      state: off
    switch.ev1_r4:
      state: on
- name: ev1_20
  entities:
    switch.ev1_r1:
      state: on
    switch.ev1_r2:
      state: off
    switch.ev1_r3:
      state: off
    switch.ev1_r4:
      state: on
1 Like

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