The binary_sensor here uses the new API, but I’m not sure what I need to do in order to have this work with MQTT. I’d like to be able to set this binary_sensor to on/off from within an HA automation.
I can’t find any MQTT examples for either. Much appreciated.
With the ESPHome API you can link the binary_sensor to a HA input boolean, so you can set it from HA, as well as have an automation trigger when it changes in the device.
I want to be able to do them same thing with MQTT, that is set the binary_sensor in the ESPHome device to on/off and respond to on/off state changes in HA.
ETA: My original code “works”, however it is too slow upon startup. Otto said using MQTT would be faster.
I’m not sure I can help since I still consider myself a novice with Home Assistant. Before going further, what do you understand about the mqtt protocol? In my home, I have some sensors that publish an mqtt message that home assistant can respond to:
In this direction you need to know the command and state topics the device is listening for and what the format of the data that the device works from.
If I am completely misunderstanding your question, then I’ll stop trying to help here.