Automation: open shutter when stop raining - what am I doing wrong?

Hi Home Assistant community

I am trying to add an automation where the shutter should open once the rain is stopping. I managed a simple automation which works once rain rate is below a certain value. However, as rain is usually coming in waves, I wanted to add a delay of 30min before opening the shutters so they do not go up and down multiple times.
The following automation however is not working at all.
Anyone in here able to spot the error in the automation or has an idea how to add such a delay?

id: '1654028831267'
alias: open shutter when stop raining (if <1mm)
description: ''
trigger:
  - platform: numeric_state
    entity_id: sensor.pws_precip_rate
    for:
      hours: 0
      minutes: 30
      seconds: 0
    attribute: ''
    below: '1'
condition:
  - condition: sun
    before: sunset
    before_offset: '3000'
    after: sunrise
action:
  - device_id: 6a2c6eefe5a9007af2988228bdb56b10
    domain: cover
    entity_id: cover.wohnzimmer_rolladen_rechts_shutterbox_position
    type: set_position
    position: 98
  - device_id: 5e40e1695db7fdbbc79ba744e90b31d7
    domain: cover
    entity_id: cover.rolladen_wohnzimmer_links_shutterbox_position
    type: set_position
    position: 98

You tagged your post with “Share your Projects!” which is reserved for sharing working projects you have created. In this situation the automation you posted doesn’t work and you’re asking for help to fix it. Change the post’s category to “Configuration”.

The value for before_offset is usually expressed in the following format HH:MM:SS like 01:15:00 but you have supplied it with a single integer value 3000. What is the amount of offset that you want?

In addition, I don’t believe you can combine before: sunset and after: sunrise in the same Sun Condition.

to me
look like your condition is wrong

the before_offset should be a time format

Assuming you want an offset of 50 minutes, try this version:

id: '1654028831267'
alias: open shutter when stop raining (if <1mm)
description: ''
trigger:
  - platform: numeric_state
    entity_id: sensor.pws_precip_rate
    below: 1
    for:
      minutes: 30
condition:
  condition: or
  conditions:
    - condition: sun
      after: sunrise
    - condition: sun
      before: sunset
      before_offset: '00:50:00'
action:
  - device_id: 6a2c6eefe5a9007af2988228bdb56b10
    domain: cover
    entity_id: cover.wohnzimmer_rolladen_rechts_shutterbox_position
    type: set_position
    position: 98
  - device_id: 5e40e1695db7fdbbc79ba744e90b31d7
    domain: cover
    entity_id: cover.rolladen_wohnzimmer_links_shutterbox_position
    type: set_position
    position: 98

Thank you all for your inputs!
Not sure how to change from “share your projects” to “configurations”, but I will figure it out and change it - thank you for the hint.
Regarding the several comments about the “before_offset” I doubt that this is the problem, as I am using the same condition in my automation to close the shutters when precipitation rate is >1mm. In the following you can see this automation, which is working fine. Note that the sunrise / sunset condition is set because an other automation is closing the shutters during night (after sunset with an offset of 50min (=3000s)) and opens the shutters after sunrise (with no offset). The rain automations shall work during daylight only, as during night the shutters are closed anyway and should not open if rain stops:

id: '1654240862464'
alias: close to 10% if Rain above 1mm
description: ''
trigger:
  - platform: numeric_state
    entity_id: sensor.pws_precip_rate
    above: '1'
condition:
  - condition: sun
    before: sunset
    after: sunrise
    before_offset: '3000'
action:
  - device_id: 5e40e1695db7fdbbc79ba744e90b31d7
    domain: cover
    entity_id: cover.rolladen_wohnzimmer_links_shutterbox_position
    type: set_position
    position: 12
  - device_id: 6a2c6eefe5a9007af2988228bdb56b10
    domain: cover
    entity_id: cover.wohnzimmer_rolladen_rechts_shutterbox_position
    type: set_position
    position: 12
mode: single

→ shutters react to rain only during daylight and close the shutters if rain is above 1mm. This automation works fine.
→ Only difference to the previously posted automation to open the shutters when rain is below 1mm is the delay of 30min.
→ main reason having this delay of 30min is to avoid opening / closing the shutters multiple times if rain is toggling between higher / less than 1mm of precipitation rate. However, not sure if the delay will even solve this. Ideally the open shutter when <1mm automation shall be reset if during the delay of 30min the rain rate raises again over 1mm.

Meanwhile I could solve the issue! The only thing I change to make it work was to edit the code in YAML so that the code “for: minutes: 30” is at the end of the trigger code!!
This is the corrected code:

platform: numeric_state
entity_id: sensor.pws_precip_rate
below: "1"
for:
  hours: 0
  minutes: 30
  seconds: 0

This was the wrong code as written by the visual editor:

platform: numeric_state
entity_id: sensor.pws_precip_rate
for:
  hours: 0
  minutes: 30
  seconds: 0
below: "1"

Looks like a bug in the visual editor…
@123Tara: you were indicating the correct solution in your example already but I did not see it! So thank you for that!

You’re welcome!

Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has been resolved. This helps users find answers to similar questions.

For more information refer to guideline 21 in the FAQ.


It’s not a bug. The order of a trigger’s options doesn’t matter. The for option can even be placed before the platform option and it will still work correctly. The YAML code representing the trigger is converted into JSON and as long as it contains all of the desired data, regardless of sort order, it will function properly.

:face_with_monocle: if the position of the “for” option does not matter, then it is still unclear why the automation did not work before…that was the only thing I have changed (plus removed attribute: ’ ').

This is the final, working automation:

id: '1654028831267'
alias: open when stop raining if rain rate is <1mm
description: ''
trigger:
  - platform: numeric_state
    entity_id: sensor.pws_precip_rate
    below: '1'
    for:
      hours: 0
      minutes: 30
      seconds: 0
condition:
  - condition: sun
    before: sunset
    before_offset: '3000'
    after: sunrise
action:
  - device_id: 6a2c6eefe5a9007af2988228bdb56b10
    domain: cover
    entity_id: cover.wohnzimmer_rolladen_rechts_shutterbox_position
    type: set_position
    position: 100
  - device_id: 5a44aeea8f17f389dc4fe0ca721202d1
    domain: cover
    entity_id: cover.rolladen_wohnzimmer_links_shutterbox_position_2
    type: set_position
    position: 100
mode: restart

Something you did during your testing procedure led to a false-negative result. Because, as explained, option order doesn’t influence how the trigger is handled. I have seen examples where options were sorted alphabetically and the trigger worked properly.

I verified your statement and set the “for” option back to the previous position. It got triggered this morning - whatever was wrong before, the automation works and therefore I am happy :slight_smile: