Close courtains based on sensor illuminance and time

Hi everybody,
This is my first post, and not sure if it is the right place to post :slight_smile:

Im trying to automate a simple thing… but to be honest, not sure how to do it.
The idea is pretty simple, I’d like to close the curtain, if the illuminance is below 50, and after 20:00.

I did the following,

trigger:
  - platform: numeric_state
    entity_id:
      - sensor.lightsensor_illuminance
    below: 50
    for:
      hours: 0
      minutes: 2
      seconds: 0
condition:
  - condition: time
    after: "20:00:00"
    weekday:
      - sun
      - mon
      - tue
      - wed
      - thu
      - fri
      - sat
    before: "22:00:00"
action:
.....

And set the mode to restart so, if the illuminance condition trigger, but it is not the time, will reload again.
The problem is that the automation never triggers. Probably Im missing something obvious but I dont know what can be.

Any guidance is appreciated.

Restart mode is only for when the automation is triggered while it is still doing something. But this runs very shortly, so the restart mode does not do much.

Two things you need to realise:

  1. triggers only fire when what it checks goes from false to true. That is the only time it starts the automation
    2.if you have other conditions that also need to be true, those also need a trigger.

This is all explained here, read it well because it applies to pretty much any automation you’ll write:

So you need to add a trigger for the start of the time period (20:00) in case illuminance is already low at that time. You’ll need to add a condition too, to check the illuminance at the start time. If you want, you can also add a condition for the start of home assistant.

You’ll also need to fight the urge to put in a time trigger: you don’t need it. The automation is only supposed to run when the moment comes to close the curtain: either at 20:00 when it is dark, or at the exact moment when it turns dark after 20:00. If it is already dark, and it is already after 20:00, and the curtain is still open, there probably was a reason why you chose to open it anyway, after the automation had closed it.

Hi Edwin,

Thanks for your support! I was imagine something like that.
I’ll read carefully the post you mentioned.

Thanks again!

1 Like