Google calendar, show location, start and end time in sensor not working

I’ve recently setup google calendar and am having an issue getting the location, start and end time to show up in my group from the sensor. Here is what shows currently and my code. Am I doing the sensor attributes correctly? I wish there was some more info in the Google Calendar doc on HA.

sensor:
  family_calendar:
    friendly_name: 'Family'
    value_template: '{{ states.calendar.family.attributes.message }}' 
    location: true
    start_time: true
    end_time: true     

  holidays_calendar:
    friendly_name: 'Holidays'
    value_template: '{{ states.calendar.holidays.attributes.message }}' 
    location: true
    start_time: true
    end_time: true

You need template sensors for the other attributes. Just like you did with ‘message’, create sensors for the other attributes. I don’t have location set up, but here’s how I get the start, end and all day attributes:

#
#
#  Event Calendar Sensors
#
#
     event_title:
       friendly_name: 'Next Event'
       value_template: "{{ states.calendar.rpiteraphonegmailcom.attributes.message }}"

     event_description:
       friendly_name: 'Description'
       value_template: "{{ states.calendar.rpiteraphonegmailcom.attributes.description }}"

     event_allday:
       friendly_name: 'All Day?'
       value_template: "{{ states.calendar.rpiteraphonegmailcom.attributes.all_day }}"

     event_start:
       friendly_name: 'Event Time'
       value_template: "{{ states.calendar.rpiteraphonegmailcom.attributes.start_time }}"

     event_end:
       friendly_name: 'Event Time'
       value_template: "{{ states.calendar.rpiteraphonegmailcom.attributes.end_time }}"
3 Likes

Thank you so much @rpitera

Pleasure! Glad I could help.

@thechriswick would you mind sharing all your config for the google calendar setup? I have only made the first configuration and got the google_calendars.yaml file. Im to new with home assistant so i would like to see an example to get up and running like you did.

Outside of setting up your account and authenticating by following the instructions here:

You should be able to use the config example I posted to get the sensors to show up.

What part are you having issues with?

Sorry im such a newbie but have been tinkering around alot lately and starting to get a hang of how this works :wink:
so in general to get this to work you do:

in google_calendars.yaml you take the calndars device_id and replace DEVICE_ID with yours {{ states.calendar.DEVICE_ID.attributes.message }}

Example of sensors.yaml

- platform: template
  sensors:
    event_title_andreas:
      friendly_name: 'Nästa event'
      value_template: "{{ states.calendar.andreas_privat.attributes.message }}"
    
    event_description:
       friendly_name_andreas: 'Beskrivning'
       value_template: "{{ states.calendar.andreas_privat.attributes.description }}"

    event_allday:
       friendly_name_andreas: 'Hela dagen?'
       value_template: "{{ states.calendar.andreas_privat.attributes.all_day }}"

    event_start:
       friendly_name_andreas: 'Startar'
       value_template: "{{ states.calendar.andreas_privat.attributes.start_time }}"

    event_end:
       friendly_name_andreas: 'Slutar'
       value_template: "{{ states.calendar.andreas_privat.attributes.end_time }}"

Then in groups.yaml you put:

kalender:
  view: no
  name: Kalender
  entities:
    - sensor.event_title
    - sensor.event_description
    - sensor.event_allday
    - sensor.event_start
    - sensor.event_end

You will get a group called Kalender that you can use in your webpage like this also configured in groups.yaml

hem:
#default_view:
  name: Hem
  view: yes
  entities:
    - group.mediaspelare
    - group.lampor
    - group.sensorer
    - group.kalender

This will create a new top meny called Hem and inside that a box called Kalender will show you all info for the calender choosen.

I get one error though when starting up home assistant:
homeassistant.components.sensor.template: UndefinedError: ‘None’ has no attribute ‘attributes’
but it works…

1 Like

When making a sensor for a calendar that i subscribe to i get this error in the log file wonder what that is. the built in google calendar component that shows all calendars works.

homeassistant.components.sensor.template: SecurityError: access to attribute '_7a__1617' of 'DomainStates' object is unsafe.

I get the same undefined none error but my calendar works fine as well. @hanfelt

HA testing a sensor before it exists yet. It updates when the sensor gets initialized and can be ignored.

@ih8gates recommends wrapping the sensor in an if test like this will make it go away:

value_template: '{% if states.remote.livingroom.state %}{{ states.remote.livingroom.attributes.current_activity }}{% endif %}'

1 Like

Thanks! @rpitera

For some reason it’s showing end time “unknown” when I have an end time of 8pm.

I have switched the event to all day for testing, but HA still shows ALL Day as False,

How long does it take to update?

Edit: Found my answer.
“MIN_TIME_BETWEEN_UPDATES = timedelta(minutes=15)”

1 Like

Any idea why it displays
“End Time unknown”

Not sure as I don’t use it much but it could be the formatting.

Formatting where?

It could be that the value of the End Time is a string instead of an integer and the template is looking for an integer or vice versa. Again, just a guess.

Any idea how I can get the description text in the card to wrap down or show entirely?

Someone, Anyone?

1 Like

@Coolie1101 - I was curious about this as most of my descriptions are short so I edited one that was upcoming to see what happened and mine is wrapping fine:

But I’m not doing anything special with the template sensors or group so I’m not sure why yours isn’t wrapping properly.

I’m curious about something off topic… Do you see more than one event? I setup this component but I only see the next upcoming event and nothing else do you have this same behaviour?