Hi,
I have set up an esp32 to mimic the 433Mhz remote for 4 different RC-sockets.
code snippets below show what I did so far. I can toggle ONE socket (number 4, hardcoded in my example) from the HA UI.
Of course I want to switch all 4 of them (with 4 different buttons on the Dashboard) by calling setLigthState(x) with different values for x. in my understanding, the value of x has to be published as different payloads or maybe as different topics when pressing the corresponding button on the dashboard.
what is the correct approach?
use different topics for each socket? or different payloads?
how do I control which topic/payload is published when I press a dashboard button?
use service: mqtt.publish with data: payload ?
something completely different?
This should be a very common problem, but I can’t find a suitable answer. Maybe because I am looking at the wrong places.
Thanks for any help.
##################################################
ESP Code:
// MQTT: ID, server IP, port, username and password
const PROGMEM char* MQTT_CLIENT_ID = "WZRF";
const PROGMEM char* MQTT_SERVER_IP = "homeassistant";
const PROGMEM uint16_t MQTT_SERVER_PORT = 1883;
const PROGMEM char* MQTT_USER = "!!!-user";
const PROGMEM char* MQTT_PASSWORD = "!!!-PW";
// MQTT: topics
const char* MQTT_LIGHT_STATE_TOPIC = "WZRF/status";
const char* MQTT_LIGHT_COMMAND_TOPIC = "WZRF/switch";
// payloads by default (on/off)
const char* LIGHT_ON = "ON";
const char* LIGHT_OFF = "OFF";
... bla bla bla
// handle message topic
if (String(MQTT_LIGHT_COMMAND_TOPIC).equals(p_topic)) {
// test if the payload is equal to "ON" or "OFF"
if (payload.equals(String(LIGHT_ON))) {
if (m_light_state != true) {
m_light_state = true;
setLightState(4); <<<< Switch socket # 4 !!
configuration.yaml:
mqtt:
- switch:
name: "WZRF"
state_topic: WZRF/status
command_topic: WZRF/switch
qos: 1
payload_on: "ON"
payload_off: "OFF"
retain: true
UI card configuration:
show_name: true
show_icon: true
type: button
tap_action:
action: toggle
name: WZRF
hold_action:
action: none
icon: mdi:lightbulb-multiple-outline
entity: switch.wzrf