diff --git a/code/espurna/config/types.h b/code/espurna/config/types.h index fc611740..d9f0f832 100644 --- a/code/espurna/config/types.h +++ b/code/espurna/config/types.h @@ -96,6 +96,10 @@ #define RELAY_PROVIDER_RFBRIDGE 3 #define RELAY_PROVIDER_STM 4 +#define RELAY_GROUP_SYNC_NORMAL 0 +#define RELAY_GROUP_SYNC_INVERSE 1 +#define RELAY_GROUP_SYNC_RECEIVEONLY 2 + //------------------------------------------------------------------------------ // UDP SYSLOG //------------------------------------------------------------------------------ diff --git a/code/espurna/relay.ino b/code/espurna/relay.ino index fa9fe407..0c42c05a 100644 --- a/code/espurna/relay.ino +++ b/code/espurna/relay.ino @@ -630,7 +630,7 @@ void _relayWebSocketSendRelay(unsigned char i) { line["pulse_ms"] = _relays[i].pulse_ms / 1000.0; #if MQTT_SUPPORT line["group"] = getSetting("mqttGroup", i, ""); - line["group_inv"] = getSetting("mqttGroupInv", i, 0).toInt(); + line["group_sync"] = getSetting("mqttGroupSync", i, RELAY_GROUP_SYNC_NORMAL).toInt(); line["on_disc"] = getSetting("relayOnDisc", i, 0).toInt(); #endif @@ -794,6 +794,18 @@ void relaySetupAPI() { #if MQTT_SUPPORT +void _relayMQTTGroup(unsigned char id) { + String topic = getSetting("mqttGroup", id, ""); + if (!topic.length()) return; + + unsigned char mode = getSetting("mqttGroupSync", id, RELAY_GROUP_SYNC_NORMAL).toInt(); + if (mode == RELAY_GROUP_SYNC_RECEIVEONLY) return; + + bool status = relayStatus(id); + if (mode == RELAY_GROUP_SYNC_INVERSE) status = !status; + mqttSendRaw(topic.c_str(), status ? RELAY_MQTT_ON : RELAY_MQTT_OFF); +} + void relayMQTT(unsigned char id) { if (id >= _relays.size()) return; @@ -807,12 +819,7 @@ void relayMQTT(unsigned char id) { // Check group topic if (_relays[id].group_report) { _relays[id].group_report = false; - String t = getSetting("mqttGroup", id, ""); - if (t.length() > 0) { - bool status = relayStatus(id); - if (getSetting("mqttGroupInv", id, 0).toInt() == 1) status = !status; - mqttSendRaw(t.c_str(), status ? RELAY_MQTT_ON : RELAY_MQTT_OFF); - } + _relayMQTTGroup(id); } // Send speed for IFAN02 @@ -939,7 +946,7 @@ void relayMQTTCallback(unsigned int type, const char * topic, const char * paylo if (value == 0xFF) return; if (value < 2) { - if (getSetting("mqttGroupInv", i, 0).toInt() == 1) { + if (getSetting("mqttGroupSync", i, RELAY_GROUP_SYNC_NORMAL).toInt() == RELAY_GROUP_SYNC_INVERSE) { value = 1 - value; } } diff --git a/code/html/custom.js b/code/html/custom.js index 0c79d78a..fe0b4a9d 100644 --- a/code/html/custom.js +++ b/code/html/custom.js @@ -246,7 +246,7 @@ function addValue(data, name, value) { "ssid", "pass", "gw", "mask", "ip", "dns", "schEnabled", "schSwitch","schAction","schType","schHour","schMinute","schWDs","schUTC", "relayBoot", "relayPulse", "relayTime", - "mqttGroup", "mqttGroupInv", "relayOnDisc", + "mqttGroup", "mqttGroupSync", "relayOnDisc", "dczRelayIdx", "dczMagnitude", "tspkRelay", "tspkMagnitude", "ledMode", @@ -951,7 +951,7 @@ function initRelayConfig(data) { $("select[name='relayPulse']", line).val(relay.pulse); $("input[name='relayTime']", line).val(relay.pulse_ms); $("input[name='mqttGroup']", line).val(relay.group); - $("select[name='mqttGroupInv']", line).val(relay.group_inv); + $("select[name='mqttGroupSync']", line).val(relay.group_sync); $("select[name='relayOnDisc']", line).val(relay.on_disc); line.appendTo("#relayConfig"); diff --git a/code/html/index.html b/code/html/index.html index a0555d23..09c0a6de 100644 --- a/code/html/index.html +++ b/code/html/index.html @@ -1631,9 +1631,10 @@