This project relies upon you having a RaspberryPi Zero running a Domoticz home automation server (quite easily made) with Node-Red and is setup as a MQTT Broker.
OverviewMy fish tank controller was my first project I had made after learning basic Arduino IDE and ESP8266 programming, the fishtank was the first I built and installed after this I setup my home automation system along with some temperature sensors and other things so as natural progression I have integrated this into my Domoticz System and moved away from solely using an android app.
User friendly drop down box control:
Additionally I also have the feedback that is displayed within Domoticz:
The domoticz home automation system uses MQTT topics 'domoticz/in' and 'domoticz/out', the 'in' topic is for sending to the domoticz system the 'out' is outgoing information from it. So when the control switch is changed the below JSON message is sent out ;
{ "Battery" : 255, "LevelActions" : "|||||||", "LevelNames" : "Off|Lights Off|Lights On|Bubbles Off|Bubbles On|Filter Off|Filter On|Time Check", "LevelOffHidden" : "true", "RSSI" : 12, "SelectorStyle" : "1", "description" : "", "dtype" : "Light/Switch", "id" : "00014071", "idx" : 33, "name" : "FishTank Control", "nvalue" : 2, "stype" : "Selector Switch", "svalue1" : "30", "switchType" : "Selector", "unit" : 1 }
This contains far too much info so I use Node-Red to shorten this, as described below in more detail. Once converted I send the reduced JSON message out on the original 'home/fishtank/control' topic.
Software changesFirstly:I had to modify the program for the ESP12 via Arduino IDE to receive the Domoticz specific payloads, previously the ESP12 expected payloads of 1 thru 7 the Domoticz switch object sends payloads in increments of tens so the program was simply changed to expect 10 thru 70.
Secondly:The ESP12 needed changing so it could parse JSON messages, so I had to add arduinojson.h library, as described below:
Within the MQTT callback function (when a message is received), the message is placed inside a buffer (inData) to which the arduinojson.h library ultimately interrogates and parses the objects and values into their respective parts for use within the program.
In this example the key information I receive is the idx and the svalue1. The idx is the individual device id from my Home Automation System this makes sure the ESP12 control is working to the correct device. The svalue1 is the selector value to tell the ESP12 what to do.
From this we can see providing idx 33 is received we then read the svalue1 and operate the fish tank to corresponding control state. At the same the controller provides feedback that it has received the control, this feedback is a simple numeric string sent back for the Node-Red software to convert.
Thirdly:Setup Domoticz, this is relatively easy, once a switch point was added, I needed to go into the setup and change the selector values to correspond with the fishtank controller itself:
Setup the Node-Red as a middle man, due to the large size of the Domoticz messages and also I forgot about the feedback points to rather modifying the ESP12 program I added some flows to my Node-Red.
The Selector switch flow mainly removes switch un-necessary object from the original JSON message from the home automation system.
The feedback flow converts the numeric strings into description text strings which it passes to the home automation system.
I appreciate this step could be engineered out, I might do one day!!
TestTurn on the Bubbles (aerator):
Comments
Please log in or sign up to comment.