Formatting hint: Your defer & add nodes line up, making it very difficult to see where wires are actually connected. Moving âdeferâ up & to the right one position might make things a little more clear.
This look pretty good, except for the fact that âbufferâ only updates when Temp changes to more than 30 or less than 30. It doesnât continue to change each time Temp is checked. (âselectâ only gets a pulse when one of the conditions changes to true)
I think you said you wanted to check the temp every 15 minutes (900 seconds). I assume that is what the âdelayâ node is for. You COULD use delay (have DONE trigger SET to keep repeating), but âclockâ would be a better option. Set clock-IVAL=900, then feed clock-tick to Temp-UPD to check Temp every 15 minutes. Now delete the link between buffer-UPD and âselectâ and link Temp-DONE to buffer-UPD and buffer will update every 15 minutes. Just to be safe, you might want to put a âdeferâ before buffer-UPD. This is a direct link from Temp to buffer, and the values you want to use pass through conditional & select nodes. Adding defer will make sure those values get updated before you update buffer.
A slight âbugâ with what you end up with: when Temp is equal to 30, you will continue to adjust the power in whatever direction you were going, but it would probably be better to keep the same power level. Since Temp is a floating point number, it will almost never be exactly 30, so this is a very minor issue.
Looking closer, I think you need to switch your âgreaterâ and âlessâ nodes. You want to add power when temp is <30, not when temp is >30.
You can add fail-safe checks by expanding your select. If Temp>40, set power to 0. If Temp <20, set power to 1.
Just noticed another bug: there is nothing to keep buffer from going below zero of over 1. You can add if-else between âaddâ and âselectâ to output 1 if add output is >1 and between âsubtractâ and âselectâ to return 0 if subtract output is <0
For example:
The down-side of this solution is that you will always be over-shooting the target temperature. A better option might be to set power based on how far we are from target temperature. For example, if you want to stay within 5 degrees of 30, you can calculate 30-Temp, then map [-5âŚ5] to [0.0âŚ1.0] using âmap-clipâ. Now you donât need to wait 15 minutes to check temp & you can get smoother power transitions and steadier temperature. If you want to improve performance even more, you can factor in âoutsideâ temperature (outside of the terrariumâif it is in the house, this might be a non-issue).
You might find that this results in temp always holding steady just above or below target temp, so adjustments might be neededâit is assuming 50% power is needed at set temp, which may well be wrong. You might also find power ramps up/down too fast, in which case easiest solution is probably to expand the Smin/Smax. Using [-10âŚ10] will change power setting half as fast.