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:
1 parent
66588149a8
commit
c58e765253
3 files changed
+15
-6
No files matched your search
+12
-1
@@ -30,6 +30,13 @@
|
|||||||
|
|
||||||
#ifdef ZactuatorONOFF
|
#ifdef ZactuatorONOFF
|
||||||
|
|
||||||
|
void setupONOFF() {
|
||||||
|
pinMode(ACTUATOR_ONOFF_GPIO, OUTPUT);
|
||||||
|
# ifdef ACTUATOR_ONOFF_DEFAULT
|
||||||
|
digitalWrite(ACTUATOR_ONOFF_GPIO, ACTUATOR_ONOFF_DEFAULT);
|
||||||
|
# endif
|
||||||
|
}
|
||||||
|
|
||||||
# if jsonReceiving
|
# if jsonReceiving
|
||||||
void MQTTtoONOFF(char* topicOri, JsonObject& ONOFFdata) {
|
void MQTTtoONOFF(char* topicOri, JsonObject& ONOFFdata) {
|
||||||
if (cmpToMainTopic(topicOri, subjectMQTTtoONOFF)) {
|
if (cmpToMainTopic(topicOri, subjectMQTTtoONOFF)) {
|
||||||
@@ -104,7 +111,11 @@ void ActuatorButtonTrigger() {
|
|||||||
}
|
}
|
||||||
Log.trace(F("Actuator triggered %s by button" CR), level_string);
|
Log.trace(F("Actuator triggered %s by button" CR), level_string);
|
||||||
digitalWrite(ACTUATOR_ONOFF_GPIO, level);
|
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
|
#endif
|
||||||
+1
-3
@@ -39,9 +39,7 @@ extern void MQTTtoONOFF(char* topicOri, JsonObject& RFdata);
|
|||||||
#ifndef ACTUATOR_ON
|
#ifndef ACTUATOR_ON
|
||||||
# define ACTUATOR_ON LOW // LOW or HIGH, set to the output level of the gpio pin to turn the actuator on.
|
# define ACTUATOR_ON LOW // LOW or HIGH, set to the output level of the gpio pin to turn the actuator on.
|
||||||
#endif
|
#endif
|
||||||
#ifndef ACTUATOR_ONOFF_DEFAULT
|
//# define ACTUATOR_ONOFF_DEFAULT !ACTUATOR_ON // ACTUATOR_ON or !ACTUATOR_ON, set to the state desired on reset.
|
||||||
# define ACTUATOR_ONOFF_DEFAULT !ACTUATOR_ON // ACTUATOR_ON or !ACTUATOR_ON, set to the state desired on reset.
|
|
||||||
#endif
|
|
||||||
#ifndef ACTUATOR_BUTTON_TRIGGER_LEVEL
|
#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.
|
# 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
|
#endif
|
||||||
|
|||||||
+2
-2
@@ -723,8 +723,8 @@ void setup() {
|
|||||||
delay(1500);
|
delay(1500);
|
||||||
|
|
||||||
#ifdef ZactuatorONOFF
|
#ifdef ZactuatorONOFF
|
||||||
pinMode(ACTUATOR_ONOFF_GPIO, OUTPUT);
|
setupONOFF();
|
||||||
digitalWrite(ACTUATOR_ONOFF_GPIO, ACTUATOR_ONOFF_DEFAULT);
|
modules.add(ZactuatorONOFF);
|
||||||
#endif
|
#endif
|
||||||
#ifdef ZsensorBME280
|
#ifdef ZsensorBME280
|
||||||
setupZsensorBME280();
|
setupZsensorBME280();
|
||||||
|
|||||||
Reference in new issue
Block a user