How I automated my aquarium, and how YOU can too! (using sonoff and HomeAssistant)
It’s been a while, hasn’t it?
While the updates may have been slacking, I sure haven’t slacked in the “home-automation departement”. Home Assistant is still my go-to when I want to start automating anything! That being said, over the past year I have been keeping fish & shrimp (yes, shrimp) which sometimes require a lot of manual activity. Know that a lot of aquariums need a set light cycle and some other even require much more than that! In my case I use CO2 which is used as part of the plant fertilization. Finally, for me it is also important to be able to monitor my aquarium form anywhere in the world. When I’m on holiday, I am able to help my “fish-sit” (babysit) with turning on/off every single piece of electrical equipment when they need it.
Obviously, this serves just as an example. If you want your HomeAssistant to turn on your coffee machine after your alarm clock goes off, you can also get inspiration here!
If you have watched the video above, I hope you start to get an understanding on how I tackled things. A lot of the components used are an application of the previous videos I posted with regards to sonoff, homeassistant, …
If you are interested in building something similar, I suggest you check out below resources and code/configuration examples!
- For flashing your sonoff, I have two instructional videos: 1 and 2 (click on the numbers)
- I use sonoff Tasmota firmware
- I don’t have any examples of DIY arduino applications. If you are reading this in the future, maybe I have some but for now I suggest the following link and some healthy dose of google.
- In my case I used a NodeMCU, a DHT22 sensor and a DS18b20 sensor (waterproof)
- In HomeAssistant I configured the different components and used some custom automations to make everything work together.
- I use MQTT as my “data hub”.
- Check down below for the code examples!
With this write-up I hope to have peaked your interest in automation as a whole. In case you have further questions, feel free to get in touch with me by any means possible (comments in this post, comments on my youtube video or via my mail)
Thanks for reading!
For those interested in the code examples, please find the general lay-out below:
Setting up the general requirements: I use MQTT sensors to display the values and the lights are turned on via MQTT (the Sonoff Tasmota Firmware allows for this):
input_boolean:
aquarium_light_cycle:
name: Automatically cycle the aquarium light
initial: on
icon: mdi:ceiling-light
sensor:
- platform: mqtt
state_topic: "aquarium/sensor/temperature"
name: Aquarium Ambient Temperature
unit_of_measurement: "°C"
- platform: mqtt
state_topic: "aquarium/sensor/humidity"
name: Aquarium Ambient Humidity
unit_of_measurement: "%"
light:
- platform: mqtt
name: "Juwel Main Light"
icon: mdi:lightbulb-outline
state_topic: "stat/JuwelAquaPlus/POWER2"
command_topic: "cmnd/JuwelAquaPlus/POWER2"
qos: 1
payload_on: "ON"
payload_off: "OFF"
retain: true
- platform: mqtt
name: "Juwel Night Light"
icon: mdi:theme-light-dark
state_topic: "stat/JuwelAquaPlus/POWER3"
command_topic: "cmnd/JuwelAquaPlus/POWER3"
qos: 1
payload_on: "ON"
payload_off: "OFF"
retain: true
We have some sliders to control the light cycle:
input_number:
aquarium_light_on:
name: Main Light On
icon: mdi:timer
initial: 14
min: 0
max: 23
step: 1
aquarium_light_off:
name: Main Light Off
icon: mdi:timer
initial: 22
min: 0
max: 23
step: 1
And finally the (far from optimal?) automations!
- alias: Aquarium Light on action
initial_state: true
hide_entity: true
trigger:
platform: time
hours: /1
condition:
- condition: state
entity_id: input_boolean.aquarium_light_cycle
state: 'on'
- condition: state
entity_id: light.juwel_main_light
state: 'off'
- condition: template
value_template: '{{ (now().strftime("%s") | int | timestamp_custom("%H")) | int
== states.input_number.aquarium_light_on.state | int }}'
action:
- service: light.turn_on
entity_id: light.juwel_main_light
- alias: Aquarium Light off action
initial_state: true
hide_entity: true
trigger:
platform: time
hours: /1
condition:
- condition: state
entity_id: input_boolean.aquarium_light_cycle
state: 'on'
- condition: state
entity_id: light.juwel_main_light
state: 'on'
- condition: template
value_template: '{{ (now().strftime("%s") | int | timestamp_custom("%H")) | int
== states.input_number.aquarium_light_off.state | int }}'
action:
- service: light.turn_off
entity_id: light.juwel_main_light
