Enable to keep actuator on off state in case of restart (#1334)

and publish status as a json when triggering actuator on off through a button
This commit is contained in:
Florian authored and GitHub committed 2022-11-28 20:28:40 -06:00
1 parent 66588149a8
commit c58e765253
3 files changed
+15 -6

No files matched your search

+12 -1
View File
@@ -30,6 +30,13 @@
#ifdef ZactuatorONOFF
void setupONOFF() {
pinMode(ACTUATOR_ONOFF_GPIO, OUTPUT);
# ifdef ACTUATOR_ONOFF_DEFAULT
digitalWrite(ACTUATOR_ONOFF_GPIO, ACTUATOR_ONOFF_DEFAULT);
# endif
}
# if jsonReceiving
void MQTTtoONOFF(char* topicOri, JsonObject& ONOFFdata) {
if (cmpToMainTopic(topicOri, subjectMQTTtoONOFF)) {
@@ -104,7 +111,11 @@ void ActuatorButtonTrigger() {
}
Log.trace(F("Actuator triggered %s by button" CR), level_string);
digitalWrite(ACTUATOR_ONOFF_GPIO, level);
pub(subjectGTWONOFFtoMQTT, level_string);
// Send the state of the switch to the broker so as to update the status
StaticJsonDocument<JSON_MSG_BUFFER> jsonBuffer;
JsonObject ONOFFdata = jsonBuffer.to<JsonObject>();
ONOFFdata["cmd"] = (int)level;
pub(subjectGTWONOFFtoMQTT, ONOFFdata);
}
#endif
+1 -3
View File
@@ -39,9 +39,7 @@ extern void MQTTtoONOFF(char* topicOri, JsonObject& RFdata);
#ifndef ACTUATOR_ON
# define ACTUATOR_ON LOW // LOW or HIGH, set to the output level of the gpio pin to turn the actuator on.
#endif
#ifndef ACTUATOR_ONOFF_DEFAULT
# define ACTUATOR_ONOFF_DEFAULT !ACTUATOR_ON // ACTUATOR_ON or !ACTUATOR_ON, set to the state desired on reset.
#endif
//# define ACTUATOR_ONOFF_DEFAULT !ACTUATOR_ON // ACTUATOR_ON or !ACTUATOR_ON, set to the state desired on reset.
#ifndef ACTUATOR_BUTTON_TRIGGER_LEVEL
# define ACTUATOR_BUTTON_TRIGGER_LEVEL LOW // 0 or 1, set to the sensing level which to detect a button press to change the actuator state.
#endif
+2 -2
View File
@@ -723,8 +723,8 @@ void setup() {
delay(1500);
#ifdef ZactuatorONOFF
pinMode(ACTUATOR_ONOFF_GPIO, OUTPUT);
digitalWrite(ACTUATOR_ONOFF_GPIO, ACTUATOR_ONOFF_DEFAULT);
setupONOFF();
modules.add(ZactuatorONOFF);
#endif
#ifdef ZsensorBME280
setupZsensorBME280();