RPi3 vs. 32 relays

Hi All,
I have read the relevant topics (I hope so), but I could not find the solution.
I need to control 32 relays from the controller. Since it will be an essential part of a heating system, it needs to operate reliably for years. So I would connect 2 of 16 relay modules to the Raspberry Pi 3. The question is how?
I have some SN74HC595N shift registers in the drawer. Can I use them to multiply the output ports? But how can I control them from Home Assistant?
Or should I use am Arduino Meg2560 and communicate with it through serial?
Has anyone some experience with a problem like this?

I wouldn’t connect your relays directly to the pi running home assistant. Run a separate pi or arduino.

Why? because occasionally ha stops working, on an upgrade, or you misconfigure something.

So I would build a pi with the 32 relays (or 2 pis with 16 each) and have them controlled by mqtt.

OK, I understand what you mean.
I make backups from the Pi’s sd card, so it looks quite safe. I would like to have the most reliable solution. If I use an MQTT than I will need some network. It is more component than a direct link to the relays.
But if this is the right solution, I can use this to connect the relays to the network.

Not MQTT but looks simple.

For communication between the RasPi and an Arduino (or 2) It is common to use MQTT and rf24 radios. A setup similar to mine would be HA on RasPi, RasPi has a rf24 radio and a C program that ties the rf24 network to the MQTT system. With that, HA publishes an MQTT command, the MQTT->rf24 program writes it to the rf24 network, the Arduino sees it on the rf24 network and processes it accordingly. The Arduino then sends its status back over rf24, the program on the Pi sees it and publishes it to MQTT where HA then reads it and updates the state. I have an example of the MQTT->rf24 communication program on my github: https://github.com/clintgeek/rf24NetworkInterface.

I eventually moved HA to a linux server and now the conversion between MQTT and rf24 lives on an ESP8266. The code for that is on my github as well. I found that even an old upcycled computer running Ubuntu server had much more power and reliability than the RasPi. It also allows me to run all kinds of other services on the local network.

1 Like

WOW, great project! Congratulations! :smile:
I think your MQTT->rf24 is a very good idea. In an other project I use nRF24 with mysensors network, I like the idea and simplicity very much.
I will have the Pi and the relays installed within half a meter. Based on your solution I have the idea to communicate MQTT over serial to an arduino mega. One mega board would handle 2x16 relays and have enough resoruces to communicate througt MQTT. The only question is if I can find library to use…

That sounds like a great solution since they are physically so close together. I have several projects in my github that read serial input. You could just use a MQTT->serial program on the rasPi much like I did with the MQTT->rf24. I’m not sure how to read/write serial on the Pi, but it’s probably something similar to Serial.read() on the Arduino. Since you wouldn’t be using the rf24 in this solution you aren’t limited by the C drivers/C++ wrapper for the rf24 interface. You could just cobble somthing together in Python as I’m pretty sure it has access to the serial port. I’m sure there is a MQTT client for Python. If not, directions to install the C++ MQTT library on the rasPi are in the readme that I linked above.

1 Like

You can use mysensors for this application as well. Mysensors supports gateways without radio. Make the mega a gateway that creates all needed relays, and leave out all the radio defines in the sketch.

1 Like

Thank you!
I use mysensors since version 1.2 but never had this idea! :smile:
I think this is the solution!

1 Like

I use these ESP8266 based 8CH relay boards with ESPeasy installed. Ive had 4 8 way board installed for well over 12months without a single glitch. so can recommend.

They were available on amazon UK/US but they removed them for copyright of Rpi (didnt make sense to me)
You can buy direct from linksprite

1 Like