So, I’m trying to use a PCA9685 board to control a bunch of relays. The actual application is a room with 3 separate light fixtures, and 2 ceiling fans. The relays will control the lights, but also the speed of the fans. 11 Relays total, and that’s not counting the pins I need for presence detection. But I’m hoping to do it all from one Wemos D1, because the PCA9685 provides 16 PWM outputs on an i2c interface, and you can turn them on and off instead of doing PWM.
Now, this works surprisingly well. Here is what my current test yaml looks like:
esphome:
name: wem002
platform: ESP8266
board: d1_mini
wifi:
ssid: ""
password: ""
# Enable logging
logger:
# Enable Home Assistant API
api:
ota:
i2c:
sda: D2
scl: D1
scan: True
pca9685:
- frequency: 500
address: 0x40
output:
- platform: pca9685
id: 'pca_1'
channel: 0
inverted: true
- platform: pca9685
id: 'pca_2'
channel: 1
inverted: true
- platform: pca9685
id: 'pca_3'
channel: 2
inverted: true
- platform: pca9685
id: 'pca_4'
channel: 3
inverted: true
switch:
- platform: template
name: "Relay 1"
optimistic: true
turn_on_action:
then:
output.turn_on: pca_1
turn_off_action:
then:
output.turn_off: pca_1
- platform: template
name: "Relay 2"
optimistic: true
turn_on_action:
then:
output.turn_on: pca_2
turn_off_action:
then:
output.turn_off: pca_2
- platform: template
name: "Relay 3"
optimistic: true
turn_on_action:
then:
output.turn_on: pca_3
turn_off_action:
then:
output.turn_off: pca_3
- platform: template
name: "Relay 4"
optimistic: true
turn_on_action:
then:
output.turn_on: pca_4
turn_off_action:
then:
output.turn_off: pca_4
But there’s some weirdness. When power is applied to the PCA9685, all the relays turn on. You can then turn them off, but, they start turned on.
I tried adding an “on boot” statement to the esphome: section to turn all the relays off immediately, and that does work, but, they still click in for a fraction of a second first.
That’s a problem because of how I intend to control the fan speed. I took apart the manual control that comes with the fan, and it works by using capacitors and resistors in series to lower the voltage that arrives at the fan. I can duplicate that circuit on a board, but instead of using a manual switch, I’ll use relays to select which path the power should flow down. If the relay board boots up with all of the relays on, even for just a second, that’s not going to be great for the fan motor. It might foomp.
I toyed with the idea of just running it light that, and connecting my relays on the NC side. With the NO side engaged by default, the channels would only turn on with the relays were “off”. But then it occurred to me that whenever the D1 rebooted, or if it crashed, or whatever, such that the relays all disengaged at once … well that’d be bad too.
Can anyone think of a way to have these outputs not be high by default? I have a feeling that it’s something to do with the output: section but I am a bear of very little brain and large words confuse me.