diff --git a/inputs.cpp b/inputs.cpp index a19c7a7..93212ce 100644 --- a/inputs.cpp +++ b/inputs.cpp @@ -121,11 +121,11 @@ void Input::Changed (int val) if (val) { //send set command - if (scmd) client.publish(emit->valuestring,scmd->valuestring); else client.publish(emit->valuestring,"ON"); + if (!scmd) client.publish(emit->valuestring,"ON"); else if (strlen(scmd->valuestring)) client.publish(emit->valuestring,scmd->valuestring); } else { //send reset command - if (rcmd) client.publish(emit->valuestring,rcmd->valuestring); else client.publish(emit->valuestring,"OFF"); + if (!rcmd) client.publish(emit->valuestring,"OFF"); else if (strlen(rcmd->valuestring)) client.publish(emit->valuestring,rcmd->valuestring); } } @@ -136,11 +136,11 @@ void Input::Changed (int val) { if (val) { //send set command - if (scmd) it.Ctrl(txt2cmd(scmd->valuestring),0,NULL,true); else it.Ctrl(CMD_ON,0,NULL,true); + if (!scmd) it.Ctrl(CMD_ON,0,NULL,true); else if (strlen(scmd->valuestring)) it.Ctrl(txt2cmd(scmd->valuestring),0,NULL,true); } else { //send reset command - if (rcmd) it.Ctrl(txt2cmd(scmd->valuestring),0,NULL,true); else it.Ctrl(CMD_OFF,0,NULL,true); + if (!rcmd) it.Ctrl(CMD_OFF,0,NULL,true); else if (strlen(rcmd->valuestring)) it.Ctrl(txt2cmd(rcmd->valuestring),0,NULL,true); } } } diff --git a/item.cpp b/item.cpp index 9d40567..4844406 100644 --- a/item.cpp +++ b/item.cpp @@ -599,6 +599,9 @@ int Item::VacomSetHeat(int addr, int8_t val, int8_t cmd) } int Item::SendCmd(short cmd,short n, int * Par) { + +/// ToDo: relative patches, configuration + char addrstr[32]; //char addrbuf[17]; char valstr[16]=""; @@ -801,12 +804,17 @@ int Item::checkModbus(int data) if (d) { // Actually turned on - SendCmd(0,1,&d); //update OH - setCmd(CMD_ON); - setVal(d); //Storing + if (cmd==CMD_OFF || cmd==CMD_HALT) SendCmd(CMD_ON); //update OH with ON if it was turned off before + SendCmd(0,1,&d); //update OH with value + setCmd(CMD_ON); //store command + setVal(d); //store value } else { - if (cmd!=CMD_HALT && cmd!=CMD_OFF) {setCmd(CMD_OFF); SendCmd(CMD_OFF); } + if (cmd!=CMD_HALT && cmd!=CMD_OFF) + { + setCmd(CMD_OFF); // store command (not value) + SendCmd(CMD_OFF);// update OH + } } } //if data changed }