2 google calendar questions

Hi

I have 3 different types of calendars in my google calendar. 1st is my rugby teams fixtures, School Holidays and parents holidays.

1st question. Before Coronavirus and league season was running and fixtures appeared. Since fixtures have now been removed, all I get is Unknown. Is there a way to get blank rather than unknown.
image

2nd question. My other calendar is telling me when the next school holidays are. Today was meant to be the 1st day since breakup but its still showing me the event. Should this not change to the next event after expirey of first date ?

image

Thank you in advance

Martyn

anyone know why or what I can do to get around it ?

Are you using a custom card to show those events?

The google calendar sensors states are simply ‘on’ or ‘off’ normally. It’s ‘on’ if the event is happening right now. Else, it’s off.

Otherwise, it has a bunch of attributes about the next events. And if there are no further events, there are no useful attributes (hence ‘unknown’)

The only way to change that would be to create a template sensor for each calendar and track that one in lovelace instead. But, you’ll have to manually copy all of the attributes yourself for each calendar. This will get quite annoying.

# Example configuration.yaml entry
sensor:
  - platform: template
    sensors:
      rugby_calendar:
        friendly_name: "Rugby Calendar"
        value_template: "{{ states('calendar.my_rugby_calendar')}}"
        attribute_templates:
          start_time: >
            {% set a = state_attr('calendar.my_rugby_calendar', 'start_time') %}
            {{ a if a != 'unknown' else "" }}
          end_time: >
            {% set a = state_attr('calendar.my_rugby_calendar', 'end_time') %}
            {{ a if a != 'unknown' else "" }}
          # And so on for all attributes

Or, just modify the integration to put in dummy values for those attributes if they don’t exist.

As for your 2nd one showing an old event, I’m not sure about that one. Have you not reboot HA since then? It’s possible the last event just gets stuck there, but it should be gone by next reboot I would think!

It would have been best if I put the code originally but here goes. I tried adding yours in at the end but it still says Unknown

- platform: template
  sensors:
    rhinos_next_game_countdown:
      friendly_name: Days to Go
      entity_id:
        - calendar.leeds_rugby
        - sensor.date_time
      value_template: >
        {% set daystogo = strptime(states.calendar.leeds_rugby.attributes.start_time, "%Y-%m-%d %H:%M:%S").strftime("%A") %}
        {% set daystogo2 = strptime(states.calendar.leeds_rugby.attributes.start_time, "%Y-%m-%d %H:%M:%S").strftime("%b %d, %Y") %}
        {% if as_timestamp(states.calendar.leeds_rugby.attributes.start_time) / 86400 - as_timestamp(as_timestamp(now()) | timestamp_custom("%Y-%m-%d 00:00:00",true)) / 86400 == 0.0 %}
        - TODAY -
        {% elif as_timestamp(states.calendar.leeds_rugby.attributes.start_time) / 86400 - as_timestamp(as_timestamp(now()) | timestamp_custom("%Y-%m-%d 00:00:00",true)) / 86400 == 1.0 %}
        TOMORROW
        {% elif as_timestamp(states.calendar.leeds_rugby.attributes.start_time) / 86400 - as_timestamp(as_timestamp(now()) | timestamp_custom("%Y-%m-%d 00:00:00",true)) / 86400 >= 7.0 %}
        {{ (as_timestamp(states.calendar.leeds_rugby.attributes.start_time) / 86400 - as_timestamp(now()) / 86400) | int  }} days
        {% elif as_timestamp(states.calendar.leeds_rugby.attributes.start_time) / 86400 - as_timestamp(as_timestamp(now()) | timestamp_custom("%Y-%m-%d 00:00:00",true)) / 86400 >= 2.0 %}
        {{ daystogo }}
        {% else %}
        {{ daystogo if daystogo != 'Unknown' else "" }}
        {% endif %}

Actually, it looks like a non existent attribute returns a None type.

Also, use state_attr(‘sensor’, ‘attribute’) so it doesn’t throw an error if the sensor doesn’t exist. Calendar integration might be slow to start.

      value_template: >
        {% start = state_attr('calendar.leeds_rugby', 'start_time') %}
        {% if start == None %}
          " "
        {% else %}
          {% set daystogo = strptime(start , "%Y-%m-%d %H:%M:%S").strftime("%A") %}
          {% set daystogo2 = strptime(start , "%Y-%m-%d %H:%M:%S").strftime("%b %d, %Y") %}
          {% set start_timestamp = as_timestamp(start) %}
          {% if start_timestamp  / 86400 - as_timestamp(as_timestamp(now()) | timestamp_custom("%Y-%m-%d 00:00:00",true)) / 86400 == 0.0 %}
            - TODAY -
          {% elif start_timestamp / 86400 - as_timestamp(as_timestamp(now()) | timestamp_custom("%Y-%m-%d 00:00:00",true)) / 86400 == 1.0 %}
            TOMORROW
          {% elif start_timestamp  / 86400 - as_timestamp(as_timestamp(now()) | timestamp_custom("%Y-%m-%d 00:00:00",true)) / 86400 >= 7.0 %}
           {{ start_timestamp  / 86400 - as_timestamp(now()) / 86400) | int  }} days
          {% else %}
            {{ daystogo }}
        {% endif %}

Or, if you want, just put this at the end.

{{ daystogo if daystogo != None else " " }}

Sorry my friend. It wont accept the start command.

No worries. if its not possible.