I’ve got an automation to tell me to water my plants if the zigbee moisture sensors detect them drying out. The automation sends me a Telegram message.
To avoid multiple triggers at, say, <90%, <80% and <70% i wondered if I could set the below: to a list of values. I asked the question in Goole and this is what its AI thing said:-
Yes, you can configure Home Assistant automations to trigger when a value falls below a list of values using the numeric_state trigger and the below keyword with multiple values.
Here’s how you can achieve this:
Trigger: Use the numeric_state trigger platform and specify the entity_id of the sensor you want to monitor.
Below: Use the below keyword and list the values you want to trigger on. For instance, below: [10, 20, 30] will trigger if the value drops below 10, 20, or 30.
Actions: Define the actions you want to perform when the trigger condition is met.
You are not showing the whole automation, so your action is a mystery. Why do you care if the sensor.moisture_3_soil_moisture is below 90 or below 60? No matter what sensor.moisture_3_soil_moisture is, if it’s below 90, it triggers the action.
If the sensor is below 90, send a telegram with the sensor value.
The action is not the problem, but here is the full automation that does work (although I’ve not included the other 5 plants to keep it short)…
alias: Plants Watering
description: ""
triggers:
- trigger: numeric_state
entity_id:
- sensor.moisture_3_soil_moisture
below: 90
for:
hours: 0
minutes: 5
seconds: 0
id: anthurium
actions:
- choose:
- conditions:
- condition: trigger
id:
- anthurium
sequence:
- action: telegram_bot.send_message
metadata: {}
data:
message: >-
The Anthurium in the Dining Room needs watering. Moisture level
is reported as {{trigger.to_state.state}}%
title: Water Alert
I want it to do multiple triggers on each plant as I forget and need badgering!
When I try the above 2 examples, HA throws a wobbly saying “Error” or “Unknown trigger” and refuses to save.
I’d also like to able to cut the 6 chosen actions down to 1 by replacing the plant name and room with templates. The plant name I think I can do with {{trigger.id}} but I’ve not worked out how to get the Area.
If you don’t need full resolution, you could use some, admittedly kind of silly, math. Basically, round the value to the nearest multiple of 5 then trigger when that value changes from even (multiple of ten) to odd…
alias: Plants Watering
description: ""
triggers:
- id: anthurium
trigger: template
value_template: >-
{% set s_state = states('sensor.moisture_3_soil_moisture') | round(0, default=50) | int %}
{{ ((s_state //5)*5) is odd and 60 < s_state < 90 }}
for: "00:01:00"
conditions:
- alias: Check that value is decreasing
condition: template
value_template: "{{ trigger.to_state.state|float < trigger.from_state.state|float }}"
actions:
- choose:
- conditions:
- condition: trigger
id:
- anthurium
sequence:
- action: telegram_bot.send_message
metadata: {}
data:
message: >-
The Anthurium in the Dining Room needs watering. Moisture level
is reported as {{trigger.to_state.state}}%
title: Water Alert
My mistake. I just looked at the Automations documentation and see that those states are present for a Template trigger, as well as a State trigger. I just assumed they wouldn’t be. I’ll work on it.
I’ve settled on the following complete automation for my 6 plants with sensors. It should trigger all the way down to 9% in 10% intervals on any of the plants.
The message template, I’m sure could be simplified if i knew the right syntax for area_name(trigger.id). That might be it, but I haven’t tried it because it’s difficult to test without having the trigger go off naturally.
alias: Plants Watering
description: ""
triggers:
- trigger: template
value_template: >-
{% set s_state = states('sensor.moisture_1_soil_moisture') | round(0,
default=50) | int %} {{ (s_state //5) is odd and s_state < 90 }}
for: "00:01:00"
id: croton
- trigger: template
value_template: >-
{% set s_state = states('sensor.moisture_2_soil_moisture') | round(0,
default=50) | int %} {{ (s_state //5) is odd and s_state < 90 }}
for: "00:01:00"
id: dracaenna
- trigger: template
value_template: >-
{% set s_state = states('sensor.moisture_3_soil_moisture') | round(0,
default=50) | int %} {{ (s_state //5) is odd and s_state < 90 }}
for: "00:01:00"
id: anthurium
- trigger: template
value_template: >-
{% set s_state = states('sensor.moisture_4_soil_moisture') | round(0,
default=50) | int %} {{ (s_state //5) is odd and s_state < 90 }}
for: "00:01:00"
id: ficus
- trigger: template
value_template: >-
{% set s_state = states('sensor.moisture_5_soil_moisture') | round(0,
default=50) | int %} {{ (s_state //5) is odd and s_state < 90 }}
for: "00:01:00"
id: monstera
- trigger: template
value_template: >-
{% set s_state = states('sensor.moisture_dracaena_en_suite_soil_moisture')
| round(0, default=50) | int %} {{ (s_state //5) is odd and s_state < 90
}}
for: "00:01:00"
id: en-suite
conditions:
- condition: template
value_template: "{{ trigger.to_state.state|float < trigger.from_state.state|float }}"
actions:
- action: telegram_bot.send_message
metadata: {}
data:
message: >-
The {% if trigger.id != "en-suite" %}{{trigger.id}}{%else%}Draceana{%
endif %} in the {% if (trigger.id == "anthurium") or (trigger.id ==
"draceana") %}Dining Room {% elif (trigger.id == "croton") or
(trigger.id == "monstera") %}Lounge {% elif trigger_id == "en-suite"
%}En-Suite {% elif trigger.id == "ficus" %}Hall {% endif %} needs
watering. Moisture level is reported as {{trigger.to_state.state}}%
title: Water Alert
mode: single
I’ve just got wait now to see if it works. 2 of my plants are currently at 90% so it shouldn’t be long. They will trigger at 89%.
I never knew you could override the actual state of an entity. I just set one of the plants to 89 (was 90) and it triggered and i got the Telegram message
But if you edit the trigger name to name,plant then you can split the room and name and use them in the code.
Yes, that would work, but I’m a believer in just entering data once ie at the the Device level. I think I will start another thread on that specific issue.
Edit: Solved the area problem with area_name(trigger.entity_id) so the action part of the automation now looks like this…
actions:
- action: telegram_bot.send_message
metadata: {}
data:
message: >-
The {{ trigger.id }}in the {{area_name(trigger.entity_id)}} needs
watering. Moisture level is reported as {{trigger.to_state.state}}%
title: Water Alert
Note that I changed the trigger_id: of the dracaena in the en-suite to dracaena.