Hi there,
I’m quite new to Home Assistant and home automation stuff.
I’ve installed Home Assistant on Raspberry Pi 3 and connected 8 low-level trigger 5v relays module, similar to this:
I’m able to control relays using HA, but there is one problem.
When I power up my raspberry or restart HA relays are “flickering”.
I couldn’t find anything here, maybe because many users use ESP8266 via MQTT to control relays.
I’m wondering if it is possible to setup initial GPIO pin state, so my 8 relays won’t flicker.
On raspberry forum I found this thread, new firmware for raspberry has new command “gpio” that allows to setup gpios.
Is this possible to setup using hassio? (I’ve setup my Home Assistant using Getting Started page)
thank You for reply. Now I’m even more confused than before
could You advice me which one are “safe” to use? As I wrote before I need 8 pins for 8 relays.
I have active low relays, so pins should be pull up so relays won’t flicker. Am I right on that?
GPIO7, GPIO8 are ok? Problem is that there aren’t many GPIO’s that are pull up.
Any alternatives?
If your relays are active low then yes you want the pull up GPIOs. Of which there are only 7:
GPIO2, 3, 4, 5, 6, 7,8.
So one of your relays may flicker on start up becuase you have to use a pull down GPIO.
You could use logic inverters (not gates, 1 in = 0 out, and vice versa) to drive the relays, in which case you would use the the pull down outputs of which there are many more.
Or just use the logic inverter circuit for the one relay you need to use a pull down GPIO for.
I’ve enable onewiere using this guide: https://www.home-assistant.io/components/onewire/ I SSH to my pi and edited boot\config.txt, I’ll try this with GPIO’s, but I need to be sure I’m using correct ones.
Which one’s can be used?
I already use GPIO4 for onewire sensors, so I have 2,3,5,6,7,8 and I must add two more.
Can I use which GPIOS I want? Are there any pins that I shouldn’t reconfigure?
I’m going to try that out today.
Hopefully I won’t destory my PI (again )
If everything works well I’ll try to add info to documentation, i think this is a really great features and not everyone knows about it.
I have used a RPI with those relay board on a few occasions. Most of the pins are suitable for controlling your relay board. The relays board most likely requires an active low to trigger, but that is easy to set in home assistant config and RPI pins are all Bi directional. And outputs don’t need pull ups or pull downs.
It would be done like this in configuration.yaml:
switch:
- platform: rpi_gpio
invert_logic: true
ports: # Port numbers are the GPIO pin numbers, these pins number are all ok to use BTW
5: Light One
6: Light Two
13: Light Three
19: Light Four
26: Light Five
21: Light Six
20: Light Seven
16: Light Eight
When the RPI restarts the relays will turn on and off once, I couldn’t figure out a simple way to stop it, not in config anyway.
If your relays are chattering/flickering, even if they aren’t, (as they are designed for 5v) I recommend removing the LEDs on the relay board and bridging the gap with solder, as the RPI GPIO pins are 3.3v and the forward voltage of the LEDs is about 1.2v which leaves only barely enough voltage to power the optocoupler, and sometimes it can’t power it which causes chattering or not working at all randomly and as the optocoupler ages it gets worse. Remove the LEDs it will work ok.
And if you power the relays with the same power supply as the RPI make sure you have a 2.5A 5v or bigger. As the 8 x relays will use ~700mA together. It would be better to have a second power supply for the relays this would connect on the 3 pins to the right of the picture, remove jumper and connect a second 5v Supply to the left 2 pins of the three GND and VCC, you will still need VCC and GND from RPI as well at the other 10 pins.
And one important note, as far as I know till recently don’t use GPIO pins on the RPI with HASSIO as input(binary_sensors) it doesn’t work, it’s way to hit and miss, I think it has something to do with interrupts on the GPIO not being set up right, I don’t really know why but I know it’s not reliable.
The best way I have found is using ESPhome on HASSIO, an ESP32 or ESP8266 and an MCP23017 16 port expander and you can connect 16 relays like this one or input and the expander is 5v compatible and very easy to setup, pretty affordable.
Here one I used at I job - works really well
That is exactly what misiu is attempting to fix by adding the new Pi gpio command to the boot config (and using the correct GPIOs). As outlined in my post, most (except for seven of them) are high at boot.
Ok, now you say that it makes sense, what you had posted before. It did make me think about something though. I went and tried it out connected and active low to relay board to a RPI GPIO pin 26 and for some reason it didn’t turn off and on when it rebooted. I had a look around and I found that on boot the GPIOs are all in input mode, some comments based on the datasheet that pins 0-8 up pullup and the rest pull-down, while others disagreed with any pullup or down being applied that they and float of sort I assume, and randomly trigger the relays. Perhaps you could try an external pullup resistor from each output pin to 3.3v maybe from 20 - 50Kohm might stop it happening, if that worked it would be fair straight forward. I might try it tomorrow I would be interested to know the answer.
Indeed they are inputs at boot - you don’t use pull resistors on outputs (unless they are open drain). And I’ve always found the table above accurate for which are pull-up and which are pull-down at boot.
The internal resistors the pi uses are 50K minimum so to get less than 0.8v (V-in low) any value resistor below 16K to GND should do the trick.
There is also an option to modify relay module to be high level trigger. I just found this video: https://www.youtube.com/watch?v=-wiygjMviFo I didn’t tried it, but there is always an option.
The best option is to buy relay modules that have jumper to select between low and high level triggers