Is it possible to have ESPHome present a Sonoff switch as a light?

I successfully flashed and integrated Sonoff Basic switches to Home Assistant.

In my specific context, the Sonoff Basic lives between the power socket and a lamp (the lamp is electrically always switched on so that the management is done with the Sonoff). It is therefore more a “light” for me than a “switch”.

Specifically, I would like it to present itself to Home Assistant as a light, so that the icon reacts to the state of the switch (= that the bulb is illuminated when on).

Is this possible?

I found a bit in the ESPHome documentation about the “Light Component” but it is not clear at all for me how this integrates with the switch configuration of my Sonoff (or whether it remplaces it, or whether this i ssomething completely different).


As a side note, I currently use a workaround to have switches seen as lights, though a light entry such as

- name: martin bureau gauche
  platform: switch
  entity_id: switch.multiprise_martin_mss425f_switch_2

The main problem here is that this disables the ability to manage the entity via the UI (to add a friendly name) and complicates my YAML configuration (I have to separately customize each entity - which would be fine if the entity was not already integrated, and therefore manageable though the UI)

You can do it in home assistant:

Or ESPHome:

It seem that you can do it. Here: https://esphome.io/components/light/binary.html
you define a binary light in ESPHome. This point to an ID of an output. Here: https://esphome.io/components/output/gpio.html you find the definition.

So I would guess that something like this:

light:
  - platform: binary
    name: "Lamp"
    output: switch_output_of_sonoff
output:
  - platform: gpio
    pin: D1
    id: switch_output_of_sonoff

should work.

Cheers,
Christian

Thank you @CeeCee. I just found the same approach (by poking around, mostly).

It indeed works, I end up with a switch and a light, both can manage the Sonoff (but the state is not propagated between switch and light)

I am not sure yet what the relationship between switch, output and light is - I will open another question for that.

1 Like

If you use an output it won’t show up as an entity like a switch will. The full config for exactly what you wanted is in my second link above.

Yes, I noticed. This said, despite the docs for output stating that

Note that output components are not switches

I still “switch” (toggle) though it (from the light component). I asked with more details about that here: What is in ESPHome the relationship between binary_switch, switch and output?