Shutters not down

I want my shutters down at sunset (+offset), for wich I created a sensor, but at last at a certain time (helper).

So I created this automatisation

alias: Rolluiken 's avonds neer
description: ''
trigger:
  - platform: time
    at: sensor.rolluik_avond
  - platform: time
    at: input_datetime.tijdstip_rolluik_avond
condition:
  - condition: template
    value_template: '{{ now() <=  today_at(states(''input_datetime.tijdstip_rolluik_avond'')) }}'
  - condition: template
    value_template: '{{ now() <= states(''sensor.rolluik_avond'') | as_datetime }}'
action:
  - service: script.rolluiken_automatisch_neer
mode: single

I presume it’s a problem of miliseconds, but don’t know how to fix it…

Unless the sensor and helper has the exact same time then it will only trigger at the later of the two since both is in the condition like that (assuming the <= should actually be >=)

why not use the condition:

          - condition: sun
            before: sunset
            before_offset: "1:00:00"

I believe that is the sensors value if I understood it correctly.

I’m not sure I understand the conditions at all.
The way I see it the have no use.
Do they?
It’s time triggered, so what’s the condition for?

Sorry, I meant the trigger:

  trigger:
    - platform: sun
      event: sunset
      offset: "-01:00:00"

This is my sensor :

  - name: 'Rolluik avond'
    unique_id: 'sensor_rolluik_avond'
    state: >
      {{ state_attr('sun.sun', 'next_setting') | as_datetime + timedelta(minutes = states('input_number.offset_rolluik_avond')|int(0)) }}
    device_class: timestamp

Changed a little (add 1 minute), so I hope it will go down this evening…

alias: Rolluiken 's avonds neer
description: ''
trigger:
  - platform: time
    at: sensor.rolluik_avond
  - platform: time
    at: input_datetime.tijdstip_rolluik_avond
condition:
  - condition: template
    value_template: >-
      {{ now() <=  today_at(states('input_datetime.tijdstip_rolluik_avond')) +
      timedelta(minutes=1) }}
  - condition: template
    value_template: >-
      {{ now() <= states('sensor.rolluik_avond') | as_datetime +
      timedelta(minutes=1) }}
action:
  - service: script.rolluiken_automatisch_neer
mode: single

Schermafbeelding 2022-01-21 075832
Schermafbeelding 2022-01-21 075846

So I suppose shutters will go down at 17:24:59
In summer, when sunset is at f.e. 22:40 the shutters should go down at 22:00

I still don’t see a reason for the conditions.

What is the difference between:

alias: Rolluiken 's avonds neer
description: ''
trigger:
  - platform: time
    at: sensor.rolluik_avond
  - platform: time
    at: input_datetime.tijdstip_rolluik_avond
condition:
  - condition: template
    value_template: >-
      {{ now() <=  today_at(states('input_datetime.tijdstip_rolluik_avond')) +
      timedelta(minutes=1) }}
  - condition: template
    value_template: >-
      {{ now() <= states('sensor.rolluik_avond') | as_datetime +
      timedelta(minutes=1) }}
action:
  - service: script.rolluiken_automatisch_neer
mode: single

and this:

alias: Rolluiken 's avonds neer
description: ''
trigger:
  - platform: time
    at: sensor.rolluik_avond
  - platform: time
    at: input_datetime.tijdstip_rolluik_avond
condition: []
action:
  - service: script.rolluiken_automatisch_neer
mode: single

Both will trigger at both times, and both will close the shutters at whatever time is the first.
So what is the condition for?

True, but with the conditions it will only occurs on time (at: sensor.rolluik_avond OR at: input_datetime.tijdstip_rolluik_avond) not twice…correct ?

Conditions are AND not OR.
So both conditions has to be true in order for the automation to trigger.

Since Now() has to be less than your variable then it could be that your trigger wont happen because you made it complicated for no reason.

Say Now is 20:00, sensor is 17:00 and input_datetime is 22:00.
That means the sensor is less than Now thus condition will fail.

What is the reason for the conditions? What are they supposed to do?

In your example the shutters are already down at 17:00 (is less than 17:01 and les than 22:01).

I want my shutters down at sensor time but at last at input_datetime (22:00).

Not if HA is restarted at 16:59. This makes the 17:00 fail, and the 22:00 fail because Now() is larger than sensor.

Yes… I know… But explain the purpose of the conditions.
Unless the example above they will always evaluate to true so you might as well replace the conditions with {{ true }} because it’s the same thing.

If I do not place these conditions, the trigger will hit twice…and I would like to avoid that.

Why ?
If my sensor is 17:00 and my input_datetime 22:00, then my shutters go down at 17:00 (both conditions are true).
But at 22:00 the first condition is false (not less than 17:01)

That is true.
But I would rather have an input boolean that is set to true when down, then reset the boolean at midnight or if an automation is used to roll them up again.

Yes, that’s true. I will think about it.

Thanks !

@Hellis81

Just fyi and to confirm that the solution without a boolean works fine, so I took the same solution for the shutters to go up.

Worked fine, until today…the reason is that both triggers went off on within a time span of a some seconds :joy:

So I will add this, so the automatisation runs only once (I took 12 hours between) :

  - condition: template
    value_template: >-
      {{ ( as_timestamp(now()) -
      as_timestamp(state_attr('automation.1642230056582',
      'last_triggered')) |int(0) ) > 43200 }}

Is there another way to do this (I found this solution in another topic), cause now I have to search that ID… ?