Sorry – couldn’t resist it. I saw a YouTube video yesterday where a guy was griping about LED STRIP and the rubbish adhesive on most of it – my thoughts exactly. He thoughly recommended 3M’s VHB foam tape (Very High Bond – that keeps making me laugh) – and he could not have timed it better.
I’ve just been updating my garden watering system to work with Home Assistant (more on that in a minute – Claude AI comes into this) and I’d been fitting new code to turn the watering on and off around dusk and dawn. I’ll explain in a minute but first – the tape – well, I was experimenting to see if my code was working and the way I do that without going into the garden is to go into the kitchen where my little smartplug-controlled 12v pump supply box sits on the wall.
The switch box itself is just a cheap smartplug and a little 12v supply powered by the plug which in turn used to be controlled by Node-Red – to turn on and off power to the pump. The pump is in a cupboard out of sight-and-mind so I fitted a 3-LED length of blue LED STRIP to the power unit so I could see at a glance when the pump was running. I did this years ago and when the lights didn’t come on yesterday after convincing myself that the code I was using was ok, I noticed two things, not only were the LEDs down to very low brightness due to age but were also dropping off the power unit due to adhesive failure.
I replaced the 3-LED strip and all was well, until this morning when I noted that already the adhesive was failing (the PSU gets warm when on). Thats not uncommon – I have LED strip all over and it often starts coming away at the edges quite quickly. Well, I’ve now fitted a short length of the 3M VHB tape to the box and mounted the tape on that. As I put it all together I noted I could not adjust the fit – that’s a GOOD thing – I’m hoping the adhesive will last and I’ll update this entry after a while to let you know how it does.
So, what brought all of this on? Well, a couple of days ago I turned off my Node-Red control in favour of this month’s rampant Home Assistant development – and then it hit me – I’d forgotten about the watering system – thankfully my wife is on the ball and has been checking the plants regularly and had noted they were dry.
My initial reaction was panic. The old system used node-red-contrib-bigtimer to give 2 on-off cycles a day, one at dusk, one at dawn to water the plants for a period dependant on the average humidity for the last 24 hours as detected by one of my pergola sensors (temperatuer/humidity) with an extra proviso that if the humidity averaged more than 80%, no watering would be needed (here in Spain that’s basically a short time in winter).
So now I was faced with, in Home Assistant, firstly averaging the humidity reading over 24 hours, then deciding how to tackle the actual watering. In for a penny, I thought that instead of one watering at each of dusk and dawn, I’d go for several waterings around those times – the reason being that when it’s very dry here, the plants need several minutes of watering – and our garden area and plant pots being what they are, more water ends up falling out of the bottom of the pots or dropping through the very shallow wall mounted “garden” – to feed the wasps, than remains for the plants.
Bear in mind at this point I had NO idea how I was going to do this – I have in total a few weeks experience of Home Assistant.
As it happens I just discovered claude.ai – a newly update AI agent that claims to outperform CHATGPT. I don’t trust any of them but I was desperate for a quick solution.
I asked claude first of all for a means to average outside humidity over 24 hours in Home Assistant – and it came up with a solution first time around.
I used the the HACS “average Sensor for Home Assistant… I grabbed it (a simple click) and added the following into my Home Assistant sensors.yaml file. It doesn’t get any easier than this..
- platform: average name: Average Outside Humidity duration: days: 1 entities: - sensor.new_aqara_humidity
The sensor referred to is one of my Aqara temperature/humidity sensors – one sitting in the shade under our pergola. So now, with no effort I had a new “entity” in HA called “Average Outside Humidity”.
In Home assistant In my sensors panel I simply created a “tile card” who’s “entity” was “Average Outside Humidity”. Hours later I could compare my normal sensor card which shows temperature and humidity from the same sensor – with this new one.
By example… here is the normal sensor card at 8pm tonight – humidity is quite low – but then it gets much higher overnight and the new entity is keeping track of the average.
So, here’s the “average” entity – you can see it is much higher in value than the instant value above left. To show the power of Home Assistant.
All very nice – but NO. The “average” humidity came out at the average for the day, not a rolling average for the last 24 hours. Having done my own averaging in Node-Red and used it successfully for years, thankfully I was able to write my own which I’ll share here. Thankfully I had cloned my Raspberry Pi (good old rpi-clone to the rescue) and so could eaily revert to before I started all of this. I decided to go with a simple array and started the ball rolling by adding 2 items into Home Assistant’s configuration.yaml file.
# attempt at 24 hour rolling average input_text: humidity_array: name: "Humidity Array" initial: "[30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30]" input_number: av_hum: name: "Average Humidity" min: 0 max: 100 step: 0.01
The humidity_array is simply a non-volatile array of 24 values which I chose to initialise at 30 for 30% rather than start with the impossible 0%.
I then proceeded to make a simple automation (Home Assistant – settings – automations). I tried using CLAUDE.AI for that and I have to say it took so many attempts – with so many apologies for producing code for an old vresion of Home Assistant, I ended up pretty much writing this myself. The automation runs every hour, checking the current value of the aqara humidity sensor. It then chops off the oldest value in the array, moves the other values left by one, adds the new value on the other end and finally stores the new average in an “entity” defined above called input_number.av_hum (my choice of name) which could then be used in a second automation.
alias: Hourly Humidity Collection and Average Calculation trigger: - platform: time_pattern hours: "*" action: - variables: current_humidity: "{{ states('sensor.new_aqara_humidity') | float }}" humidity_array: "{{ states('input_text.humidity_array') | from_json }}" - service: input_text.set_value target: entity_id: input_text.humidity_array data: value: "{{ (humidity_array[1:] + [current_humidity]) | to_json }}" - service: input_number.set_value target: entity_id: input_number.av_hum data: value: "{{ ((humidity_array[1:] + [current_humidity]) | sum / 24) | round(2) }}"
The only original AI-generated code lies in the last line above – I have no idea how to shift an array in YAML but it seems to work – easy in Javascript – I’m quite familiar with Javascript’s shift() and push().
The second automation makes use of the power controller I’m using which has Tasmota installed – and in which I’ve set to timeout after 1 minutes (failsafe in case the Raspberry Pi fails (which it never does) using Pulsetime 160 (60 seconds) (non-volatile).
alias: Watering Schedule Based on Humidity trigger: - platform: time_pattern minutes: /10 condition: - condition: and conditions: - condition: or conditions: - condition: and conditions: - condition: sun after: sunrise after_offset: "-01:00:00" - condition: sun before: sunrise before_offset: "01:00:00" - condition: and conditions: - condition: sun after: sunset after_offset: "-01:00:00" - condition: sun before: sunset before_offset: "01:00:00" - condition: numeric_state entity_id: input_number.av_hum below: 80 action: - service: switch.turn_on target: entity_id: switch.watering data: {} - variables: humidity: "{{ states('input_number.av_hum') | float }}" - choose: - conditions: - condition: numeric_state entity_id: input_number.av_hum below: 30 sequence: - delay: >- {{ '00:10:00' if humidity < 30 else '00:20:00' if humidity < 50 else '00:45:00' if humidity < 70 else '01:00:00' }}
Ok, This could probably have been a lot simpler but it works. I’m again showing the YAML here, this could easily be made with Home Assistant’s UI but I get a better feel for what is happening by looking at the YAML.
The second automation checks the time for one hour before dawn to one hour after dawn – same again for dusk. Depending on the average humidity, it gives the garden a number of 1-minute waterings.
Why all that? Well, as I said above, the use of a pump on-off controller kitted out with Tasmota means I’m not relying on Home Assistant on Raspberry Pi, with which I’m constantly experimenting, to turn the water OFF. Why a bunch of short bursts of watering? Because we have a wall garden and a load of plant pots – on my original sytem which did the watering in one go at dusk and dawn, I’m sure more water ended up falling down to the ground than remaining in the soil – and here in Southern Spain in 2024, not a good idea to waste water by soaking cement (which also attracts wasps etc) instead of feeding plants and bushes.
The above code it easy to use – if anyone’s interested – just remember to get the indenting right – something I hate about YAML. Back in the day when programming in C and variations, the semicolon was used for delimiting and braces for grouping – actual formatting was just a nicety. Not here.
Until I come up with something better – this works. The actual timing figures just came from experience – if I find they need adjustment later in the year, it’s a simple matter of going into that second automation and changing values accordingly.