EDIT: actually I just realised you have no way of controlling the 3 way switch with home assistant (it’s a “dumb” switch). So instead of using an input select (which you could have used to control the switch, if it was smart), use a template sensor in esphome to show the state.
Thanks , yes as a beginner I found it pretty confusing finding the parts I required in the documentation and where to put certain code samples. Hopefully this can be improved in the future so other beginners aren’t discouraged .
I added a filter with a delayed_on: 250ms so when quickly moving the switch from 1 to 3 ESPHome will not set the sensor to 2. And lastly, to retain states across boots I added some on_boot logic. Final result for now:
They’re only required where you have a list of more than one thing or action to do. It does not hurt to include them if you only have one item. In fact it helps if you come back and edit in more later.
I used a cheap ESP32 devboard (I have boards from various brands, including unbranded ones), obviously flashed it with ESPHome using the YAML from my earlier posts. I used an ESP32 because I also use it to read BLE sensors, otherwise I would use an ESP8266 because it has more stable Wi-Fi stack (for me at least, the ESP32 needs to reconnect every 200 minutes, it will then resend the sensor state MQTT message).
Anyways, I connected the 4 wires from the wall switch to the ESP’s GPIO pins that I configured in the YAML file. There is one wire for each state of the switch and a fourth wire that connects to ground. By using INPUT_PULLUP mode no resistors are required, you can directly connect the wires to the GPIO pins.
This way the switch should show up as a sensor in Home Assistant with state 1, 2, or 3, depending on the state of the actual switch.
Hi, I know this is a while ago, but I was attempting to implement a similar solution, and looking at yours, and also the documentation, I’ve tried all manner of things but it just wants bools…
Expected boolean value, but cannot convert to a boolean. Please use ‘true’ or ‘false’.
state (Optional, dict): Widgets or their (sub)parts can have have states, which support separate styling. These state styles inherit from the theme, but can be locally set or overridden within style definitions. Can be one of:
.....
user_1, user_2, user_3, user_4 (Optional, boolean): Custom states.
- button:
checkable: true
state:
checked: true # here you activate the state to be used at boot
checked:
bg_color: 0x00FF00 # here you apply styles to be used when in the respective state
I have 3 relays for selecting open mid and closed on a door
I have two switch/sensors for detecting if gate is fully open or fully closed
I was trying to have a requested_state and a known_state type thing
but I’m not getting states right.