ebaauw / homebridge-rpi

Homebridge plugin for Raspberry Pi.
Apache License 2.0
308 stars 18 forks source link

Controlling solenoid valves using Relays closing on LOW level #86

Closed ychieux closed 3 years ago

ychieux commented 3 years ago

Dear @ebaauw, thank you for putting together this nice little plugin!

I'd like to use this plugin to control 4 solenoid valves using 4 channel relays in a remote GPIO configuration.

The relays are closing on Low level so I reversed the control of the accessories, it works fine thru HomeKit.

When I reboot the remote PI, all relays open (which is fine for my use case). The problem is that when homebridge-rpi connects for the first time, the GPIO get initialized on LOW level rather than HIGH which leads to all 4 relays to close.

In my use case, that would cause the valves to open until they get cycled open / closed thru Homekit which is not ok (I don't want to have the garden irrigation running by default :-) )

Could it be possible to add an option for the startup state to assign to GPIO output with HIGH level? Having this configurable thru config.json (and settings on UI) would be awesome.

ebaauw commented 3 years ago

What's your config.json? Could you please capture and attach a debug log file (see https://github.com/ebaauw/homebridge-hue/wiki/FAQ#homebridge)?

Are you sure you got reversed right? Normally, low means inactive (off) and high means active (on).

Valves are initialised to inactive (off), because of the duration logic, but that should take into account the reversed setting. What happens if you expose the relays as switches?

On boot, the Pi initialises the GPIO pins as input pins with a pull-up/pull-down resistor, dependent on the pin (see https://www.raspberrypi.org/documentation/hardware/raspberrypi/gpio/README.md and page 102 of https://www.raspberrypi.org/documentation/hardware/raspberrypi/bcm2835/BCM2835-ARM-Peripherals.pdf). To change these, see https://www.raspberrypi.org/documentation/configuration/config-txt/gpio.md.

ebisu commented 3 years ago

Thank you for the detailed instructions above, @ebaauw. I'm also leveraging your wonderful plugin to build an irrigation system and experiencing the same issues as @ychieux.

I changed the default pin initialized settings by editing /boot/config.txt. Now, I have a fail-safe irrigation system. Thanks again!

@ychieux, I added the following to change pin 27 default behavior. gpio=27=op,dh