Sure, that would work.
Ok, thanks. I also read about the difference between offset and delay_on/delay_off. Offset fires the trigger later and for delay the event has still to be going at the point of the delay, otherwise it won’t work. I still don’t understand, why my solution didn’t work. Is there something wrong in the code?
The addition of an offset to a trigger fires it at a different time, but the Calendar event details are are part of the trigger. Whether or not that event is active in the calendar would make no difference.
I don’t think there’s anything “wrong” with it on its face. But, I don’t know if using a delay like that has an effect on the update of subsequent sensors configured in the same block…
You could try an experiment like:
Splitting the two sensors
- triggers:
- trigger: calendar
entity_id: 'calendar.my_calendar'
event: start
- trigger: calendar
entity_id: 'calendar.my_calendar'
event: end
actions:
- variables:
message: "{{ trigger.calendar_event.summary }}"
binary_sensor:
- name: Event 1
state: |
{% if message != "Event 1" %}
{{ this.state | default('off', true) }}
{% else %}
{{ 'on' if trigger.event == 'start' else 'off' }}
{% endif %}
delay_on:
hours: 8
delay_off:
hours: 8
- triggers:
- trigger: calendar
entity_id: 'calendar.my_calendar'
event: start
- trigger: calendar
entity_id: 'calendar.my_calendar'
event: end
actions:
- variables:
message: "{{ trigger.calendar_event.summary }}"
binary_sensor:
- name: Event 2
state: |
{% if message != "Event 2" %}
{{ this.state | default('off', true) }}
{% else %}
{{ 'on' if trigger.event == 'start' else 'off' }}
{% endif %}
delay_on:
hours: 8
delay_off:
hours: 8
It could also just be a quirk of all-day events… there have been weird issues with them in the past, but I thought those had been resolved.