So recently, we’ve seen a new trend develop of budget consumer grade peristaltic pump / auto-doser products introduced on the market that sport WiFi and Mobile App control technology. Whether your into Hydroponics or Aquarium applications for your auto-dosers, or perhaps some other application entirely, these new products may seem rather attractive. However, some of us may also have invested substantially in previous generation technology, that still performs quite nicely and reliably, just without all the elegant graces of Mobile App technology and/or possibility to integrate into a centralised automated controller like Home Assistant.
Myself, I am in the later camp in that I have TWO 4 channel peristaltic pump devices from the aquarium vendor AquaMedic. I just looked them up on the web, and they are still available today from said manufacture and cost up to 400 Euros or more. My first one is now over 12 years old, although I had to replace the stepper motors eventually around 4-5 years of use, I discovered I can replace these individually myself for about 15 Euros. And I did that again, not long ago and the motors are still fine at this time. But I’ve longed for centralised control of both my Reefdosers for a long time, and certainly wanted a far, far, far more elegant and intuitive interface.
Now if you’ve already read my thread on heading off to use Home Assistant as a dedicated Coral Reef Aquarium Controller for my 10 tanks here --> ( https://community.home-assistant.io/t/going-to-next-level-of-aquarium-automation-whos-with-me/ ) You’ll know that I’m already invested heavily in my Home Assistant setup, which employs ESP32s, ESP8266s and Sonoff devices. With that knowledge in hand, I decided to do something this last week about my AutoDosers. And this is what I came up with.
I started off with two 4-Channel Sonoff devices; one for each doser. My AquaMedic Reefdosers’ stepper motors are 220V AC so using the base 4-Channel Sonoff device was my preference for costs. I believe this solution should also be applicable to pumps that run on DC as well, perhaps using the 4-Channel PRO Sonoff version, but I’ve not yet the opportunity to try that as I have no DC based doser.
BTW - if you do this yourself, all standard SAFETY / WARNING / ACHTUNG disclaimers of working with 110/220V AC power mains apply. PLEASE do not flash your Sonoff devices with the Power Mains connected - you may melt your computer and may fry yourself.
First you need to remove the cover of the Sonoff 4CH device and flash your Sonoff with the appropriate TASMOTA Firmware. Detailing the instructions of how to Flash your firmware is a bit beyond this instructional, but you can find all the info you need on how to do this, along with the firmware itself, here:
Do pay attention to setting all the declared variables under ‘user_config.h’ or your results may vary a bit. And one thing I will draw your attention to is this specific line of ‘user_config.h’ which I recommend to set to as POWER_ALL_OFF, because you probably do not want your AutoDosers to immediately turn on after a power blackout / power outage:
#define APP_POWERON_STATE POWER_ALL_OFF // [PowerOnState] Power On Relay state
// (POWER_ALL_OFF, POWER_ALL_ON, POWER_ALL_SAVED_TOGGLE, POWER_ALL_SAVED, POWER_ALL_ALWAYS_ON, POWER_ALL_OFF_PULSETIME_ON)
You’ll also want to ensure you have all the core network connectivity and MQTT configuration already pre-set so you don’t have to deal with any of that after you’ve flashed it - it should just work.
After flashing your firmware, you should be able to connect to your Sonoff 4CH to check to see that in basic principle it all functions, and you can activate each channel individually. Double check all your pre-configured settings, and adjust if necessary.
BTW, realistically - if all you wanted was a WiFi programmable upgrade for your Autodoser, software wise, you’re effectively done at this point. There’s a scheduling component in this firmware that will allow you to program up to 16 individual events! That’s not what the objective of this upgrade is, but just saying it’s there if you want it.
All that remains is to install the hardware & setup Home Assistant now.
The case design of the AquaMedics is pretty cool in that it’s very modular and seemed to be a perfect candidate for this modification. But I’ll come back to how cool that is, later.
For now, I decided to start off with leaving the original Microcontroller in place and just wiring the Sonoff into the doser just by-passing the previous controller all together.
BTW, In Europe, Blue is Neutral and Brown is the LIVE wire. (Blue is the colour of life giving water, brown is the colour of the earth they cover you with when you die. Don’t touch the brown wire. )
Again - ensure both your Autodoser and your Sonoff are not plugged into the power mains before going any further than this. This is your final warning.
Now the main AC input comes from the far right (that upper right most white electrical block is where it comes in at, and it routes over to the lower-most left GREEN terminal block on the PCB. That is the brown wire that must go in the left most hole in the central orange terminal block of the Sonoff.
Then place that paired blue wire in the first left-most hole of the GREY terminal block of the Sonoff device.
Now, the remaining 4 upper terminal blocks of your Reefdoser should still have blue and brown wires still attached also. These are the 220V switchable AC Feeds that go to the stepper motors of the AutoDoser. On the PCB they are labelled CH1, CH2, CH3, and CH4. Starting with CH1 repeat the same steps of transferring these wires to the Sonoff in the same steps described above. Brown wire goes in the next available hole in the ORANGE terminal block of the Sonoff device and the matched BLUE wire from that pair should go to the next available GREY Terminal Block of the Sonoff device. Proceed in sequence with the same procedure for CH2 and then CH3 and finally CH4.
At the end, you should have something like this:
If you’ve done everything properly, congratulations, you just gave your Doser a Brain Transplant.
Another cool thing about this upgrade you may have just realised - there’s no reason you cannot reverse the process just described to “back out” of this upgrade at a later date, should. you choose too. You can quite literally restore the autodosers original factory state, if you decide to sell them or send them in for service, etc.
Just saying…
Additionally - and this is the cool thing about the case of the AquaMedic Reefdosers - you can even decide to completely remove the entire original Microcontroller, put it in a box and reduce the width of your upgraded AutoDoser, and still even later “back out” of this upgrade and removal of the modular micro controller and rebuild it to it’s original state.
Originally, I left it for about 4 days, before deciding to finally remove it.
I carefully attached the Sonoff to the remains condensed housing with two threaded screws after carefully measuring out and tapping some new screw holes in the plastic casing. I never hang my AquaMedic losers on the wall, so the modified “backpack configuration” works for me, but if you have your’s mounted via the back of the doser, you’ll have to find some other solution for mounting your Sonoff to your Autodoser.
Once you have it all wired together and snapped all safely away behind the protect housings, go ahead and plug it in and toggle those pumps on and off for about 5 minutes via your mobile phone or computer. Isn’t that already pretty cool?
If you made it this far, congratulations, now all you should have to do is setup Home Assistant. And below is all the YAML CODE I wrote specifically for these AutoDosers, so I’ve done all the hardworking for you.
BTW, since this implementation is based on MQTT as the communication protocol, this HA code should work for any kind of Peristaltic Pump designed for measuring out fluids - not just the AquaMedic. You’ll just need to tweak the values for how much it pumps within a given timeframe. For the AquaMedic Reefdosers, it’s 0.41666667 ml per second.
Also - although my implementation is for a 4 x Pump doser, I’m only going to copy and paste the necessary code for controlling a single pump. All you have to do is copy and paste and modify to reflect the names (and numbers) of your device pumps and channels you want to control. (In otherwords, for a Sonoff 4CH controller, you’ll need to duplicate the entries created under SWITCH, INPUT_BOOLEAN, SENSOR, INPUT_SELECT, INPUT_NUMBERS, and AUTOMATIONs for every pump you want to control. In my case with two Reefdosers upgraded with two Sonoffs I also had to duplicate the entry for the second Sonoff / Reefdoser under DEVICE_TRACKER below.
customize_glob.yaml:
"input_boolean.r2d*":
icon: mdi:calendar-clock
"input_boolean.r1d*":
icon: mdi:calendar-clock
"sensor.reefdoser*_pump*_daily_runtime":
icon: mdi:history
"sensor.reefdoser*_pump*_dosage_split":
icon: mdi:beaker
"sensor.reefdoser*_pump*_time_split":
icon: mdi:history
"input_number.reefdoser*_pump*_daily_mins":
icon: mdi:clock
"input_select.reefdoser*_pump*_daily_freq":
icon: mdi:progress-clock
switch:
- platform: mqtt
name: "Reefdoser1 Pump1"
state_topic: "homeassistant/stat/Reefdoser1/POWER1"
command_topic: "homeassistant/cmnd/Reefdoser1/POWER1"
qos: 1
payload_on: "ON"
payload_off: "OFF"
retain: True
input_boolean:
r1d1:
name: R1D1 Automatic Mode
sensor:
- platform: template
sensors:
# Reefdosers ONLINE status sensors
reefdoser1:
value_template: '{% if is_state("device_tracker.reefdoser1", "home") %}Online{% else %}OFFLINE{% endif %}'
friendly_name: 'Reefdoser1 Status'
icon_template: >-
{% if is_state('device_tracker.reefdoser1', 'home') %}
mdi:power-plug
{% else %}
mdi:power-plug-off
{% endif %}
# Reefdoser1 Runtime sensors
reefdoser1_pump1_daily_runtime:
value_template: "{{ (float(states('input_number.reefdoser1_pump1_daily_dosage')) / 0.4166666666667 ) | round(2) }}"
friendly_name: 'R1D1 Total Dosing Time'
unit_of_measurement: 'sec'
reefdoser1_pump1_dosage_split:
value_template: "{{ (float( states('input_number.reefdoser1_pump1_daily_dosage')) / float(states('input_select.reefdoser1_pump1_daily_freq'))) | round(2) }} "
friendly_name: 'R1D1 Individual Dosage Amount'
unit_of_measurement: 'ml'
reefdoser1_pump1_time_split:
value_template: "{{ (float(states('sensor.reefdoser1_pump1_daily_runtime')) / float(states('input_select.reefdoser1_pump1_daily_freq'))) | round(2) }}"
friendly_name: 'R1D1 Individual Dosing Time'
unit_of_measurement: 'sec'
device_tracker:
- platform: ping
home_interval: 10
hosts:
reefdoser1: 192.168.1.50
input_numbers.yaml:
reefdoser1_pump1_daily_dosage:
name: Daily Dosage
min: 1
max: 500
step: 1
unit_of_measurement: ml
icon: mdi:beaker
# initial: 30
reefdoser1_pump1_daily_mins:
name: Dosing Start Minute
min: 00
max: 59
step: 1
mode: box
# initial: 00
unit_of_measurement: mins
input_selects.yaml:
reefdoser1_pump1_daily_freq:
name: Daily Dosing Frequency
options:
- "1"
- "2"
- "3"
- "4"
- "6"
- "8"
- "12"
- "24"
icon: mdi:target
automations.yaml:
# Reefdoser1 Section
# R1D1 Subsection Automations
- alias: Reefdoser1 Pump1 at the specified frequency
trigger:
- platform: time
hours: '/1'
seconds: '00'
condition:
condition: and
conditions:
- condition: template
value_template: "{{ now().hour % ( 24 / float(states('input_select.reefdoser1_pump1_daily_freq')))|int == 0 }}"
- condition: template
value_template: "{% if now().minute | int == states.input_number.reefdoser1_pump1_daily_mins.state | int %}true{% endif %}"
- condition: state
entity_id: sensor.reefdoser1
state: 'Online'
- condition: state
entity_id: input_boolean.r1d1
state: 'on'
action:
- service: switch.turn_on
entity_id: switch.reefdoser1_pump1
- delay: '00:00:{{ states.sensor.reefdoser1_pump1_time_split.state | int }}'
- service: switch.turn_off
entity_id: switch.reefdoser1_pump1
groups.yaml:
aqua_view:
view: yes
name: AquaMedic Reefdosers
entities:
- group.r1d1
r1d1:
name: R1D1 - Calcium
control: hidden
entities:
- switch.reefdoser1_pump1
- input_boolean.r1d1
- input_number.reefdoser1_pump1_daily_mins
- input_select.reefdoser1_pump1_daily_freq
- input_number.reefdoser1_pump1_daily_dosage
- sensor.reefdoser1_pump1_dosage_split
- sensor.reefdoser1_pump1_daily_runtime
- sensor.reefdoser1_pump1_time_split
Now, if you’ve copy and pasted the above into your HA configuration and made the appropriate modifications correctly, you should be able to restart HA. And once it restarts, you should get something that looks a lot like the very top original screenshot (just depending on how many Pumps you actually setup).
If you like this and end up using it in your own solutions, please let us know! I’d really like to see how useful this becomes for others.
And of course, I hope you’ll share any improvements and or unique application ideas for this.
PS - A very special shout out to @pnbruckner who helped me yesterday realise a mistake and because of his brilliant direction helped me reduce the number of necessary automations per pump from EIGHT to a single ONE Automation rule. He rocks.