I’m having a weird issue with HA UI. I have added a switch (MQTT type switch) in MQTT but for some reason, the UI does not display a 2 position toggle switch but 2 distinct buttons to turn on or off the switch. The switch is used to control an air conditioner.
Is there a way to tell Home Assistant to use a 2 position toggle switch?
The reason you are seeing two buttons instead of a switch is because you have not defined a state_template for your mqtt switch. So home assistant has no idea what the state of the switch is.
You have two options:
define a state_tempate, this is the best option.
Or if that is not possible:
add optimistic: true to your mqtt switch config. Home Assistant will assume the state of the switch is whatever was last sent from home assistant. The problem with this is that the state in home assistant can get out of sync with the physical switch if the switch can be controlled outside home assistant or if the command to change state does not reach the switch for some reason.