Acknowledge GPIO change using MQTT
Posted: 11 Sep 2018, 21:46
Hi All,
A common pattern with multiple control apps seems to be, that if you are turning on /of a relay, the node responds with a state message (MQTT)
I am using openhab and I send an MQTT message to turn on/off the pool light:
/pool/GPIO/2 : 1
/pool/GPIO/2 : 0
The switch in openHab turns to the new status. That works fine.
However, if i use Alexa or some other source to publish that MQTT message, the switch does not update. (of course)
What i'd like to do is sending something like:
/pool/light : 1
/pool/light : 0
And the device responding:
/pool/light/state : 1
/pool/light/state : 0
That way, all others will know that the light was in fact turned on (by whoever)
I was able to get this done creating my own firmware like this:
but I'd like to use ESPEasy instead...
Can this be done?
Thank you!
A common pattern with multiple control apps seems to be, that if you are turning on /of a relay, the node responds with a state message (MQTT)
I am using openhab and I send an MQTT message to turn on/off the pool light:
/pool/GPIO/2 : 1
/pool/GPIO/2 : 0
The switch in openHab turns to the new status. That works fine.
However, if i use Alexa or some other source to publish that MQTT message, the switch does not update. (of course)
What i'd like to do is sending something like:
/pool/light : 1
/pool/light : 0
And the device responding:
/pool/light/state : 1
/pool/light/state : 0
That way, all others will know that the light was in fact turned on (by whoever)
I was able to get this done creating my own firmware like this:
Code: Select all
if (!strcmp(topic,"/pool/light")) {
if (!memcmp(payload,"ON",length)) {
state=LOW; action=true; // LOW is LED ON (inverted driver)
}
if (!memcmp(payload,"OFF",length)) {
digitalWrite(LED_BUILTIN, LOW);
state=HIGH; action=true; // HIGH is LED ON (inverted driver)
}
if (action) {
digitalWrite(LED_BUILTIN, state);
client.publish("/pool/light/state",state==LOW ? "ON" : "OFF");
}
}
Can this be done?
Thank you!