Changed state messages to domoticz

Sat, 10 Jun 2017 13:00:14 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Sat, 10 Jun 2017 13:00:14 +0200
changeset 514
f5a00ad53329
parent 513
a2732027afb3
child 515
7ab5cf2afc0c

Changed state messages to domoticz

thermferm/mqtt.c file | annotate | diff | comparison | revisions
--- a/thermferm/mqtt.c	Wed Jun 07 23:06:47 2017 +0200
+++ b/thermferm/mqtt.c	Sat Jun 10 13:00:14 2017 +0200
@@ -199,6 +199,33 @@
 
 
 
+void pub_domoticz_output(int idx, int value) {
+    char        *dload = NULL;
+    char        sidx[10], sval[10];
+
+    if (idx == 0)
+	return;
+
+    sprintf(sidx, "%d", idx);
+    sprintf(sval, "%d", value);
+
+    dload = xstrcpy((char *)"{\"command\":\"udevice\",\"idx\":");
+    dload = xstrcat(dload, sidx);
+    dload = xstrcat(dload, (char *)",\"nvalue\":");
+    if (value >= 50)
+	dload = xstrcat(dload, (char *)"1");
+    else
+	dload = xstrcat(dload, (char *)"0");
+    dload = xstrcat(dload, (char *)",\"svalue\":\"");
+    dload = xstrcat(dload, sval);
+    dload = xstrcat(dload, (char *)"\"}");
+    publisher(mosq, (char *)"domoticz/in", dload, false);
+    free(dload);
+    dload = NULL;
+}
+
+
+
 char *unit_data(units_list *unit, bool birth)
 {
     char		*payload = NULL;
@@ -253,7 +280,7 @@
 	sprintf(buf, "%d", unit->heater_state);
 	payload = xstrcat(payload, buf);
 	payload = xstrcat(payload, (char *)"}");
-	pub_domoticz_temp(unit->heater_idx, buf);
+	pub_domoticz_output(unit->heater_idx, unit->heater_state);
     } else {
 	payload = xstrcat(payload, (char *)",\"heater\":null");
     }
@@ -265,7 +292,7 @@
 	sprintf(buf, "%d", unit->cooler_state);
 	payload = xstrcat(payload, buf);
 	payload = xstrcat(payload, (char *)"}");
-	pub_domoticz_temp(unit->cooler_idx, buf);
+	pub_domoticz_output(unit->cooler_idx, unit->cooler_state);
     } else {
 	payload = xstrcat(payload, (char *)",\"cooler\":null");
     }
@@ -277,7 +304,7 @@
 	sprintf(buf, "%d", unit->fan_state);
 	payload = xstrcat(payload, buf);
 	payload = xstrcat(payload, (char *)"}");
-	pub_domoticz_temp(unit->fan_idx, buf);
+	pub_domoticz_output(unit->fan_idx, unit->fan_state);
     } else {
 	payload = xstrcat(payload, (char *)",\"fan\":null");
     }
@@ -289,7 +316,7 @@
 	sprintf(buf, "%d", unit->door_state);
 	payload = xstrcat(payload, buf);
 	payload = xstrcat(payload, (char *)"}");
-	pub_domoticz_temp(unit->door_idx, buf);
+	pub_domoticz_output(unit->door_idx, unit->door_state);
     } else {
 	payload = xstrcat(payload, (char *)",\"door\":null");
     }
@@ -301,7 +328,7 @@
 	sprintf(buf, "%d", unit->light_state);
 	payload = xstrcat(payload, buf);
 	payload = xstrcat(payload, (char *)"}");
-	pub_domoticz_temp(unit->light_idx, buf);
+	pub_domoticz_output(unit->light_idx, unit->light_state);
     } else {
 	payload = xstrcat(payload, (char *)",\"light\":null");
     }
@@ -313,7 +340,7 @@
 	sprintf(buf, "%d", unit->psu_state);
 	payload = xstrcat(payload, buf);
 	payload = xstrcat(payload, (char *)"}");
-	pub_domoticz_temp(unit->psu_idx, buf);
+	pub_domoticz_output(unit->psu_idx, unit->psu_state);
     } else {
 	payload = xstrcat(payload, (char *)",\"psu\":null");
     }

mercurial