All you guys with fitness trackers, smart watches or who are just interested in IoT may know the function to track daily personal water consumption through mobile apps or widgets on the wearable devices. There is just one problem: People are lazy and so am I 🙂 (For those of you who are too lazy to read, scroll down to the video showing the result)
Hence I would do it a couple of times, forget about it the other time and finally do not track it at all. So I thought this could be autmated…somehow.
After we moved to our new apartmenet, we also bought this new cool Siemens fridge with a water and ice dispenser.
In my old flat I used a Homematic inteface device (HM-PBI-4-FM) for a cross connection lamp wiring, which I do not need anymore. So I thought about divert this inteface from its intended use and measure the amount of tapped water by establishing a connection between the COM and one of the E1-E4 connectors. I did not want to mess around with the control unit of the fridge itself as it was quite new. Therefore, I decided to built a small box with a rotary switch which is connected to the lever and the back of the lever. The rotary switch provides 4 different states, so you could assign each of the Ex connectors to a person. Hence users could use a control knob to switch between the “profiles” and then tap water.
I will not deep dive into the details about wiring. If you have any questions feel free to leave a comment…
This is how the result looks like:
1) The Hardware
- Homematic interface (HM-PBI-4-FM)
- Control knob
- Some cables
- 2 small copper plates (or any other conductor plate)
- Rotary control switch (optimal with 5 states; depending on your use case)
- Varnish/Finish (optional)
- Hot-Melt gun
- Soldering station
This is how the prototype looked like. I used some copper plates to enlarge the conduction area. One will be connected to the back of the water dispenser lever and the other to the fridge itself. Pressing the lever would then establish a connection between these two plates.
I decided to keep things clean and exchanged the cables with proper colored ones. Also I connected the inner pins all together as I need only one connection to all of them.
I decided to paint it silver as it may harmonize better with the fridge finishing.
Heat bonded the switch.
These are the control knobs I ordered…the arrived late as they were shipped from China. Now I have some for future projects 😉
As mentioned previously, the components barely fit but they do.
The two cables on the top left were exchanged later by longer ones. These have the copper plates soldered at the and and installed to the lever
1) The Software
The software contains 2 scripts. One acts as a stopwatch saving the press duration in seconds. The other is executed on regular base (every 10 seconds for instance). It calculates the amount of tapped water based on the press duration, saves the value in “ml” and resets the press duration to “0.0”. You could also directly log the water intake with every singal received from the Homematic interface which would be more “real-time”. However, in respect to future functionalities such as sending the tapped water amount to Fitbit or leveraging other APIs, I decided to go with the 2 step approach and avoid invoking API calls 4 times in a second.
You will find some hard coded variables in the scripts which are representing the personal profiles, i.e. personal variables assigned to the different channels of the Homematic inteface (it would be better to use classes though). You may also recognize that channel 1 is “dead”. I did not wire it up so someone decides to tap ice instead of water, this channel can be used.
The Symcon screenshot shows the additional variables and how the scripts are triggered.
The stopwatch is triggered whenever the Homematic variable “PRESS_CONT” is updated.
$variableIdPressDuration = IPS_GetObjectIDByName("PressDuration", IPS_GetParent($_IPS['VARIABLE']));
$currentPressDuration = GetValue($variableIdPressDuration);
$newPressDuration = $currentPressDuration + 0.25; //Script executes 4 times in a second
This script checks if the press duration of any channel is changed and if so, it aggregates the tapped amount of water. Here you also see that I tried something with Fitbit already …
$variableIdsToWatch = array(55049,10899,23624);
$variableIdsPressDuration = array(16728,17454,27802);
$variableIdsWaterConsumption = array(58828,50621,27734);
foreach($variableIdsToWatch as $key=>$value)
#0.25s results in ~ 5.58ml
$pressContinuousDetails = IPS_GetVariable($value);
$pressContinuousLastUpdate = $pressContinuousDetails['VariableUpdated'];
$pressDuration = GetValue($variableIdsPressDuration[$key]);
$currentWaterConsumption = GetValue($variableIdsWaterConsumption[$key]);
if($pressContinuousLastUpdate == time())
//echo "last update equals time now";
IPS_LogMessage("WaterManagement", "No Action required: last update equals time now");
elseif($pressContinuousLastUpdate != time() && $pressDuration != 0)
$amountOfTappedWater = $pressDuration * 22.72;
IPS_LogMessage("WaterManagement", "pressContLastUpdate was done earlier and current press Duration has not been managed yet. PressDuration is: ".$pressDuration);
IPS_LogMessage("WaterManagement", "Water tapped: ".$amountOfTappedWater."ml");
$waterParameters['date'] = date("Y-m-d"); //needed for Fitbit API, for instance
$waterParameters['amount'] = $amountOfTappedWater; //needed for Fitbit API, for instance
#logWater($waterParameters); // Fitbit API call
$newWaterConsumption = $currentWaterConsumption + $amountOfTappedWater;
IPS_LogMessage("WaterManagement", "Resetting PressDuration to 0 ");
That’s it. Bye!