mirror of
https://github.com/anklimov/lighthub
synced 2025-12-06 19:59:50 +03:00
-default topics prefix used if no "/" in "emit" parameters of output
-Thermostat should be working with DHT22 -Negative PIN# in thermostat item - reverse logic: HIGH level of output should stop heating
This commit is contained in:
@@ -162,8 +162,9 @@ void Input::counterPoll() {
|
||||
aJsonObject *emit = aJson.getObjectItem(inputObj, "emit");
|
||||
if (emit) {
|
||||
char valstr[10];
|
||||
char addrstr[100] = "";
|
||||
strcat(addrstr, emit->valuestring);
|
||||
char addrstr[MQTT_TOPIC_LENGTH];
|
||||
strncpy(addrstr,emit->valuestring,sizeof(addrstr));
|
||||
if (!strchr(addrstr,'/')) setTopic(addrstr,sizeof(addrstr),T_OUT,emit->valuestring);
|
||||
sprintf(valstr, "%d", counterValue);
|
||||
mqttClient.publish(addrstr, valstr);
|
||||
setNextPollTime(millis() + DHT_POLL_DELAY_DEFAULT);
|
||||
@@ -225,9 +226,11 @@ void Input::dht22Poll() {
|
||||
float humidity = dht.readHumidity();
|
||||
#endif
|
||||
aJsonObject *emit = aJson.getObjectItem(inputObj, "emit");
|
||||
aJsonObject *item = aJson.getObjectItem(inputObj, "item");
|
||||
if (item) thermoSetCurTemp(item, temp);
|
||||
debugSerial << F("IN:") << pin << F(" DHT22 type. T=") << temp << F("°C H=") << humidity << F("%");
|
||||
if (emit && temp && humidity && temp == temp && humidity == humidity) {
|
||||
char addrstr[100] = "";
|
||||
char addrstr[MQTT_TOPIC_LENGTH] = "";
|
||||
#ifdef WITH_DOMOTICZ
|
||||
if(getIdxField()){
|
||||
publishDataToDomoticz(DHT_POLL_DELAY_DEFAULT, emit, "{\"idx\":%s,\"svalue\":\"%.1f;%.0f;0\"}", getIdxField(), temp, humidity);
|
||||
@@ -235,7 +238,9 @@ void Input::dht22Poll() {
|
||||
}
|
||||
#endif
|
||||
char valstr[10];
|
||||
strcat(addrstr, emit->valuestring);
|
||||
|
||||
strncpy(addrstr, emit->valuestring, sizeof(addrstr));
|
||||
if (!strchr(addrstr,'/')) setTopic(addrstr,sizeof(addrstr),T_OUT,emit->valuestring);
|
||||
strcat(addrstr, "T");
|
||||
printFloatValueToStr(temp, valstr);
|
||||
mqttClient.publish(addrstr, valstr);
|
||||
@@ -444,13 +449,16 @@ void Input::onContactChanged(int newValue) {
|
||||
: publishDataToDomoticz(0,emit,"{\"command\":\"switchlight\",\"idx\":%s,\"switchcmd\":\"Off\"}",getIdxField());
|
||||
} else
|
||||
#endif
|
||||
char addrstr[MQTT_TOPIC_LENGTH];
|
||||
strncpy(addrstr,emit->valuestring,sizeof(addrstr));
|
||||
if (!strchr(addrstr,'/')) setTopic(addrstr,sizeof(addrstr),T_OUT,emit->valuestring);
|
||||
if (newValue) { //send set command
|
||||
if (!scmd) mqttClient.publish(emit->valuestring, "ON", true);
|
||||
if (!scmd) mqttClient.publish(addrstr, "ON", true);
|
||||
else if (strlen(scmd->valuestring))
|
||||
mqttClient.publish(emit->valuestring, scmd->valuestring, true);
|
||||
mqttClient.publish(addrstr, scmd->valuestring, true);
|
||||
} else { //send reset command
|
||||
if (!rcmd) mqttClient.publish(emit->valuestring, "OFF", true);
|
||||
else if (strlen(rcmd->valuestring))mqttClient.publish(emit->valuestring, rcmd->valuestring, true);
|
||||
if (!rcmd) mqttClient.publish(addrstr, "OFF", true);
|
||||
else if (strlen(rcmd->valuestring))mqttClient.publish(addrstr, rcmd->valuestring, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -485,9 +493,12 @@ void Input::onAnalogChanged(int newValue) {
|
||||
// : publishDataToDomoticz(0,emit,"{\"command\":\"switchlight\",\"idx\":%s,\"switchcmd\":\"Off\"}",getIdxField());
|
||||
// } else
|
||||
//#endif
|
||||
char strVal[16];
|
||||
itoa(newValue,strVal,10);
|
||||
mqttClient.publish(emit->valuestring, strVal, true);
|
||||
char addrstr[MQTT_TOPIC_LENGTH];
|
||||
strncpy(addrstr,emit->valuestring,sizeof(addrstr));
|
||||
if (!strchr(addrstr,'/')) setTopic(addrstr,sizeof(addrstr),T_OUT,emit->valuestring);
|
||||
char strVal[16];
|
||||
itoa(newValue,strVal,10);
|
||||
mqttClient.publish(addrstr, strVal, true);
|
||||
}
|
||||
|
||||
if (item) {
|
||||
|
||||
@@ -287,7 +287,7 @@ if (isSet)
|
||||
Par[0] = map(hsv.h, 0, 255, 0, 365);
|
||||
Par[1] = map(hsv.s, 0, 255, 0, 100);
|
||||
Par[2] = map(hsv.v, 0, 255, 0, 100);
|
||||
return Ctrl(0, 3, Par, send, subItem);
|
||||
return Ctrl(0, 3, Par, send, subItemN);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -296,21 +296,21 @@ if (isSet)
|
||||
|
||||
// if (item.getEnableCMD(500) || lanStatus == 4)
|
||||
return Ctrl(cmd, 0, NULL,
|
||||
send, subItem); //Accept ON command not earlier then 500 ms after set settings (Homekit hack)
|
||||
send, subItemN); //Accept ON command not earlier then 500 ms after set settings (Homekit hack)
|
||||
// else debugSerial<<F("on Skipped"));
|
||||
|
||||
break;
|
||||
default: //some known command
|
||||
return Ctrl(cmd, 0, NULL, send, subItem);
|
||||
return Ctrl(cmd, 0, NULL, send, subItemN);
|
||||
|
||||
} //ctrl
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int Item::Ctrl(short cmd, short n, int *Parameters, boolean send, char * subItem) {
|
||||
int Item::Ctrl(short cmd, short n, int *Parameters, boolean send, int subItemN) {
|
||||
|
||||
debugSerial<<F(" MEM=")<<freeRam()<<F(" Item=")<<itemArr->name<<F(" Sub=")<<subItem<<F(" Cmd=")<<cmd<<F(" Par= ");
|
||||
debugSerial<<F(" MEM=")<<freeRam()<<F(" Item=")<<itemArr->name<<F(" Sub=")<<subItemN<<F(" Cmd=")<<cmd<<F(" Par= ");
|
||||
if (!itemArr) return -1;
|
||||
int Par[MAXCTRLPAR] = {0, 0, 0};
|
||||
if (Parameters)
|
||||
@@ -630,7 +630,7 @@ int Item::Ctrl(short cmd, short n, int *Parameters, boolean send, char * subItem
|
||||
while (i) {
|
||||
Item it(i->valuestring);
|
||||
// it.copyPar(itemVal);
|
||||
it.Ctrl(cmd, n, Par, send); //// was true
|
||||
it.Ctrl(cmd, n, Par, send,subItemN); //// was true
|
||||
i = i->next;
|
||||
} //while
|
||||
} //if
|
||||
|
||||
@@ -116,7 +116,7 @@ class Item
|
||||
Item(char * name);
|
||||
Item(aJsonObject * obj);
|
||||
boolean isValid ();
|
||||
virtual int Ctrl(short cmd, short n=0, int * Parameters=NULL, boolean send=true, char * subItem=NULL);
|
||||
virtual int Ctrl(short cmd, short n=0, int * Parameters=NULL, boolean send=true, int subItem=0);
|
||||
virtual int Ctrl(char * payload, boolean send=true, char * subItem=NULL);
|
||||
|
||||
int getArg(short n=0);
|
||||
|
||||
@@ -1622,15 +1622,15 @@ void thermoLoop(void) {
|
||||
<< F(" cmd:") << thermoStateCommand;
|
||||
pinMode(thermoPin, OUTPUT);
|
||||
if (thermoDisabledOrDisconnected(thermoExtensionArray, thermoStateCommand)) {
|
||||
digitalWrite(thermoPin, LOW);
|
||||
if (thermoPin<0) digitalWrite(-thermoPin, HIGH); digitalWrite(thermoPin, LOW);
|
||||
debugSerial<<F(" OFF");
|
||||
} else {
|
||||
if (curTemp < thermoSetting - THERMO_GIST_CELSIUS) {
|
||||
digitalWrite(thermoPin, HIGH);
|
||||
if (thermoPin<0) digitalWrite(-thermoPin, LOW); digitalWrite(thermoPin, HIGH);
|
||||
debugSerial<<F(" ON");
|
||||
} //too cold
|
||||
else if (curTemp >= thermoSetting) {
|
||||
digitalWrite(thermoPin, LOW);
|
||||
if (thermoPin<0) digitalWrite(-thermoPin, HIGH); digitalWrite(thermoPin, LOW);
|
||||
debugSerial<<F(" OFF");
|
||||
} //Reached settings
|
||||
else debugSerial<<F(" -target zone-"); // Nothing to do
|
||||
@@ -1650,8 +1650,10 @@ publishStat();
|
||||
}
|
||||
|
||||
short thermoSetCurTemp(char *name, float t) {
|
||||
if (!name || !strlen(name)) return 0;
|
||||
if (items) {
|
||||
aJsonObject *thermoItem = aJson.getObjectItem(items, name);
|
||||
if (!thermoItem) return 0;
|
||||
if (isThermostatWithMinArraySize(thermoItem, 4)) {
|
||||
aJsonObject *extArray = NULL;
|
||||
|
||||
@@ -1672,5 +1674,5 @@ short thermoSetCurTemp(char *name, float t) {
|
||||
att->valueint = (int) T_ATTEMPTS;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return 1;}
|
||||
return 0;}
|
||||
|
||||
@@ -98,7 +98,7 @@
|
||||
#endif
|
||||
|
||||
#define MQTT_SUBJECT_LENGTH 20
|
||||
#define MQTT_TOPIC_LENGTH 20
|
||||
#define MQTT_TOPIC_LENGTH 64
|
||||
|
||||
#ifndef DMX_DISABLE
|
||||
#define _dmxin
|
||||
|
||||
Reference in New Issue
Block a user