Completely new. I’m trying to set up an automation For a pump for my Greenhouse, which works fine in Home Assistant. Numerous failed attempts to automate my first automation, I’m hoping someone can help.
I want the pump to run five minutes every hour if over 10°C.
10 minutes if over 20°C
15 minutes is over 30°C
20 minutes over 40°C
(I have a temp and humidity sensor fully working in HA in the greenhouse)
I’d like this automation to only be available during daylight hours
And it definitely has to turn off ideally with some extra failsafes in place otherwise i’ll flood the greenhouse.
Any kind helpers? If it can be done in the normal UI way rather than code which, I have not done yet.
triggers:
- trigger: time_pattern # at 5 seconds past the hour, every hour
hours: "*"
minutes: 0
seconds: 5
conditions:
- condition: sun # only during daylight, you can add offsets if needed.
after: sunrise
before: sunset
- condition: numeric_state # only if above 10°
entity_id: sensor.greenhouse_temperature
above: 10
actions:
- action: input_number.set_value # store the minutes the timer should be on
target:
entity_id: input_number.watering_on_time # you have to create this helper first
data:
value: >
{% set temp = states('sensor.greenhouse_temperature')|float(0) %}
{% if temp > 40 %}
20
{% elif temp > 30 %}
15
{% elif temp > 20 %}
10
{% else %}
5
{% endif %}
- action: switch.turn_on
target:
entity_id: switch.greenhouse_irrigartion
Off automation:
triggers:
- trigger: state
entity_id: switch.greenhouse_irrigartion
to: 'on'
for:
minutes: "{{ states('input_number.watering_on_time') }}"
actions:
- action: switch.turn_off
target:
entity_id: switch.greenhouse_irrigartion
And a failsafe automation:
triggers:
- trigger: state
entity_id: switch.greenhouse_irrigartion
to: 'on'
for:
minutes: 21
actions:
- action: switch.turn_off
target:
entity_id: switch.greenhouse_irrigartion
- action: notify.your_phone
data:
message: "The irrigation ran over time. Please check the system."
Thank you so much. When I posted the question yesterday, I had no idea I would get any answer but to receive an answer the same evening is great and I am really appreciative
I haven’t quite got it to work yet, but I’m working on it now and I will get back to you.
Not ideal if your HA restarts often, as this gets terminated while waiting in that case.
An alternative solution is to have one automation that turns the pump on (if the temp is above 10), then an automation that runs at 10 minutes after the hour and turns the pump off if the temp is below 30, a third at 15 minutes that turns it off if the temp is below 40, and so on. That’s more resilient to restarts, especially because all the later ones for higher temps will also turn the pump off, so even if the right one is missed, 5 minutes later the next one will do the job. (Hint: Add an extra unconditional one 5 minutes after the last.)
Those also can be combined into one automation with 5 timed triggers. For that, you need to assign names to the triggers (“…”-menu on the trigger), then you can have a CHOOSE block based on which of the triggers fired. However, the only advantage is to have it all in one automation, which also is a negative as it becomes harder to read. I usually just put mine into separate automations and then group them in their own category.
Thank you very much for taking the time to help me. I really appreciate it. I am still working on the first solution provided. As I’m still working on that I tried your solution but, when I select ‘fan’ and try to select something there is nothing there to select. lol. I’m still learning I guess.
Many thanks again for helping me. I really appreciate it. I took on board what you said and made the necessary corrections. But it seems to be something about a visual editor and YAML? At this days stage of my journey, I have no idea what it’s all about. lol.
Hi Tom. Just wondering if you could possibly help me again. If you look at my screenshots I think the problem is where I’m putting the code? For some reason, the on routine isn’t working. Definitely something small I’m not doing right But my complete lack of experience is preventing me from knowing what’s wrong. Many thanks in advance of any help.
I’m putting the ‘code’ in the wrong place I’m sure.
It says visual editor not supported or, something.
I have no idea what I’m doing really. Although I have managed to do automations for lights, which were much more simple. Any help from anybody would be so much appreciated, but please treat me like an idiot because I didn’t seem to have the same basic understanding as everyone else. I am older guy in my 50’s
triggers:
trigger: time_pattern # at 5 seconds past the hour, every hour
hours: “*”
minutes: 0
seconds: 5
conditions:
condition: sun # only during daylight, you can add offsets if needed.
after: sunrise
before: sunset
condition: numeric_state # only if above 10°
entity_id: sensor.greenhouse_temperature
above: 10
actions:
action: input_number.set_value # store the minutes the timer should be on
target:
entity_id: input_number.watering_on_time # you have to create this helper first
data:
value: >
{% set temp = states(‘sensor.greenhouse_temperature’)|float(0) %}
{% if temp > 40 %}
20
{% elif temp > 30 %}
15
{% elif temp > 20 %}
10
{% else %}
5
{% endif %}