Comments (10)
I think the current recommended way to do this is to:
- Set up the LED as a binary light, but don't give it a name (to prevent it from showing up in HASS)
- Set up the relay as a switch, also without a name
- Set up a template switch, configure it to turn the LED and relay on and off together
from esphome.
Yes, as @brandond said: currently that's only possible with a template switch. Kind of like this:
# Pseudocode!
switch:
- platform: gpio
id: led
pin: D4
- platform: gpio
id: relay
pin: D5
- platform: template
name: My Switch
turn_on_action:
- switch.turn_on:
id: led
- switch.turn_on:
id: relay
turn_off_action:
- switch.turn_off:
id: led
- switch.turn_off:
id: relay
As that's IMO pretty easy, I'm not sure I should add native support for it (would just end up cluttering docs). But for the "triggering on a switch", I guess that would be possible, might take a look at that once I get some time.
from esphome.
Yeah, I hoped something like this would work:
binary_sensor:
- platform: gpio
id: button
pin:
number: GPIO0
mode: INPUT_PULLUP
inverted: True
on_press:
then:
- switch.toggle:
id: relay
switch:
- platform: gpio
id: relay
name: "Sonoff3"
pin: GPIO12
turn_on_action:
then:
- light.turn_on:
id: led_light
turn_off_action:
then:
- light.turn_off:
id: led_light
output:
- platform: esp8266_pwm
id: basic_green_led
pin:
number: GPIO13
inverted: True
light:
- platform: monochromatic
id: led_light
output: basic_green_led
The template switch method seems to work though. If implementing the turn_on//-off actions in the (gpio) switch (or switch core?) is possible, then that would be wonderful!
from esphome.
@TheJulianJES Why not something like this?
binary_sensor:
- platform: gpio
id: button
pin:
number: GPIO0
mode: INPUT_PULLUP
inverted: True
on_press:
then:
- switch.toggle:
id: relay
- light.toggle:
id: led_light
from esphome.
Yeah sorry, I should have updated that comment. I already got that solution on discord although I previously tried something that worked but spammed mqtt, even after a slimmed down version (which doesn't work but shouldn't spam mqtt?): https://i.imgur.com/0jE3xCt.png // https://i.imgur.com/0DlpKZH.png (Maybe a bug?) https://hastebin.com/zocicupata.m was another solution I came up with but that might have been a bit overcomplicated. So, then somebody sent an option like yours on Discord (makes sense, but I didn't think of that for some reason).
from esphome.
binary_sensor:
- platform: gpio
id: button
pin:
number: GPIO0
mode: INPUT_PULLUP
inverted: True
on_press:
then:
- switch.toggle:
id: relay
- light.toggle:
id: led_light
Nice but not fault proof as if led_light has been toggled for an other reason light will be then in opposite state ! Would be better and more fault proof to put light in same status as relay ;)
from esphome.
I tried using the led as power_supply option but that does not work for me. Not sure why but could also be an option?
from esphome.
I tried using the led as power_supply option but that does not work for me. Not sure why but could also be an option?
What are you trying to do exactly ?
from esphome.
I'm trying to do the exact same thing as you are :) Making the led reflect the state of the relay.
I tried using the power_supply option, so the board would enable the led as if it were the power supply for the relay. This would also allow it to shut it down after the relay has been disabled.
binary_sensor:
- platform: gpio
pin:
number: GPIO0
mode: INPUT_PULLUP
inverted: True
id: bogus_2
on_press:
then:
- light.toggle:
id: living_lights_front_2
power_supply:
- id: basic_green_led
pin:
number: GPIO13
inverted: True
keep_on_time: 0.5s
output:
- platform: gpio
pin:
number: GPIO12
id: 'generic_out'
power_supply: basic_green_led
light:
- platform: binary
name: "Living room lights front 2"
output: generic_out
id: 'living_lights_front_2'
But for some reason it's not working. Still, this is a workaround and it would be nice if we can make multiple outputs work in sync. Maybe this can be done by setting the correct MQTT payload topic? Not sure if it's available for the light
component.
from esphome.
this should now be possible with the latest automation engine changes.
from esphome.
Related Issues (20)
- Buttons should be published by raising events in Home Assistant HOT 1
- Issue Title HOT 2
- Missing `f` prefix on f-strings HOT 1
- esp8285 reboot due to incorrect API or wireless timeout HOT 6
- ESPhome reboot at various intervals
- Create SECURITY.md HOT 2
- Typo in oversampling 32x HOT 1
- adafruit_qtpy_esp32 neopixel gpio8 HOT 1
- New PMS5003T HOT 2
- I2S Media Player not working for ESP32 S2 based boards
- ESPHOME and NGINX Proxy Manager SSL proxy HA addon don't play nicely HOT 1
- Unable to compile new firmware for BT Proxies HOT 1
- missing ADC2 register on ESP32-S3 HOT 1
- Can be deleted
- AC dimmer - phase delay calculation
- Delete the `packages` directory in the `.platformio` directory and try again. It's probably at `/home/esphome/.platformio`. If that doesn't work, then delete the entire `.platformio` directory. HOT 4
- M5StickC support for Rhasspy or Home assistant voice control HOT 1
- response_size (Required): Number of bytes of the response HOT 1
- Please add missing code for climate
- Error compiling yaml with ssl_fingerprints HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from esphome.