Variable speed cooling fan

the register

Community Member
View Badges
Joined
Apr 16, 2009
Messages
50
Reaction score
47
Rating - 0%
0   0   0
I DIY'ed a could cooling fans out of a 3d printed hinge and some computer fans. Works fine connected to my red reef pi as DC fans, but is loud.

I'd ideally like to run them at variable speed, ramping up at a baseline pressure and increasing power as temp increases. The current reef pi system doesn't seem to have any way to do that. Equipment is on/off, but I can set it up as a pwm light.

However, there's no way to do this with temperatures. Not only is there no way to adjust the temp, but there's no way to control anything besides equipment. You can try and use a macro, but macros don't seem to do anything when you tell it to turn a light on it off. Nothing changes AFAICT.

My plan is to instead just build this myself by creating a cronjob to do it outside the UI using the API. I'd like to see info in the UI about it, but I'll punt on that for V1.

First question: is anyone doing variable speed fans with reef pi?

My default guess is no, so I'd just build it.

To build it, my plan would be to create a script that just (I'm making assumptions on what APIs exist):

1. Create a secondary temperature, setup to run a macro called "VariableFanScript1", with that macro having a step to change a light. Right now that does nothing. I'll use those to effectively pass config info to my script

The script will:
1. Hit the temperature API and get all temperatures. For any temperature configured to run a macro named VariableFanScript*, I'll grab the macro and pull all lights it's configured to touch. That will give me the set of temperatures to use, their configs, and their corresponding lights
2. pull the current temperature for those, if I didn't already get it
3. Read the temperature's cooler setting as a fan min temp, and the min + hysterisis as max
4. Compare the current temp to the min/max temp and if greater than min, scale a speed setting linearly. Max 100%
5. Based on that, switch the manual setting on a "light" between 0 and 100% accordingly

Assuming those APIs are hittable, it should be straightforward. I then could reconfigure the settings in the UI, easily disable it if needed, and even see the cooler settings in the temp graphs.

Assuming this works, I'd far prefer it to trying to write all this out through clicking around in a UI.

Second question: what gotchas am I liable to hit here?
 

Wolfw28

Active Member
View Badges
Joined
Mar 13, 2022
Messages
201
Reaction score
138
Location
Myakka City
Rating - 0%
0   0   0
1 I would use multiple temp control using the same sensor with multiple input and chiller controls and macro
2 set up multiple light each with different pulse with output to same device.
3 set up multiple macro to turn on the multiple lights at different pulse withs.
4 attach a MOSFET to the pulse with circuit and power circuit to the fan.
So if it 80 degrees temp 1 activates macro 1 to turn on light control 1 to 100 Percent. The next one can be 70 and 80 percent and so on. Or you can buy a

Noctua super quick fan I have 2 mounted on the top of my tank you can even tell there on​

 

Attachments

  • A67927CE-9D6B-44C3-BE38-1E5D8AB5B314.png
    A67927CE-9D6B-44C3-BE38-1E5D8AB5B314.png
    435.2 KB · Views: 36

Sral

Valuable Member
View Badges
Joined
May 2, 2022
Messages
1,006
Reaction score
976
Location
Germany
Rating - 0%
0   0   0
@the register Sounds possible anr pdobably easier than one thinks, since @Ranjib made it work through an http API.

He described how to update "lights" here. You probably need to define the lights as static and then need to find out the name of the "power" property in the database.
Even if you don't plan on using python you can look at the http API usage in this example. Main things to take from there: http login, and the http get and http post queries to log in, get info from API and toggle/change equipment etc.

I do however very much like @Wolfw28 's approach:
if that's possible, simply define 3 temperature controls that toggle macros at let's say 76°F, 77°F, 78°F or whatever you need, with some hysteresis. If those macros can switch the "light"/fan PWM output from 0% to 30%, from 30% to 60% and from 60% to 90% you have a UI-clickable solution.
(fans have a minimal working speed, depending on the fan they require a minimum of 30% PWM duty cycle, or they are mapped that 0% duty cycle equals their minimal speed, you have to test that out). The MOSFET drivers should do the trick. Since fans are inductive loads, you might want to add freewheeling diode(s) to protect your power supply.

Only thing you might not have in the UI version, I think, is an easy Off-switch.
 
OP
OP
T

the register

Community Member
View Badges
Joined
Apr 16, 2009
Messages
50
Reaction score
47
Rating - 0%
0   0   0
@the register Sounds possible anr pdobably easier than one thinks, since @Ranjib made it work through an http API.

He described how to update "lights" here. You probably need to define the lights as static and then need to find out the name of the "power" property in the database.
Even if you don't plan on using python you can look at the http API usage in this example. Main things to take from there: http login, and the http get and http post queries to log in, get info from API and toggle/change equipment etc.

I do however very much like @Wolfw28 's approach:
if that's possible, simply define 3 temperature controls that toggle macros at let's say 76°F, 77°F, 78°F or whatever you need, with some hysteresis. If those macros can switch the "light"/fan PWM output from 0% to 30%, from 30% to 60% and from 60% to 90% you have a UI-clickable solution.
(fans have a minimal working speed, depending on the fan they require a minimum of 30% PWM duty cycle, or they are mapped that 0% duty cycle equals their minimal speed, you have to test that out). The MOSFET drivers should do the trick. Since fans are inductive loads, you might want to add freewheeling diode(s) to protect your power supply.

Only thing you might not have in the UI version, I think, is an easy Off-switch.
The issue is the macro controls in reef pi are pretty basic, and you can't adjust lighting power from them. In my current testing they don't actually work at all with lighting (it should allow on/off, but my experience is it's currently broken).

Unless I'm missing something, which is totally possible.
 

Sral

Valuable Member
View Badges
Joined
May 2, 2022
Messages
1,006
Reaction score
976
Location
Germany
Rating - 0%
0   0   0
The issue is the macro controls in reef pi are pretty basic, and you can't adjust lighting power from them. In my current testing they don't actually work at all with lighting (it should allow on/off, but my experience is it's currently broken).

Unless I'm missing something, which is totally possible.
Then you might be able to do it like @Wolfw28 suggested: turn different lights on/off that all trigger the same PWM channel. At least if toggling lights with macros works better than you seem to think :grinning-face-with-sweat:
 
OP
OP
T

the register

Community Member
View Badges
Joined
Apr 16, 2009
Messages
50
Reaction score
47
Rating - 0%
0   0   0
Then you might be able to do it like @Wolfw28 suggested: turn different lights on/off that all trigger the same PWM channel. At least if toggling lights with macros works better than you seem to think :grinning-face-with-sweat:
That's an interesting setup, but yes my experience is a macro + light does nothing. That however is certainly a bug and fixable though.

From a return on my time standpoint, I think the script version will be cleaner and more extensible.

@Ranjib I'm curious your take on the script idea. I actually was thinking it'd be pretty easy to extend that a couple steps further and productionize it on top of reef pi with a UI. As with all scripts the programmer in me would want version control + CICD for it. I'm thinking if I prototype this out, and create a couple simple wrappers around reef pi apis, I could generalize this.

My mindset being it wouldn't be too hard to make this work similar to something like chef or ansible or terraform. Have a library for interacting with reef pi constructs, and then a dsl or yaml or json configs for creating the actual items, and scripts that trigger in defined conditions.

I then could do the config editing in GitHub, and have a script just periodically pull the main branch from the config repo. My version would be standalone, but at some point it could be documented and slapped behind a UI and integrate into the actual reef pi UX.
 
OP
OP
T

the register

Community Member
View Badges
Joined
Apr 16, 2009
Messages
50
Reaction score
47
Rating - 0%
0   0   0
Variable speed fan control implemented via the API: https://github.com/richievos/reef-pi-ext-macros

If others are interested in this I can simplify it a bit more and help do some setup. I'll likely continue iterating on macros myself and continue pushing them up here.

I personally like this idea quite a bit. Managing the macros in code, and outside of the same repository/release schedule of the rest of the reef pi and UI seems like a nice setup.

I intentionally didn't include hysteresis, because I didn't want to implement something stateful. For that I'd need to keep it long-running, or store state in a data store.

I implemented it in Python because of the general usability of Python. I'm not sure if it's more confusing to have these macros in Python while the main code is Go. I find Python easier to use, particularly for people not super familiar with programming, but for this version I'm not sure it matters (I imagine mostly programmers would use this).

Temp Controlled Fan​

Automatically adjust the speed of fans in reef-pi based on a temperature reading. This uses the reef-pi api to control a reef-pi, whose information is stored in a config file.

This will automatically control a fan which is setup as a light within reef-pi. The fact that it's a light doesn't matter, it's just a hack because reef-pi doesn't have a general purpose power controller, so we pretend it's a 1-channel, manually controlled light.

For this to function the following settings must be done in the UI:

  • create one or more temperatures with their name prefixd with [RPExt][macro=TempFan]
  • the temperature must:
    • have its name start with [RPExt][macro=TempFan]
    • be enabled
    • be setup to control a macro as a chiller
    • have the chiller's temperature set to something
  • the macro that the temperature is attached to:
    • must have one or more "lights" attached to it (which are really fans)
    • should not be reversible, just to avoid reef-pi disabling it (doesn't really matter though)
The temperature will be adjusted based on: * fan speed 0 = temperature's cooler temp (temp["max"]) * fan speed 100 = speed 0 + the relevant fan_temp_max in the config (F or C)

While this script can be run anywhere that has access to the reef-pi, the safest setup is to run this from within the reef-pi device itself as a cron job. For that you just run with "hostname": "localhost" in the configs, and you'd likely run the cron job every minute.

Instructions:

Code:
# Retrieve the macros repo
$ git clone https://github.com/richievos/reef-pi-ext-macros.git
$ cd reef-pi-ext-macros

# Setup your machine for the macro scripts
$ pip install -r requirements.txt

# Setup your config file
$ cp config.json.example config.json
# EDIT config.json as appropriate

# Do a trial-run
$ python reefpi/tempcontrolledfancli.py --config-file=./config.json

# Run the scripts automatically with cron
$ crontab -e
# Your settings should look like:
* * * * * /home/pi/reef-pi-ext-macros/reefpi/tempcontrolledfancli.py  --config-file=/home/pi/reef-pi-ext-macros/reefpi/config.json
 
OP
OP
T

the register

Community Member
View Badges
Joined
Apr 16, 2009
Messages
50
Reaction score
47
Rating - 0%
0   0   0
Nice one !

I'll have a look at it. Would you mind if I used those Pi Base classes for another project for @Wolfw28 ?
I want to adjust his Pump controller through 2 GPIO pins based on a similar light control.
Feel free. I don't have a license file on there but you can assume it's BSD, do whatever you want with it but can't hold me accountable, license.

You're also welcome to submit a pull request if you want it in one place. At some point I'll publish it out as a proper python package, for easier use.
 

Creating a strong bulwark: Did you consider floor support for your reef tank?

  • I put a major focus on floor support.

    Votes: 56 40.6%
  • I put minimal focus on floor support.

    Votes: 29 21.0%
  • I put no focus on floor support.

    Votes: 48 34.8%
  • Other.

    Votes: 5 3.6%
Back
Top