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] Fix actuator manual control with button press and overheat protection #1403

Merged
merged 1 commit into from
Jan 19, 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
23 changes: 12 additions & 11 deletions main/ZactuatorONOFF.ino
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,15 @@ void MQTTtoONOFF(char* topicOri, char* datacallback) {
void OverHeatingRelayOFF() {
# if defined(ESP32) && !defined(NO_INT_TEMP_READING)
if (millis() > (timeinttemp + TimeBetweenReadingIntTemp)) {
static float previousInternalTempc = 0;
float internalTempc = intTemperatureRead();
Log.trace(F("Internal temperature of the ESP32 %F" CR), internalTempc);
if (internalTempc > MAX_TEMP_ACTUATOR && digitalRead(ACTUATOR_ONOFF_GPIO) == ACTUATOR_ON) {
// We switch OFF the actuator if the temperature of the ESP32 is more than MAX_TEMP_ACTUATOR two consecutive times, so as to avoid false single readings to trigger the relay OFF.
if (internalTempc > MAX_TEMP_ACTUATOR && previousInternalTempc > MAX_TEMP_ACTUATOR && digitalRead(ACTUATOR_ONOFF_GPIO) == ACTUATOR_ON) {
Log.error(F("[ActuatorONOFF] OverTemperature detected ( %F > %F ) switching OFF Actuator" CR), internalTempc, MAX_TEMP_ACTUATOR);
ActuatorManualTrigger(!ACTUATOR_ON);
ActuatorTrigger();
}
previousInternalTempc = internalTempc;
timeinttemp = millis();
}
# endif
Expand All @@ -123,15 +126,13 @@ void OverHeatingRelayOFF() {
void OverHeatingRelayOFF() {}
# endif

void ActuatorManualTrigger(uint8_t level) {
# ifdef ACTUATOR_BUTTON_TRIGGER_LEVEL
if (level == ACTUATOR_BUTTON_TRIGGER_LEVEL) {
// Change level value to the opposite of the current level
level = !digitalRead(ACTUATOR_ONOFF_GPIO);
}
# else
level = !digitalRead(ACTUATOR_ONOFF_GPIO);
# endif
/*
Handling of actuator control following the cases below:
-Button press, if the button goes to ACTUATOR_BUTTON_TRIGGER_LEVEL we change the Actuator level
-Status less switch state change (a switch without ON OFF labels), an action of this type of switch will trigger a change of the actuator state independently from the switch position
*/
void ActuatorTrigger() {
uint8_t level = !digitalRead(ACTUATOR_ONOFF_GPIO);
Log.trace(F("Actuator triggered %d" CR), level);
digitalWrite(ACTUATOR_ONOFF_GPIO, level);
// Send the state of the switch to the broker so as to update the status
Expand Down
9 changes: 8 additions & 1 deletion main/ZsensorGPIOInput.ino
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,14 @@ void MeasureGPIOInput() {

# if defined(ZactuatorONOFF) && defined(ACTUATOR_TRIGGER)
//Trigger the actuator if we are not at startup
if (InputState != 3) ActuatorManualTrigger(InputState);
if (InputState != 3) {
# if defined(ACTUATOR_BUTTON_TRIGGER_LEVEL)
if (InputState == ACTUATOR_BUTTON_TRIGGER_LEVEL)
ActuatorTrigger(); // Button press trigger
# else
ActuatorTrigger(); // Switch trigger
# endif
}
# endif
InputState = reading;
}
Expand Down
8 changes: 4 additions & 4 deletions main/config_ONOFF.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ extern void MQTTtoONOFF(char* topicOri, JsonObject& RFdata);
# define ACTUATOR_ON LOW // LOW or HIGH, set to the output level of the GPIO pin to turn the actuator on.
#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
#ifndef ACTUATOR_TRIGGER
# define ACTUATOR_TRIGGER false // false or true, enable to control an actuator directly from the board switch (default behavior if true), or by button if ACTUATOR_BUTTON_TRIGGER_LEVEL is defined
# define ACTUATOR_TRIGGER false // false or true, enable to control an actuator directly from the board switch (default behavior if true), or by button if ACTUATOR_BUTTON_TRIGGER_LEVEL is also defined
#endif
#ifndef ACTUATOR_BUTTON_TRIGGER_LEVEL
//# define ACTUATOR_BUTTON_TRIGGER_LEVEL LOW // 0 or 1, set to the level which to detect a button press to change the actuator state.
#endif
#ifndef MAX_TEMP_ACTUATOR
//# define MAX_TEMP_ACTUATOR 70 // Temperature that will trigger the relay to go OFF
Expand Down
5 changes: 4 additions & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,8 @@ build_flags =
'-DZgatewayIR="IR"'
'-DZgatewayBT="BT"'
'-DZactuatorONOFF="ONOFF"'
'-DACTUATOR_BUTTON_TRIGGER_LEVEL=0'
'-ACTUATOR_TRIGGER=true'
'-DZactuatorFASTLED="FASTLED"'
'-DZactuatorPWM="PWM"'
'-DZsensorINA226="INA226"'
Expand All @@ -296,6 +298,7 @@ build_flags =
'-DZsensorGPIOInput="GPIOInput"'
'-DZsensorGPIOKeyCode="GPIOKeyCode"'
'-DZsensorRN8209="RN8209"'
'-DMAX_TEMP_ACTUATOR=80'
'-DZgatewayWeatherStation="WeatherStation"'
'-DsimplePublishing=true'
'-DWM_PWD_FROM_MAC=true'
Expand Down Expand Up @@ -1066,7 +1069,7 @@ build_flags =
'-DACTUATOR_ONOFF_GPIO=26'
'-DZsensorADC="ADC"'
'-DADC_GPIO=32'
'-DMAX_TEMP_ACTUATOR=70'
;'-DMAX_TEMP_ACTUATOR=70' ; uncomment to activate automatic switch off following ESP32 temperature measurement (experimental)
'-DUSE_MAC_AS_GATEWAY_NAME'
'-DFRAMEWORK_ARDUINO_SOLO1'
'-DGATEWAY_MANUFACTURER="Shelly"'
Expand Down