How to create a switch disconnected from the relay and stil report the status to HA

So I want to use a smart switch to control some smart lights which means that I don’t actually want to have the relay turn on of off based on the clicking of the switch.

I managed to find a configuration for my switch here:

and I actually managed to get it working by removing the ‘- switch.turn_off: relay’ line from the template platform but I would like to try to simplify the config file so I’m wondering whether there’s an easier way to do what I’m looking for.

Basically, I just need the button press to report the status of the switch (on or off) to home assistant. I guess I need to use the LED on the switch to determine whether it’s on or off or does it make more sense to just toggle the state in HA with each press of the button.

I’m looking at the basic switch integration but it looks like I have to specify the “platform” and I can’t have it be just a toggle reporting it’s state to HA.

I would also love to setup a fall back on the switch whereby it operates as a normal relay toggle if the switch can’t connect to HA (either because it’s offline or because the wifi is down). Is that even possible?

I don’t really understand your problem.

Removing turn_off: relay and turn_of: relay lines should be exactly what you want? You still have the state inside Home Assistant and also the LED on the device will reflect the state.

To only use the relay when home assistant is not connected is easy. There is the api.connected condition that you can add to the condition of switching the relay.

    not:
      api.connected

Well, that’s a good point. Ha ha.

I guess the YAML as it is today seems really complex so maybe my bigger issue is “what the heck is this YAML” doing.

I’m unclear as to why the author is using a lambda and I’m not sure what the lambda is supposed to do. Do I need a template platform if I’m just trying to report the state of the switch and not switch the relay?

I’m super new to ESPHome and it feels like I’m trying to drink from a firehose.

I will admit, it was super easy to get the switch working the way I wanted with ESPHome, when I tired with Tasmota I couldn’t figure out how to detach the switch from the relay and still report the status to HA.