I'm currently trying to automate my indoor grow tent.
It is composed of
- 200 lm301b leds associated to an AC-DC meanwell driver
- a 220v (14W) heating mat
- a 5v (2.5W) mist masker
- a 12v pc fan
- a htu21d sensor
- a bh1750 lux sensor
- 2 DC-DC SSR
- 2 DC-AC mechanical relays
- a nodemcu
- Light on between lightBegin and lightEnd
- Fan on for w minutes then fan off for x minutes
- Mist maker for on for y minutes every z minutes (if htu21d humidity below a threshold)
- Heat on when temperature below lowerThreshold and heat off when temperature below upperThreshold
So I have implemented those rules (all values/thresholds are hardcoded for now)
Code: Select all
On System#Boot do gpio,12,0 //Light pin gpio,13,0 //Vent pin gpio,14,0 //Mist pin gpio,15,0 //Heat pin timerSet,1,10 //Light timer timerSet,2,11 //Vent on timer timerSet,3,0 //Vent off timer timerSet,4,12 //Mist on timer timerSet,5,0 //Mist off timer timerSet,6,60 endon //Light timer On Rules#Timer=1 do if %syshour%>6 and %syshour%<22 gpio,12,1 else gpio,12,0 endif timerSet,1,60 endon //Vent on timer On Rules#Timer=2 do gpio,14,1 timerSet,3,120 endon //Vent off timer On Rules#Timer=3 do gpio,14,0 timerSet,2,180 endon //Mist on timer On Rules#Timer=4 do if [htu21d#humidity]>0.0 and [htu21d#humidity]<25.0 Publish %sysname%/humidity,[htu21d#humidity] gpio,13,1 timerSet,5,60 endif timerSet,4,3600 endon //Mist off timer On Rules#Timer=5 do gpio,13,0 endon //Heat on On htu21d#temperature<20 do gpio,15,1 endon //Heat off on htu21d#temperature>22 do gpio,15,0 endon //Emergency stop On Rules#Timer=6 do if [htu21d#temperature]>40 or [htu21d#humidity]>85 gpio,12,0 gpio,13,0 gpio,14,0 gpio,15,0 timerSet,1,0 timerSet,2,0 timerSet,3,0 timerSet,4,0 timerSet,5,0 timerSet,6,0 else timerSet,6,60 endif endon
I have 2 goals now:
- The main goal is to have a totally autonomous esp that does not rely on an external device to work (it's already done) BUT I'd like if needed to be also able to set the values/threshold via events. I know those values could survive a reboot and not a restart but that's not the point here.
I think I have to setup dummy devices and variables but don't know the most efficient way of doing it.
If we take only the light example, I was thinking about someting like this (not tested yet)Would it work? How could it be optimized?
Code: Select all
On System#Boot do gpio,12,0 //Light pin TaskValueSet 10,1,7 //[dummy#lightBegin] TaskValueSet 10,1,23 //[dummy#lightEnd] timerSet,1,10 //Light timer endon On Rules#Timer=1 do if %syshour%>[dummy#lightBegin] and %syshour%<[dummy#lightEnd] gpio,12,1 else gpio,12,0 endif timerSet,1,60 endon On lightOn do TaskValueSet 10,1,%eventvalue% //[dummy#lightBegin] timerSet,1,1 // Force the light loop to take the new lightBegin parameter endon On lightOff do TaskValueSet 10,2,%eventvalue% //[dummy#lightEnd] timerSet,1,1 // Force the light loop to take the new lightEnd parameter endon
- I'd also like to be able to handle sensor erros: How do espeasy handle i2c or sensor errors? I'd like to be able to shutdown everything if temperature > 40 or humidity > 80 or htu21d sensor not responding
Does the plugin send a NaN, a 0 or another value if a I2C pin is disconnected or the sensor broken?
When I disconnect a pin and reboot, the last valid value is still pushed to MQTT -> How to hande this case? I was thinking of storing the last value in a Dummy var and compare it with the current. If it's exactly the same (float with 2 digits), sensor might not be working and all devices should be shutdown.
When I disconnect a pin and restart, value seems to be 0 (didn't have time to test it) -> How to hande this case? I can add conditions for temperature >0 and humidity> which seems relevant because in this context, neither temperature nor humidity should reach this value