Using a relay switch as push button to toggle lights

Hi,

(edit: fixed mistranslation of “relay switch”)

another newbie question here, that exceeds my googleing-skill:

I do have an installation where a push button (“taster”) toggles lights. This I wanted to smartify and I added an ESP with a relay switch that I temporarily switch on using a chain of binary_sensor/gpio (physical switch), light/binary (for the state), output/template (for resetting the GPIO/relais) and output/gpio (for actually triggering the physical light)

Here is my boilerplate:

esphome:
  # ...
esp32:
  board: esp32dev
  framework:
    type: esp-idf
# ...
output:
  - platform: template
    id: TemplateOutputLichtDecke
    type: binary
    write_action:
      - output.turn_on: RelaisButtonLichtDecke
      - delay: 500ms
      - output.turn_off: RelaisButtonLichtDecke
  - platform: gpio
    id: RelaisButtonLichtDecke
    pin: GPIO27

 light:
  - platform: binary
    name: "Licht Decke"
    id: LichtDecke
    output: TemplateOutputLichtDecke

binary_sensor:
  - platform: gpio
    id: SchalterLichtDecke
    name: "Schalter Licht Decke"
    pin:
      number: 23
      mode:
        input: true
        pulldown: true
    on_press:
      - light.toggle: LichtDecke

Now to my questions:

  • Does this approach fit into the esphome best practices or am I over-engineering things? Especially for (re-)storing the state.
  • More importantly: on every reboot/reflash of the ESP, the output is being triggered, toggling the light. I do not see anything related in the logs though.

Anything I am missing here?

Cheers,

Snafu

That is not really a very clear statement of what you want to do.

It sound’s like you have an existing something that has a push button or is this something completely new.

Your code/config looks more complicated than it probably needs to be.

Why don’t you start by describing your existing hardware and exactly what behavior you want it to have. A light controlled by a single push button is hard to automate, since it is easy to get out of sync. A human can usually figure out they need to press the button again to turn it on (or off). Automation usually doesn’t really know.

Hi Neel,

thanks for the answer. I agree that “knowing” the state of a bush button controlled light is difficult for automation. And I understand that it can get out of sync. My hope is to have a way to “reset” the state by “restarting” the ESP or by force-set the state. But this can come at a later date and is not relevant for now. :smiley:

Additionally, the setup described below is a minimal setup with all relevant devices. There are more in the setup that are either duplicates or are already handled.

Oh, and I just realized that I assumed the wrong translation. In german we call a “relay switch” a “relais”. And I assumed that this was the English word as well…

To the current setup:

I have a campervan with a light circuit that is triggered by one push button. The push button is going into a black box (electronic block) that probably contains at least one relay keeping the state. I only have access to the cuircut from the push button to the black box.

What I would like to set up (target setup):

The ESP should be the single source of truth and hold the current state. Coming out of sync with the physical world is acceptable.

I want to keep the current push button, but triggering the ESP. The ESP then should temporarily trigger a relay switch that will trigger the “black box”.

I hope this explains more on what I am trying to do.

Cheers,

Snafu

There are several ways of doing what you are looking for. I personally would probably use gpio binary sensor >> template switch >> gpio switch.
In any case you need to apply restore_mode on your setup.

You could post what exact relay / relay module you are using and how it’s wired.

Hey Karosm,

This did the trick sufficiently enough :smile: . I now have restore_mode: ALWAYS_ON on my light component. It will still “toggle” the relay, but now the light will be set to on.
As a reboot normally will happen during day time when the light is “normally off”, this is good enough for me.

I am using an integrated module with 8 relay switches from the very pronounceable company APKLVSR bought through amazon:
APKLVSR ESP 8-Kanal Relais Modul,ESP WiFi Bluetooth BLE Modul mit ESP Entwicklungsboard DC5-30V Stromversorgung Relais für Arduino IDE(LC-Relay-ESP-8R-D5)

Cheers,

Snafu