Dear folks,
I’ve been using esphome for some while now and really like its large amount of components. I’ve already got a set of simple sensors around the house and some tuya converted lamps and switches running, however for my next project I wanted to step it up a bit.
I’ve created a hallway lamp with 4 dc led bulbs and a pir sensor to activate the lamp when someone is in the hallway. I’ve got an idea about some light effects I want to incorporate where the lights are slowly dimming and brightening at different frequencies while keeping the overall brightness constant. However,first I just want to hang the thing and test the pir sensor settings and general workings and later flash the effects over the air.
So for now, I wanted to create a single monochromatic light exposed to Home assistant, but couple all 4 outputs to the monochromatic light. However, I’m unable to find anything on how to couple multiple outputs.
I’ve also looked around for lambda’s that activate on every loop to copy the value of lamp 1 to 2, 3 and 4 but I’m only able to find time or trigger based solutions. Which currently feel to me like a bit of a hack.
Does anyone else know a good solution? Any insights would be greatly apreciated
As a solution i looked at: QS-WiFi-D01-TRIAC Dimmer
Configured an internal sensor that reads the current (not remote as in the example) value of the output of the light. On change it copies that to the other 3.
Config becomes:
> substitutions:
> devicename: hallway_lamp
> upper_devicename: "Hallway Lamp"
>
> esphome:
> name: $devicename
> platform: ESP32
> board: esp-wrover-kit
>
> wifi:
> ssid:
> password:
>
> # Enable fallback hotspot (captive portal) in case wifi connection fails
> ap:
> ssid: "${upper_devicename} Fallback Hotspot"
> password:
>
> captive_portal:
>
> # Enable logging
> logger:
>
> # Enable Home Assistant API
> api:
>
> ota:
>
> binary_sensor:
> - platform: gpio
> pin: 16
> name: "${upper_devicename} PIR Sensor"
> id: ${devicename}_pir
> device_class: motion
> on_press:
> then:
> - light.turn_on: ${devicename}_light
>
> light:
> - platform: monochromatic
> name: "${upper_devicename} Light"
> output: ${devicename}_out
> id: ${devicename}_light
> output:
> - platform: ledc
> pin: 23
> id: '${devicename}_out'
> inverted: true
> - platform: ledc
> pin: 26
> id: '${devicename}_out1'
> inverted: true
> - platform: ledc
> pin: 18
> id: '${devicename}_out2'
> inverted: true
> - platform: ledc
> pin: 19
> id: '${devicename}_out3'
> inverted: true
>
>
> i2c:
> - id: bus_a
> frequency: 400khz
> sda: 21
> scl: 22
> scan: True
>
> sensor:
> - platform: sht3xd
> id: bedroom_atmosphere
> temperature:
> name: "${upper_devicename} Temperature"
> humidity:
> name: "${upper_devicename} Humidity"
> i2c_id: bus_a
> address: 0x45
> update_interval: 60s
> - platform: template
> name: "${upper_devicename} Brightness Sensor"
> id: sensor_${devicename}_bright
> internal: true
> update_interval: 20ms
> filters:
> delta: 0.005
> lambda: |-
> if (id(${devicename}_light).remote_values.is_on()) {
> return (float(id(${devicename}_light).current_values.get_brightness()));
> }
> else {
> return 0;
> }
> # On Change send new value to other lights
> on_value:
> then:
> - lambda: |-
> id(${devicename}_out1).set_level(float(id(sensor_${devicename}_bright).state));
> id(${devicename}_out2).set_level(float(id(sensor_${devicename}_bright).state));
> id(${devicename}_out3).set_level(float(id(sensor_${devicename}_bright).state));
> - logger.log:
> level: INFO
> format: "Sensor Value Change copied to others %3.1f"
> args: ["id(sensor_${devicename}_bright).state"]
If anyone knows a better solution it would be very welcome
1 Like
Thanks for sharing,
i have been looking for the same solution but than only to control it by my phone for a group at once.
When i copy the code i get certain errors about illigal character use.
Has something maybe changed in the newer versions of Home Assistant ?
Maybe because your substitutions are wrapped in ’ it’s treating it like a string and not liking the special characters like $?
Try removing " and ’ ?
1 Like
thanks for the tip, ill give that a try.
Did try to change the names manually and remove signs but did not try what you described.
Will let the outcome know