Hi all,
I’m experiencing a weirdness with a switch template, and I’m looking for some help to spot what is probably obvious to all of you. Short version is, my template switch will turn on my LEDs, but won’t turn them off. Yaml is below.
Long version: I’m trying to control a group of LED strips (yes, this is that stair project). In the end, on the advice of @glmnet, I opted to use some PCA9685 boards, since they give you 16 PWM outputs each at the cost of just 2 i2c pins. Right now I am working with just one board while I prototype the system, but I don’t anticipate any issues scaling this because they’re dead simple to use.
So, what I’ve done is solder up a daughterboard that fits onto the PWM pins of the PCA9685 board. The daughterboard has 16x NTD3055L104T4G mosfets (only using 15 right now) and a 12V power input, which turns into 5 outputs for RGB5050 strips. I chose this mosfet because it was the cheapest I could find that fit my criteria: at least 12V (it can do 60v), at least 2A (it can do 12A), and big enough that I can see it to solder it with my huge fingers. It’s technically an SMD component, but, I’ve had no problems soldering it the old fashioned way.
The board works. I’m able to expose it as 5 RGB lights in Home Assistant through the miracle of ESPHome. They turn on and off like they should, with full brightness control and colour selection. Wonderful!
But, now I need to create the visual effect I want. When deployed, there will be 15 of these strips, and they will be mounted above the risers of each stair on a staircase, concealed behind a cover strip so that you will never see the LEDs, but you will see the reflected light glowing out of each stair.
When a person steps onto the staircase, the lights must illuminate in sequence, creating a “flow” effect in the direction the person is moving. Practically that just means that they all turn on with a 200ms delay from each other. There’ll be some sort of PIR or beam at the top and bottom of the stairs to establish direction, and to detect when a person steps off the staircase.
How I thought to do this was to set up a template switch with a turn_on_action that calls each light switch in sequence, with a 200ms delay. The turn_off_action does the same, just turning off.
But it doesn’t work as expected.
The lights turn on just fine, with very nice “flow” effect. But then they stay on. In Home Assistant, the toggle switch for this template switch just bumps automatically back to the off position. The off_action is never called. The individual manual light switches work, it’s just the switch at the end that’s somehow broken.
Please have a look at my yaml file below. I’m clearly doing something wrong. Can you see what it is? This yaml validates and compiles just fine.
Thank you.
esphome:
name: wem001
platform: ESP8266
board: d1_mini
wifi:
ssid: VERY VERY SECRET
password: WHAT COULD IT BE?
# Enable logging
logger:
# Enable Home Assistant API
api:
ota:
i2c:
sda: D2
scl: D1
scan: True
light:
- platform: rgb
name: "Light - strip test 01"
id: rgb1
blue: pca_1
red: pca_2
green: pca_3
- platform: rgb
name: "Light - strip test 02"
id: rgb2
blue: pca_4
red: pca_5
green: pca_6
- platform: rgb
name: "Light - strip test 03"
id: rgb3
blue: pca_7
red: pca_8
green: pca_9
- platform: rgb
name: "Light - strip test 04"
id: rgb4
blue: pca_10
red: pca_11
green: pca_12
- platform: rgb
name: "Light - strip test 05"
id: rgb5
blue: pca_13
red: pca_14
green: pca_15
pca9685:
- frequency: 500
address: 0x40
# Individual outputs
output:
- platform: pca9685
id: 'pca_1'
channel: 0
- platform: pca9685
id: 'pca_2'
channel: 1
- platform: pca9685
id: 'pca_3'
channel: 2
- platform: pca9685
id: 'pca_4'
channel: 3
- platform: pca9685
id: 'pca_5'
channel: 4
- platform: pca9685
id: 'pca_6'
channel: 5
- platform: pca9685
id: 'pca_7'
channel: 6
- platform: pca9685
id: 'pca_8'
channel: 7
- platform: pca9685
id: 'pca_9'
channel: 8
- platform: pca9685
id: 'pca_10'
channel: 9
- platform: pca9685
id: 'pca_11'
channel: 10
- platform: pca9685
id: 'pca_12'
channel: 11
- platform: pca9685
id: 'pca_13'
channel: 12
- platform: pca9685
id: 'pca_14'
channel: 13
- platform: pca9685
id: 'pca_15'
channel: 14
switch:
- platform: template
name: "Light - Stairs Up"
turn_on_action:
then:
- light.turn_on: rgb1
- delay: 200ms
- light.turn_on: rgb2
- delay: 200ms
- light.turn_on: rgb3
- delay: 200ms
- light.turn_on: rgb4
- delay: 200ms
- light.turn_on: rgb5
turn_off_action:
then:
- light.turn_off: rgb1
- delay: 200ms
- light.turn_off: rgb2
- delay: 200ms
- light.turn_off: rgb3
- delay: 200ms
- light.turn_off: rgb4
- delay: 200ms
- light.turn_off: rgb5