Simple lamp with toggle switch

Hi!
I have a simple lamp like the picture below and I want to put a ESP8266 inside to make it connected. I will use a relay to control the 120VAC on the bulb.

I want to keep using the toggle switch but to read its state on a Digital Input, it will have 3.3V on it. Since it’s connected I will be able to toggle the relay from the network but obviously without physically moving the toggle switch to the opposite position… Basically when the toggle value changes, it toggles the bulb state, so there’s no On/Off position on the switch.

Now I am not sure if I can achieve what I want with a basic ESPHome switch component or if I need to implement a custom component with arduino specific code. Also I want to make sure the toggle switch will be functional without Wi-Fi.

The toggle switch will need to be on a different GPIO as the relay so I am wondering how I could use it internally without exposing its state to the network.

This will be my first ESPHome project so I might have very elementary concepts to learn.

I’m sure I can figure out a way to make it work but I don’t want to miss the simpler approach.

Cheers,

1 Like

what about using a sonoff Basic

you can put ESPhome or Tasmota on it

Hi Stephan,
thanks for your suggestion, I already have the hardware. I was unsure how to configure the software part.

I think I got something:

I have a relay on GPIO15, and the toggle switch is connected on GPIO2.

The switch should be internal since the position has no meaning from the network. It acts as a push button, so the only relevant information is the state of the light, or the relay.

switch:
  - platform: gpio
    pin: GPIO15
    name: "Light"
    id: output
binary_sensor:
  - platform: gpio
    pin: GPIO2
    id: toggle_switch
    internal: true
    filters:
     - delayed_on: 10ms
     - delayed_off: 10ms
    on_state:
      switch.toggle: output
1 Like

Nice. You could also configure the light as a light rather than a switch.

1 Like