Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ONOFF] ON OFF behavior fixes #1828

Merged
merged 1 commit into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions main/ZactuatorONOFF.ino
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,11 @@ void setupONOFF() {
# ifdef ACTUATOR_ONOFF_DEFAULT
digitalWrite(ACTUATOR_ONOFF_GPIO, ACTUATOR_ONOFF_DEFAULT);
# elif defined(ESP32)
if (ONOFFConfig.useLastStateOnStart)
if (ONOFFConfig.useLastStateOnStart) {
digitalWrite(ACTUATOR_ONOFF_GPIO, ONOFFConfig.ONOFFState);
} else {
digitalWrite(ACTUATOR_ONOFF_GPIO, !ACTUATOR_ON);
}
# endif
updatePowerIndicator();
Log.trace(F("ZactuatorONOFF setup done" CR));
Expand Down Expand Up @@ -194,6 +197,7 @@ void MQTTtoONOFF(char* topicOri, JsonObject& ONOFFdata) {

// Load config from json if available
ONOFFConfig_fromJson(ONOFFdata);
stateONOFFMeasures();
}
}
# endif
Expand Down Expand Up @@ -285,14 +289,12 @@ void ActuatorTrigger() {
} else {
PowerIndicatorOFF();
}
// Send the state of the switch to the broker so as to update the status
StaticJsonDocument<64> jsonBuffer;
JsonObject ONOFFdata = jsonBuffer.to<JsonObject>();
ONOFFdata["cmd"] = (int)level;
ONOFFdata["origin"] = subjectGTWONOFFtoMQTT;
handleJsonEnqueue(ONOFFdata, QueueSemaphoreTimeOutTask);

# ifdef ESP32
if (ONOFFConfig.useLastStateOnStart) {
StaticJsonDocument<64> jsonBuffer;
JsonObject ONOFFdata = jsonBuffer.to<JsonObject>();
ONOFFdata["cmd"] = (int)level;
ONOFFdata["save"] = true;
ONOFFConfig_fromJson(ONOFFdata);
}
Expand All @@ -302,9 +304,12 @@ void ActuatorTrigger() {

void stateONOFFMeasures() {
//Publish actuator state
StaticJsonDocument<64> jsonBuffer;
StaticJsonDocument<128> jsonBuffer;
JsonObject ONOFFdata = jsonBuffer.to<JsonObject>();
ONOFFdata["cmd"] = (int)digitalRead(ACTUATOR_ONOFF_GPIO);
# ifdef ESP32
ONOFFdata["uselaststate"] = ONOFFConfig.useLastStateOnStart;
# endif
ONOFFdata["origin"] = subjectGTWONOFFtoMQTT;
handleJsonEnqueue(ONOFFdata, QueueSemaphoreTimeOutTask);
}
Expand Down
5 changes: 3 additions & 2 deletions main/ZmqttDiscovery.ino
Original file line number Diff line number Diff line change
Expand Up @@ -949,7 +949,7 @@ void pubMqttDiscovery() {

# ifdef ZactuatorONOFF
Log.trace(F("actuatorONOFFDiscovery" CR));
char* actuatorONOFF[8] = {"switch", "actuatorONOFF", "", "", "", "{\"cmd\":1}", "{\"cmd\":0}", ""};
char* actuatorONOFF[8] = {"switch", "actuatorONOFF", "", "", "{{ value_json.cmd }}", "{\"cmd\":1}", "{\"cmd\":0}", ""};
//component type,name,availability topic,device class,value template,payload on, payload off, unit of measurement

//trc(actuatorONOFF[1]);
Expand All @@ -959,7 +959,8 @@ void pubMqttDiscovery() {
actuatorONOFF[5], actuatorONOFF[6], actuatorONOFF[7],
0, Gateway_AnnouncementMsg, will_Message, true, subjectMQTTtoONOFF,
"", "", "", "", false, // device name, device manufacturer, device model, device ID, retain
stateClassNone //State Class
stateClassNone, //State Class
"0", "1" //state_off, state_on
);
# endif

Expand Down
2 changes: 1 addition & 1 deletion main/ZsensorRN8209.ino
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void setupRN8209() {
cal.EC = RN8209_EC;
set_user_param(cal);
init_8209c_interface();
xTaskCreate(rn8209_loop, "rn8209_loop", 5000, NULL, 10, &rn8209TaskHandle);
xTaskCreate(rn8209_loop, "rn8209_loop", 5500, NULL, 10, &rn8209TaskHandle);
//esp_task_wdt_add(rn8209TaskHandle);
Log.trace(F("ZsensorRN8209 setup done " CR));
}
Expand Down