Creating an automation based on 'home precipitation' being less than x for xx hours - not working

Hi, I am trying to create an automation using the HA visual editor (not YAML) and it all seems straight forward, but unfortunately it doesn’t work as I have set it up, so I must be doing something wrong. I used Create new automation > Entity > Numeric state to start the automation off.

Any help much appreciated. All the topics I looked at seemed to be discussing coding and YAML files, not the simple UI.

This is how I have set it up:
When:
Entity = Home Precipitation
Attribute = left blank
Above mode = left blank
Below mode = Fixed number = 5
Value template = left blank
For = 5hh: 00mm : 00ss

This is the YAML that HA has created based on the above:

trigger:
  - platform: numeric_state
    entity_id:
      - sensor.home_precipitation
    for:
      hours: 5
      minutes: 0
      seconds: 0
    below: 5
condition:
  - condition: sun
    after: sunset
    after_offset: "00:30:00"

Based on those inputs, the automation has never triggered.

My goal is to get a sprinkler to turn on if there has been less than say 5mm of rain for 24 hours or similar. Home precipitation in my dashboard shows that there has been 0.0mm/h of rain for two days.

Your automation triggers when precipitation goes from above 5mm to below 5mm. If it’s already below 5mm when the automation starts running, it won’t trigger.

A trigger is an event, not a condition.

I see - thank you! Though I don’t quite understand how an event could last a duration. I had thought the idea of it being ‘for’ a length of time (i.e., below 5 for hh:mm:ss) was designed to create a condition.

What should I be using to create a condition?

Thanks.

You might try having the automation trigger every time the state of the sensor changes, then you could put the 5mm etc in the condition section. There’s some thoughts about this is the Home Assistant Cookbook:

Most of the time, you want the trigger to be the event closest in time to the actions you want to perform. In this case that would be a Sun trigger.

The wording is a little confusing… The state’s value would need to cross the threshold from above 5 to below 5, and stay that way for the defined duration. If it had been set up at the time, your trigger would have fired a few times on the 15th but would not fire again until it had rained then stopped raining.

Triggers and conditions don’t query the history of the entity. You’ll need to set up a Statistics helper to get a rolling sum of precipitation of the last 24 hours. That sensor is what you would use as a condition in you automation.

Thanks very much for your help Didgeridrew and jackjourneyman. I have managed to set it up using the sum calculation under statistics, which seems to be working, although I’m unclear if sum is the best option. Is there a way of finding out how often the sample is taken? If it is sampling every minute, then of course, it will get above 15mm rain quite quickly on a rainy day. If it is sampling every hour, then 15mm could be the right number. I have left sampling size empty and put max age at 24hrs, but have read that “it’s not a clear science…sensors update at a constant rate or event-driven based on external influences…” so not quite sure what’s best.

Many thanks.