Switching a lamp only between two dates

Can anyone help me with switching a lamp only between two dates. With the UI I made two helpers Datum1 and datum2.
I the UI in the automations I made the following:

alias: 11.2 testperiode 10:15 19-12/20-12
description: 11.2 testperiode 10:15 19-12/20-12
triggers:

  • trigger: time
    at: “10:15:00”
    conditions:
  • condition: time
    after: input_datetime.datum_1
    before: input_datetime.datum_2
    actions:
  • action: delay “{{ range(2,15)| random }} minutes”
  • action: light.toggle
    target:
    entity_id: light.on_off_plug_1_2
    data: {}
  • action: notify.mobile_app_ipctmp13
    data:
    title: Test Bericht
    message: 11.2 testperiode 10:15 19-12/20-12
    mode: single

It doesn’t work. Even on the 18th the automation was activated when it wasn’t supposed to be. Furthermore, the intention was to delay the start of the lamp from 2 to 15 minutes with the statement “Random”.

Thank you in advance for your efforts.

Please post the code again, correctly formatted this time. Use the </> button or surround with backticks like this:

```
CODE GOES HERE
```

The time condition doesn’t do dates. You need to use a local calendar or a template:

conditions:
  - "{{ now().day in (19,20) and now().month == 12 }}"

This topic might help.

1 Like

Maybe it is my whacky way of doing things, but I also found that it seems to work better if the datetimes being compared are converted to longs before the comparison. It shouldn’t be but this may be the case with datetime arithmetic as well (?)

Sorry I am not so well with it all.
Thanks for the remarks.

No need to apologise. With the way the forum formats text, it destroys the indentation and quotes so we can’t see potential errors in the code.