mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-27 04:36:31 +00:00
Allow Domoticz unsubsctibe using command `DzIdx0 0
` (#21019)
This commit is contained in:
parent
781491efca
commit
1ebdbfd6a4
@ -113,6 +113,14 @@ uint32_t DomoticzRelayIdx(uint32_t relay) {
|
|||||||
return (relay < MAX_DOMOTICZ_IDX) ? Settings->domoticz_relay_idx[relay] : Domoticz->relay_idx[relay -MAX_DOMOTICZ_IDX];
|
return (relay < MAX_DOMOTICZ_IDX) ? Settings->domoticz_relay_idx[relay] : Domoticz->relay_idx[relay -MAX_DOMOTICZ_IDX];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DomoticzSetRelayIdx(uint32_t relay, uint32_t idx) {
|
||||||
|
if (relay < MAX_DOMOTICZ_IDX) {
|
||||||
|
Settings->domoticz_relay_idx[relay] = idx;
|
||||||
|
} else {
|
||||||
|
Domoticz->relay_idx[relay -MAX_DOMOTICZ_IDX] = idx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef USE_SONOFF_IFAN
|
#ifdef USE_SONOFF_IFAN
|
||||||
void MqttPublishDomoticzFanState(void) {
|
void MqttPublishDomoticzFanState(void) {
|
||||||
if (Settings->flag.mqtt_enabled && DomoticzRelayIdx(1)) { // SetOption3 - Enable MQTT
|
if (Settings->flag.mqtt_enabled && DomoticzRelayIdx(1)) { // SetOption3 - Enable MQTT
|
||||||
@ -220,14 +228,13 @@ void DomoticzMqttSubscribe(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t DomoticzIdx2Relay(uint32_t idx) {
|
int DomoticzIdx2Relay(uint32_t idx) {
|
||||||
if (0 == idx) {
|
if (idx > 0) {
|
||||||
return -1; // Idx not mine
|
uint32_t maxdev = (TasmotaGlobal.devices_present > MAX_RELAYS_SET) ? MAX_RELAYS_SET : TasmotaGlobal.devices_present;
|
||||||
}
|
for (uint32_t i = 0; i < maxdev; i++) {
|
||||||
uint32_t maxdev = (TasmotaGlobal.devices_present > MAX_RELAYS_SET) ? MAX_RELAYS_SET : TasmotaGlobal.devices_present;
|
if (idx == DomoticzRelayIdx(i)) {
|
||||||
for (uint32_t i = 0; i < maxdev; i++) {
|
return i;
|
||||||
if (idx == DomoticzRelayIdx(i)) {
|
}
|
||||||
return i;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return -1; // Idx not mine
|
return -1; // Idx not mine
|
||||||
@ -242,6 +249,11 @@ bool DomoticzMqttData(void) {
|
|||||||
*/
|
*/
|
||||||
Domoticz->update_flag = true;
|
Domoticz->update_flag = true;
|
||||||
|
|
||||||
|
if (!Domoticz->subscribe) {
|
||||||
|
return false; // No Domoticz driver subscription so try user subscribes
|
||||||
|
}
|
||||||
|
|
||||||
|
// Default subscibed to domoticz/out/#
|
||||||
if (strncasecmp_P(XdrvMailbox.topic, PSTR(DOMOTICZ_OUT_TOPIC), strlen(DOMOTICZ_OUT_TOPIC)) != 0) {
|
if (strncasecmp_P(XdrvMailbox.topic, PSTR(DOMOTICZ_OUT_TOPIC), strlen(DOMOTICZ_OUT_TOPIC)) != 0) {
|
||||||
return false; // Process unchanged data
|
return false; // Process unchanged data
|
||||||
}
|
}
|
||||||
@ -520,14 +532,17 @@ void DomoticzInit(void) {
|
|||||||
\*********************************************************************************************/
|
\*********************************************************************************************/
|
||||||
|
|
||||||
void CmndDomoticzIdx(void) {
|
void CmndDomoticzIdx(void) {
|
||||||
|
// DzIdx0 0 - Reset all disabling subscription too
|
||||||
// DzIdx1 403 - Relate relay1 (=Power1) to Domoticz Idx 403 persistent
|
// DzIdx1 403 - Relate relay1 (=Power1) to Domoticz Idx 403 persistent
|
||||||
// DzIdx5 403 - Relate relay5 (=Power5) to Domoticz Idx 403 non-persistent (need a rule at boot to become persistent)
|
// DzIdx5 403 - Relate relay5 (=Power5) to Domoticz Idx 403 non-persistent (need a rule at boot to become persistent)
|
||||||
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= MAX_RELAYS_SET)) {
|
if ((XdrvMailbox.index >= 0) && (XdrvMailbox.index <= MAX_RELAYS_SET)) {
|
||||||
if (XdrvMailbox.payload >= 0) {
|
if (XdrvMailbox.payload >= 0) {
|
||||||
if (XdrvMailbox.index <= MAX_DOMOTICZ_IDX) {
|
if (0 == XdrvMailbox.index) {
|
||||||
Settings->domoticz_relay_idx[XdrvMailbox.index -1] = XdrvMailbox.payload;
|
for (uint32_t i = 0; i < MAX_RELAYS_SET; i++) {
|
||||||
|
DomoticzSetRelayIdx(i, 0);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Domoticz->relay_idx[XdrvMailbox.index -MAX_DOMOTICZ_IDX -1] = XdrvMailbox.payload;
|
DomoticzSetRelayIdx(XdrvMailbox.index -1, XdrvMailbox.payload);
|
||||||
}
|
}
|
||||||
DomoticzMqttSubscribe();
|
DomoticzMqttSubscribe();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user