This component allows you to publish a custom payload to a custom topic(s) for an ESPHome switch component.
This makes it easier to integrate with HomeKit which expects a 0
or 1
instead of ON
/OFF
for switches.
Example configuration for publishing a relay's state as 0
or 1
to a custom topic which is compatible with mqtt2homekit
(more info):
esphome:
includes:
- homekit_switch.h
switch:
- platform: gpio
name: "Sonoff Basic Relay"
pin: GPIO12
id: relay
custom_component:
- lambda: |-
auto my_component = new mqtt::HomeKitSwitchComponent(relay);
App.register_component(my_component);
my_component->set_custom_state_topic("HomeKit/sonoffbasic/Switch/On");
my_component->set_custom_command_topic("HomeKit/sonoffbasic/Switch/On");
return {my_component};
Thank you for your post, I found it nearly similar to my case but I am struggling with it. Can you please be so kind to guide me on how to integrate ESPHOME Mqtt with Thingsboard.io.
My requirement:
I have a device running on ESPhome and control gpio via pcf8574, code below. I would like this to be controllable on thingsboard.io via MQTT but I dont know how to integrate gpio switch with mqtt. A lot of tries and errors with no luck. My code as below but thingsboard does not receive any information from the device:
Great thanks to your efforts!
Ngoc
Vietnam