theone
(Dan Kessler)
April 28, 2020, 1:16pm
1
I have a WIFI light switch with:
1 button - physical interface
binary_sensor:
- platform: gpio
id: button
internal: TRUE
pin:
number: GPIO03
inverted: TRUE
mode: INPUT_PULLUP
filters:
- delayed_on: 50ms
on_press:
- light.toggle: light_output
- if:
condition:
light.is_on: light_output
then:
switch.turn_on: red_led
else:
switch.turn_off: red_led
switch:
- platform: gpio
id: red_led
name: "${friendly_name}"
internal: true
pin: GPIO14
restore_mode: ALWAYS_OFF
output:
- platform: gpio
id: relay
pin: GPIO04
light:
- platform: binary
id: light_output
name: "${friendly_name}"
output: relay
restore_mode: ALWAYS_OFF
I setup the Red LED to turn on as long as the light is on.
This works fine if I press the physical button.
The problem is how do I control the Red LED if the light is turned on via HA?
I found no trigger option for light.
tom_l
April 28, 2020, 1:46pm
2
The easiest way would be to remove the LED code altogether and physically connect the LED and it’s series resistor in parallel with the relay coil.
theone
(Dan Kessler)
April 28, 2020, 1:50pm
3
@tom_l this is a bought item (WF-WS01) not a custom build - used tuya convert to get ESPHome on it.
So I do not want to physically modify it.
tom_l
April 28, 2020, 2:25pm
4
Ah I see. In that case, try this:
binary_sensor:
- platform: gpio
id: button
internal: TRUE
pin:
number: GPIO03
inverted: TRUE
mode: INPUT_PULLUP
filters:
- delayed_on: 50ms
on_press:
- light.toggle: light_output
- platform: template
lambda: 'return id(light_output).state;'
on_press:
then:
- switch.turn_on: red_led
on_release:
then:
- switch.turn_off: red_led
Or maybe:
- platform: template
lambda: |-
if ( id(light_output).state == 'on' ) {
return true;
} else {
return false;
}
on_press:
then:
- switch.turn_on: red_led
on_release:
then:
- switch.turn_off: red_led
Harry13
(George Georgas)
April 28, 2020, 2:40pm
5
it basically the same as my smart plugs
that has a physical button with status LED’s
binary_sensor:
- platform: gpio
pin:
number: GPIO13
mode: INPUT_PULLUP
inverted: True
name: "Gorgeous Button"
on_press:
then:
- switch.toggle: s20_relay
internal: true
- platform: status
name: "Gorgeous Status"
output:
# Register the LED as a dimmable output ....
- platform: esp8266_pwm
id: s20_blue_led
pin:
number: GPIO4
inverted: false
- platform: esp8266_pwm
id: s20_red_led
pin:
number: GPIO5
inverted: true
switch:
- platform: gpio
name: "Gorgeous"
pin: GPIO12
id: s20_relay
on_turn_on:
- output.turn_on:
id: s20_red_led
on_turn_off:
- output.turn_off:
id: s20_red_led
light:
# ... and then make a light out of it.
- platform: monochromatic
name: "Power Blue LED"
output: s20_blue_led
internal: true
- platform: monochromatic
name: "Red LED"
output: s20_red_led
internal: true
theone
(Dan Kessler)
April 28, 2020, 3:58pm
6
@tom_l I tried this (on both “output” and “light”) and for both I got compilation errors:
src/main.cpp:582:28: error: 'class esphome::gpio::GPIOBinaryOutput' has no member named 'state'
src/main.cpp:586:35: error: 'class esphome::light::LightState' has no member named 'state'
These objects don’t have a “state” - maybe that is why there is no Trigger option for them…
tom_l
April 28, 2020, 4:00pm
7
Yeah ok. I’ve never tired it. Go with Harry’s idea of using the relay switch state.
theone
(Dan Kessler)
April 28, 2020, 4:03pm
8
I thought of it but my device is a “Light” and that is how I want HA to recognize it automatically.
If I change the output,light pair to a switch I will manually need to define it as a light element in HA - change the icon, etc…
tom_l
April 28, 2020, 4:10pm
9
Change the relay to a switch instead of an output. Change the red LED to a Light.
Have a closer look at Harry’s example.
theone
(Dan Kessler)
April 28, 2020, 4:23pm
10
I understood that but that brings me back to the point the HA sees a “switch” element and not a “light” element.
need to manually define an icon, etc…
In his case it is OK because he has a power outlet device and not a light switch
theone
(Dan Kessler)
April 28, 2020, 4:37pm
12
I know, I wanted to save that extra step.
If ESPHome is defined as a light element then it is not needed.
I will do this for now (no other way) and opened a feature request for light trigger automation.
opened 04:11PM - 28 Apr 20 UTC
closed 07:27PM - 28 Apr 20 UTC
Describe the problem you have/What new integration you would like
I have a light switch (generic tuya WF-WS01) with a button, led,...
tom_l
April 28, 2020, 4:42pm
13
Hang on what about this? (I may not be thinking straight):
binary_sensor:
- platform: gpio
internal: true
pin:
number: GPIO3
mode: INPUT_PULLUP
inverted: True
on_press:
then:
- switch.toggle: relay
switch:
- platform: gpio
id: relay
pin: GPIO04
on_turn_on:
- output.turn_on:
id: s20_red_led
on_turn_off:
- output.turn_off:
id: s20_red_led
output:
- platform: gpio
id: red_led
name: "${friendly_name}"
internal: true
pin: GPIO14
restore_mode: ALWAYS_OFF
light:
- platform: binary
id: light_output
name: "${friendly_name}"
output: relay
restore_mode: ALWAYS_OFF
- platform: monochromatic
name: "Red LED"
output: red_led
internal: true
theone
(Dan Kessler)
April 28, 2020, 4:45pm
14
Cannot define output:relay which is of type switch . needs to be of type output .
tom_l
April 28, 2020, 4:52pm
15
Bugger.
I’m not beat yet. There has to be a way to do this.
There’s no output template platform… so that’s not it.
Does output support on turn_on
?
binary_sensor:
- platform: gpio
pin:
number: GPIO3
mode: INPUT_PULLUP
inverted: True
on_press:
then:
- light.toggle: light_output
internal: true
output:
- platform: gpio
id: relay
pin: GPIO04
on_turn_on:
- output.turn_on:
id: s20_red_led
on_turn_off:
- output.turn_off:
id: s20_red_led
- platform: gpio
id: red_led
name: "${friendly_name}"
internal: true
pin: GPIO14
restore_mode: ALWAYS_OFF
light:
- platform: binary
id: light_output
name: "${friendly_name}"
output: relay
restore_mode: ALWAYS_OFF
theone
(Dan Kessler)
April 28, 2020, 5:07pm
16
No as I wrote before output and light do not have trigger actions - thats exactly my feature request
tom_l
April 28, 2020, 5:24pm
17
No mention of output trigger there.
This forum category is for help not feature requests. Ask here:
Or Otto might have a way to do it instead.
Harry13
(George Georgas)
April 28, 2020, 11:55pm
18
why aren’t you using the
output.turn_on Action in the output component
to then turn on the LED
remove it from being triggerd by the binary sensor
so the LED will only ever be on if the output relay is on
theone
(Dan Kessler)
April 29, 2020, 8:02am
20
The output component does not have a trigger it only has an action.
It seems my request for light trigger has already been asked and has been implemented in the dev release.
Harry13
(George Georgas)
April 29, 2020, 9:32am
21
it is a solution to what you original required.The LED will only be on when ever the light is on. Whether its been triggered by the button or HA. So I don’t understand why it’s not what you want.