Only trigger once a day using 'last triggered' state

Hi,
Newbie to HA and I think I’m missing the obvious. Can’t find what I need online so help would be greatly appreciated.

I’m trying to close our Somfy blinds at sunset+30 but not later than 23:00. I therefore created two triggers: one for sunset+30, one for 23:00.

I don’t want to run the automation twice though. E.g. in the winter when sunset is at 16:00, I want the automation to run at 16:30 (sunset+30). However, I don’t want to run the automation again at 23:00 since it’s possible that we manually opened the blinds at 18:00 because of strong winds and they then shouldn’t close again at 23:00. (my wind sensor is not coupled to my smart home… yet…)

I was thinking of using the ‘last triggered’ state and make sure the automation only runs once a day. However I cannot figure out how to check if the automation already ran “today”.

Here’s my code, currently without the condition in there:

- id: '###'
  alias: Close blinds (every day)
  description: Close the blinds 30 min after sunset on any day but not later than
    23:00
  trigger:
  - platform: sun
    event: sunset
    offset: '30'
  - platform: time
    at: '23:00'
  condition: []
  action:
  - device_id: ###
    domain: cover
    entity_id: cover.room
    type: set_position
    position: 0
  mode: single

I read about using a flow variable but understood this doesn’t “survive” a HA restart so I consider that a no-go. Any other ideas are more than welcome of course!

Thanks for your help :slight_smile:

This is similar to a question I once asked:

It’s been running for me, exactly as in the 3rd post, ever since.