|
|
automation success Tuesday, May 14 2024
During the night, Gretchen and I were awaken by the squealing of some little animal being tortured by the cats. I sprung out of bed and found Lester holding some fat varmint in his mouth. The other day the cats managed to just about kill a big fat vole (who probably didn't survive), but I got the poor little guy away from them before he was completely dead and put him under the doghouse to hopefully recover. I assumed this was another vole, though I was too bleary-eyed to look closely. I put the critter outside in front of the house and latched the pet door so nobody could come or go. This morning when I went out through that door, I found that the animal was still there: cold, stiff, and lifeless. He or she was a baby rabbit, which Clarence was infamous for killing back when he was alive. The bunny had a small patch of torn skin from which some blood had escaped, but otherwise there were no obvious injuries. I tossed him or her into the bushes and tried not to think too much about the fragility of life.
Later this morning, I noticed the upstairs bathroom door had blown shut, and that as the motive I needed to finally do something about it. I countersunk a large perforated circular rare-earth magnet into the top of the door furthest from the hinges and then installed another perforated circular magnet on a screw suspended down from the top of a hallway door frame so that the two magnets would be very near each other when the bathroom door was wide open. Because the two magnets were identical, I couldn't take advantage of the countersink for that second magnet, since doing so would cause the magnets to repel each other when brought near one another. I had to flip it over and use the non-countersunk side for the screw head. So I added a washer on the end of the magnet to carry the magnetism a bit closer to the other magnet on closest approach. This system worked as intended, though a very strong wind could still cause the bathroom door to slam shut.
Sometimes Gretchen seems to think I am misprioritizing my chores, and this was definitely the case as I built the thing I just described. She was trying to do her morning stretching exercises while listening to some public radio news podcast, and she didn't like that I was using a powertool nearby. She asked how the garden was coming as a way to shame me into beginning the process of planting all the seedlings she'd bought over the weekend.
So while Gretchen was taking Charlotte on her morning walk, I changed into shorts and a teeshirt (the day was pretty warm) and began working on the garden. I'd already tilled some of the weeds under in the raised beds nearest the house, but more needed to be done. When Gretchen returned from her walk, she dove right in to help me. At some point in all this, I stepped on an old pine pole I'd used to support a tomato plant and one of the side-branches poked me painfully in the sole of my right foot about an inch from the beginning of the littlest toe on that foot. The side branch had been so sharp that I'd initially thought it was a metal nail or a thorn, but it was just a branch; evidently when the weaker wood rots away, the remaining core is very hard and extremely sharp.
With every passing year, Gretchen seems to increasingly want to solve our bad luck with gardening by throwing money at the problem. This season, she'd bought a bunch of commercially-produced compost in plastic bags, and she'd read somewhere that a certain amount was needed. It looked to me like she'd bought plenty, especially considering the kitchen compost, cat litter, and dog shit we also add to the garden. But no, she was sure we didn't have enough based on something she'd read and her misremembering how many raised beds we have (she'd thought we had four, but we actually have six). I wanted her to be happy with whatever we did, so we only ended up fully-preparing and planting in four of the six beds. We also spaced the plants very far apart (she's long been frustrated by how close together I plant things).
A couple weeks ago, I'd planted some sunflower seeds on the north side of all the raised beds, but nothing ever came of that (it seems a lot of seeds being sold at grocery and big box starts are well-past their sell-by date). But not to worry, among the many plants Gretchen had bought this weekend were sunflowers. There were two or three in each segment of the black plastic planter tray, all with their roots hopelessly entangled, and I feared that separating them would be as difficult as successfully cleaving apart siamese twins joined at the brain. But keeping them together like that wasn't going to be good for either of them. So I separated them as best a I could, a process that felt a bit rough and traumatizing for the helpless seedlings. But they seemed perfectly healthy afterwards, even after several hours in the sun.
With all that out of the way, I could focus on a big goal I'd set for myself: building an automation system into the remote-control system I've built for the cabin. A necessary prerequisite was finishing the generic system for making many-to-many connections between tables in a MySQL database, something I finally got working late this morning. Next I had to figure out how the "conditions" would work for turning a device_feature on or off. I had a column called "conditions" that was of type text. But what would those conditions look like? I am very much the sort of person who thinks (and even designs) while doing, so it was unusual in this case that the whole design for the way conditions would work fell into place as I was writing the comments in the PHP code before doing any actual coding. I decided that the conditions would each be based on a "token" that would fetch a value from somewhere in the database. I'd then compare that value with some hard-coded value to produce a true or a false, and if the answer was true, then that would send a pre-set value (usually 1 or 0) to the device_feature, resulting in the turning on or off of a relay. The only thing left to figure out in this design was the syntax of the token. I decided to use a vaguely-XML-inspired syntax. A token would take this form: <table_name[location_id].column_name/>. My code would look for XML tags in the conditions and then parse out the table names, location_ids, and column names, do a SQL query to get a value, and then replace the whole token with the value. So if conditions contained this:
<weather_log[1].temperature_value> > 0
my code would look up the latest record with a location_id of 1 (outdoor temperatures at the cabin), take the temperature_value (stored in celsius), and, through the miracles of str_replace, produce a string like so:
22 > 0
It would then perform a PHP eval on that, and, if it turns out to be true (which in this case it isn't), set the device_feature to whatever was in the result_value of the management_rule record. Getting all this working required a lot of nested loops and if statements, but after coding for an hour or so, it worked after only a modest amount of debugging. It worked so well that I left automation for one device_feature (the west basement outlet at the cabin) in place while I took the dogs for a walk atop the escarpment west of the Farm Road. That wasn't a great idea, because when I next checked the data from the cabin, I saw that all the device_features were off but that something was using about 1.5 kw of power. It was a strange enough scenario that I actually looked at the cabin's surveillance camera to see if someone had come there and plugged in an aluminum smelter. But then I figured out that somewhere in the complexity of the data.php file that the ESP8266s repeatedly poll, the value and last_known_device_value weren't being correctly set, which allowed a controlled circuit to stay on without the system being any the wiser, a fact that could only be confirmed by the rate of electricity consumption. I tinkered with the code well into the evening, staying up past midnight trying to figure out what was going on (but not wanting to leave the code in a state that would overconsume electricity overnight). By then I was working under a crippling mental handicap: a 150 mg dose of diphenhydramine. I disabled the new automation code and went to bed.
The code containing the comments where I figured out how conditions tokens would work.
A small (and usually curvy) black rat snake on top of the big evaporator of the minisplit I installed back in January, photographed today from the east deck. Click to enlarge.
For linking purposes this article's URL is: http://asecular.com/blog.php?240514 feedback previous | next |