hacs_waste_collection_schedule icon indicating copy to clipboard operation
hacs_waste_collection_schedule copied to clipboard

Help with correct active reminders (sensor is on too late ...)

Open rubenkr opened this issue 2 years ago • 0 comments

Hi community,

i have a minor error I am unable to figure it out on my own. I have setup a calendar which works fine. Following sensor is created in home-assistant with

date all_day: true
start_time: 2022-07-06 00:00:00
end_time: 2022-07-07 00:00:00


However the sensor of this type of waste turns on at 01:00 AM in the night. Here is the config for the sensor:

    gruenetonne:
      friendly_name: 'Gruene Tonne'
      icon_template: >
        {% if is_state('binary_sensor.gruenetonne', 'on') %}
          mdi:delete-alert
        {% else %}
          mdi:delete-outline
        {% endif %}
      # sensors need their entities declared, so they can watch them
      # using sensor.date_time (or sensor.time) makes it update every minute
      entity_id:
        - sensor.date_time
        - calendar.gruenetonne
      # ON 7 hours (25200s) before all_day event = 17:00 the day before, and OFF at 17:00 on the day,
      # or 1 hour (3600s) before normal event (Problemmüll)
      # CAREFUL: Binary sensors need true/false as input, NOT UI niceties like on/off or the like!
      value_template: >-
        {% set calendar = 'calendar.gruenetonne' %}
        {# Adapt these for your needs #}
        {% set seconds_before_all_day = 3600 %}
        {% set seconds_before_end_all_day = 3600 %}
        {% set seconds_before_single = 3600 %}
        {% set start = state_attr(calendar,'start_time') %}
        {# Prevent error when no calendar event (we won't have a start_time then) #}
        {% if start != None %}
          {% set _now = now().timestamp() %}
          {% set start = as_timestamp(start) %}
          {% set end = as_timestamp(state_attr(calendar,'end_time')) %}
          {% if _now < end %}
            {% if state_attr(calendar,'all_day') %}
              {{ _now < end - seconds_before_end_all_day and start - _now < seconds_before_all_day }}
            {% else %}
              {{ start - _now < seconds_before_single }}
            {% endif %}
          {% else %}
            false
          {% endif %}
        {% else %}
          false
        {% endif %}

Could someone tell me how I can get a sensor ON at 16:00 PM before the event and OFF already at 11 AM in the morning? Thank you very much!

rubenkr avatar Jul 06 '22 08:07 rubenkr