Version 0.9.5, interior lights are now only controlled by the open door or a 5 minutes timer. The timer is started via an MQTT command. The BMS web application sends this command just before a webcam page is requested.

Sat, 27 Apr 2019 15:36:16 +0200

author
Chiel Broek <mbse@mbse.eu>
date
Sat, 27 Apr 2019 15:36:16 +0200
changeset 582
ba340e00aab2
parent 581
b56988cc516b
child 583
9795a16de807

Version 0.9.5, interior lights are now only controlled by the open door or a 5 minutes timer. The timer is started via an MQTT command. The BMS web application sends this command just before a webcam page is requested.

configure file | annotate | diff | comparison | revisions
configure.ac file | annotate | diff | comparison | revisions
thermferm/mqtt.c file | annotate | diff | comparison | revisions
thermferm/rdconfig.c file | annotate | diff | comparison | revisions
thermferm/server.c file | annotate | diff | comparison | revisions
thermferm/thermferm.c file | annotate | diff | comparison | revisions
thermferm/thermferm.h file | annotate | diff | comparison | revisions
--- a/configure	Sun Mar 31 13:57:25 2019 +0200
+++ b/configure	Sat Apr 27 15:36:16 2019 +0200
@@ -661,6 +661,7 @@
 docdir
 oldincludedir
 includedir
+runstatedir
 localstatedir
 sharedstatedir
 sysconfdir
@@ -734,6 +735,7 @@
 sysconfdir='${prefix}/etc'
 sharedstatedir='${prefix}/com'
 localstatedir='${prefix}/var'
+runstatedir='${localstatedir}/run'
 includedir='${prefix}/include'
 oldincludedir='/usr/include'
 docdir='${datarootdir}/doc/${PACKAGE}'
@@ -986,6 +988,15 @@
   | -silent | --silent | --silen | --sile | --sil)
     silent=yes ;;
 
+  -runstatedir | --runstatedir | --runstatedi | --runstated \
+  | --runstate | --runstat | --runsta | --runst | --runs \
+  | --run | --ru | --r)
+    ac_prev=runstatedir ;;
+  -runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \
+  | --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \
+  | --run=* | --ru=* | --r=*)
+    runstatedir=$ac_optarg ;;
+
   -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)
     ac_prev=sbindir ;;
   -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \
@@ -1123,7 +1134,7 @@
 for ac_var in	exec_prefix prefix bindir sbindir libexecdir datarootdir \
 		datadir sysconfdir sharedstatedir localstatedir includedir \
 		oldincludedir docdir infodir htmldir dvidir pdfdir psdir \
-		libdir localedir mandir
+		libdir localedir mandir runstatedir
 do
   eval ac_val=\$$ac_var
   # Remove trailing slashes.
@@ -1276,6 +1287,7 @@
   --sysconfdir=DIR        read-only single-machine data [PREFIX/etc]
   --sharedstatedir=DIR    modifiable architecture-independent data [PREFIX/com]
   --localstatedir=DIR     modifiable single-machine data [PREFIX/var]
+  --runstatedir=DIR       modifiable per-process data [LOCALSTATEDIR/run]
   --libdir=DIR            object code libraries [EPREFIX/lib]
   --includedir=DIR        C header files [PREFIX/include]
   --oldincludedir=DIR     C header files for non-gcc [/usr/include]
@@ -2035,7 +2047,7 @@
 
 
 PACKAGE="mbsePi-apps"
-VERSION="0.9.4"
+VERSION="0.9.5"
 COPYRIGHT="Copyright (C) 2014-2019 Michiel Broek, All Rights Reserved"
 CYEARS="2014-2019"
 
--- a/configure.ac	Sun Mar 31 13:57:25 2019 +0200
+++ b/configure.ac	Sat Apr 27 15:36:16 2019 +0200
@@ -8,7 +8,7 @@
 dnl General settings
 dnl After changeing the version number, run autoconf!
 PACKAGE="mbsePi-apps"
-VERSION="0.9.4"
+VERSION="0.9.5"
 COPYRIGHT="Copyright (C) 2014-2019 Michiel Broek, All Rights Reserved"
 CYEARS="2014-2019"
 AC_SUBST(PACKAGE)
--- a/thermferm/mqtt.c	Sun Mar 31 13:57:25 2019 +0200
+++ b/thermferm/mqtt.c	Sat Apr 27 15:36:16 2019 +0200
@@ -257,7 +257,7 @@
 						/* Allways turn everything off after a mode change */
 						unit->PID_cool->OutP = unit->PID_heat->OutP = 0.0;
 						unit->PID_cool->Mode = unit->PID_heat->Mode = PID_MODE_NONE;
-						unit->heater_state = unit->cooler_state = unit->fan_state = unit->light_state = 0;
+						unit->heater_state = unit->cooler_state = unit->fan_state = unit->light_state = unit->light_timer = 0;
 						unit->heater_wait = unit->cooler_wait = unit->fan_wait = unit->light_wait = 0;
 						device_out(unit->heater_address, unit->heater_state);
 						device_out(unit->cooler_address, unit->cooler_state);
@@ -336,12 +336,16 @@
 				    }
 				}
 
-				if ((json_object_object_get_ex(metric, "light", &setpoint)) && (unit->mode == UNITMODE_NONE)) {
+				if (json_object_object_get_ex(metric, "light", &setpoint)) {
 				    if (json_object_object_get_ex(setpoint, "state", &val)) {
-					if (json_object_get_int(val) != unit->light_state) {
-					    unit->light_state = json_object_get_int(val);
-					    unit->mqtt_flag |= MQTT_FLAG_DATA;
-					    syslog(LOG_NOTICE, "DCMD change fermenter %s: light_state to %d", message_alias, unit->light_state);
+					if (json_object_get_int(val) > 0) {
+					    unit->light_timer = 300;	// 5 minutes
+					    syslog(LOG_NOTICE, "DCMD set fermenter %s: light_timer 300", message_alias);
+					    if (!unit->light_state) {
+					    	unit->light_state = 1;
+					    	unit->mqtt_flag |= MQTT_FLAG_DATA;
+					    	syslog(LOG_NOTICE, "DCMD change fermenter %s: light_state to %d", message_alias, unit->light_state);
+					    }
 					}
 				    }
 				}
--- a/thermferm/rdconfig.c	Sun Mar 31 13:57:25 2019 +0200
+++ b/thermferm/rdconfig.c	Sat Apr 27 15:36:16 2019 +0200
@@ -577,7 +577,7 @@
 			    unit->fridge_set_lo = unit->fridge_set_hi = unit->profile_inittemp_lo = unit->profile_inittemp_hi = 20.0;
     unit->air_state = unit->beer_state = unit->chiller_state = 1; // missing
     unit->heater_state = unit->cooler_state = unit->fan_state = unit->door_state = \
-			 unit->light_state = unit->psu_state = unit->mode = unit->prof_state = unit->stage = 0;
+			 unit->light_state = unit->light_timer = unit->psu_state = unit->mode = unit->prof_state = unit->stage = 0;
     unit->air_idx = unit->beer_idx = unit->chiller_idx = unit->heater_idx = unit->cooler_idx = unit->fan_idx = \
 		    unit->door_idx = unit->light_idx = unit->psu_idx = unit->profile_fridge_mode = \
 		    unit->profile_duration = unit->profile_totalsteps = 0;
--- a/thermferm/server.c	Sun Mar 31 13:57:25 2019 +0200
+++ b/thermferm/server.c	Sat Apr 27 15:36:16 2019 +0200
@@ -1699,7 +1699,7 @@
 	unit->air_temperature = unit->beer_temperature = unit->chiller_temperature = 20000;
 	unit->beer_set_lo = unit->beer_set_hi = unit->fridge_set_lo = unit->fridge_set_hi = unit->profile_inittemp_lo = unit->profile_inittemp_hi =20.0;
 	unit->heater_state = unit->cooler_state = unit->fan_state = unit->door_state = unit->mode = \
-			     unit->light_state = unit->psu_state = unit->prof_state = unit->stage = 0;
+			     unit->light_state = unit->light_timer = unit->psu_state = unit->prof_state = unit->stage = 0;
 	unit->heater_delay = unit->cooler_delay = unit->fan_delay = 20;	/* 5 minutes delay	*/
 	unit->light_delay = 1;						/* 15 seconds delay	*/
 	unit->heater_wait = unit->cooler_wait = unit->fan_wait = unit->light_wait = 0;
@@ -2205,7 +2205,7 @@
 					/* Allways turn everything off after a mode change */
 					unit->PID_cool->OutP = unit->PID_heat->OutP = 0.0;
 					unit->PID_cool->Mode = unit->PID_heat->Mode = PID_MODE_NONE;
-					unit->heater_state = unit->cooler_state = unit->fan_state = unit->light_state = 0;
+					unit->heater_state = unit->cooler_state = unit->fan_state = unit->light_state = unit->light_timer = 0;
 					unit->heater_wait = unit->cooler_wait = unit->fan_wait = unit->light_wait = 0;
 					device_out(unit->heater_address, unit->heater_state);
 					device_out(unit->cooler_address, unit->cooler_state);
--- a/thermferm/thermferm.c	Sun Mar 31 13:57:25 2019 +0200
+++ b/thermferm/thermferm.c	Sat Apr 27 15:36:16 2019 +0200
@@ -415,7 +415,7 @@
     /* Allways turn everything off after a mode change */
     current_unit->PID_cool->OutP = current_unit->PID_heat->OutP = 0.0;
     current_unit->PID_cool->Mode = current_unit->PID_heat->Mode = PID_MODE_NONE;
-    current_unit->heater_state = current_unit->cooler_state = current_unit->fan_state = current_unit->light_state = 0;
+    current_unit->heater_state = current_unit->cooler_state = current_unit->fan_state = current_unit->light_state = current_unit->light_timer = 0;
     current_unit->heater_wait = current_unit->cooler_wait = current_unit->fan_wait = current_unit->light_wait = 0;
     device_out(current_unit->heater_address, current_unit->heater_state);
     device_out(current_unit->cooler_address, current_unit->cooler_state);
@@ -1105,7 +1105,7 @@
 	 * Safety, turn everything off
 	 */
 	unit->mqtt_flag = unit->alarm_flag = unit->alarm_last = 0;
-	unit->heater_state = unit->cooler_state = unit->fan_state = unit->door_state = unit->light_state = 0;
+	unit->heater_state = unit->cooler_state = unit->fan_state = unit->door_state = unit->light_state = unit->light_timer = 0;
 	unit->heater_wait = unit->cooler_wait = unit->fan_wait = unit->light_wait = 0;
 	if (unit->mode == UNITMODE_PROFILE) {
 	    if (!unit->profile_uuid)
@@ -1637,7 +1637,10 @@
 		 * Interior lights
 		 */
 		if (unit->light_address) {
-		    if (unit->door_state && (unit->mode == UNITMODE_NONE) && unit->light_state) {
+		    if (unit->light_timer) {
+			unit->light_timer--;
+		    }
+		    if (unit->door_state && !unit->light_timer && unit->light_state) {
 			if (unit->light_wait > 0) {
 			    unit->light_wait--;
 			} else {
@@ -1646,7 +1649,7 @@
 			    unit->mqtt_flag |= MQTT_FLAG_DATA;
 			}
 		    }
-		    if ((!unit->door_state || (unit->mode != UNITMODE_NONE)) && !unit->light_state) {
+		    if ((!unit->door_state || unit->light_timer) && !unit->light_state) {
 			unit->light_wait = unit->light_delay;   /* No delay to turn lights on   */
 			unit->light_state = 1;
 			unit->mqtt_flag |= MQTT_FLAG_DATA;
@@ -2060,7 +2063,7 @@
 	/*
 	 * Turn everything off
 	 */
-	unit->heater_state = unit->cooler_state = unit->fan_state = unit->door_state = unit->light_state = 0;
+	unit->heater_state = unit->cooler_state = unit->fan_state = unit->door_state = unit->light_state = unit->light_timer = 0;
 	unit->heater_wait = unit->cooler_wait = unit->fan_wait = unit->light_wait = 0;
 	device_out(unit->heater_address, unit->heater_state);
 	pub_domoticz_output(unit->heater_idx, unit->heater_state);
--- a/thermferm/thermferm.h	Sun Mar 31 13:57:25 2019 +0200
+++ b/thermferm/thermferm.h	Sat Apr 27 15:36:16 2019 +0200
@@ -186,6 +186,7 @@
     int			light_wait;		/* Lights wait counter		*/
     int			light_usage;		/* Lights usage in seconds	*/
     int			light_idx;		/* Domoticz idx			*/
+    int			light_timer;		/* Lights timer			*/
     char		*door_address;		/* Door input address		*/
     int			door_state;		/* Door status			*/
     int			door_idx;		/* Domoticz idx			*/

mercurial