I am working on developing the code for my first project - A Smart Washing Machine Conroller that does the following:
Has a moisture sensor
Has two solenoid valves to shutoff the water to the machine should moisture be detected (these are fail safe valves so they are normally closed)
has a relay to enable the box to control power to the washer (Power will be normally ON)
An induction sensor to determine if power is flowing to the washer to turn on water when needed
The project is based on a Arduino Uno. The Arduino code is a snap. This is my first time doing anything in Groovy / SmartThings IDE. My Arduino sends back a string formatted like so (This is from a simple test I am running to display the voltage drop across a circuit, I measure the voltage using one of the analog inputs and then either send an OK signal or the actual voltage if it is beyond some tolerance):
In my Smart Things device Type, I thought it would be simple to just parse that into a map, but it proved much more challenging than I believed. Here is what I came up with that finally worked:
Hard to provide feedback. If it works, it works. Nothing really that could be optimized too much here.
Code is like art, if you want to you can pick apart every brush stroke, but the reality is, you just have to take a step back, enjoy the hard work of another and appreciate the fact that you can see the finished piece.
There are different ways one could have tackled this, but yours works just fine. Code optimization is an art, finding ways to refactor code to use less memory, execute faster, etc. are almost pointless with Smartthings, cause we have no visibility on code execution time, resources used, etc. So no benchmarks, means no ability to test change effectiveness.
Most of it I am building myself (Unarchiving my old soldering skills, LOL). I will post some design documents as soon as I get them finalized and everything working. For the store-bought subassemblies here is what I am using:
2 ea Valves - ROB-10456 from SparkFun
1 ea Current Sensor - SEN-11005 also from SparkFun
The moisture sensor I am building myself, basically just the ends of two RCA plugs in a housing I milled out of a block of plastic with my Dremel. Current to one side, a resistor and voltage read to one of the Analog ports on the Arduino. I haven’t determined yet if I am going to trip the alarm based on an analog or a digital readout from the pin. It will depend on some field testing and calibration once I get the breadboard prototype built. It will depend on how much noise there is when doing the Analog read on the Arduino. I have already noticed that it is quite noisy - its always reading something with just the probe in air - up to 2.5-3 volts sometimes. I will have to look at that again once its connected to household current and see about setting or managing the reference voltage on those pins.
Right now I am working on building the power supply assembly. I have completed the LCD assembly (The device will have a 16x2 LCD on the front to display status messages in case ST is inaccessible, and logic to override the system) and my prototype board enough that I can start rough cutting the controller and device handler programs. The rest of my parts should be in this week.
I’ve had back luck with water shut-off solenoids. The plastic case would crack or the valve would stick over time. Hopefully, they’ve improved them since my attempts years ago.
For a whole house shut off valve I use the FortrezZ ball valve. It is real expensive but I couldn’t find a good alternative to handle my hard water well.
The same company that makes this valve also makes some pretty nice brass versions. I can always upgrade to those later if I need to. For this project since theres a small space and two valves a servo actuated project like the FortrezZ was just too clunky. I need something more compact.
When I get around to doing my whole house shutoff valve, I will look at something like that.