Getting calendar to display an event

I’m still very much a newbie at all this and am trying to get a card to display the current google calendar event. After working through various iterations of other’s YAML on the forum, and several days of fiddling which came down to needing to rename the calendar so that the device_id didn’t start with a number, I’ve ended up with an entry in my configuration.yaml which reads:

sensor:
  - platform: metoffice
    api_key: "redacted"
    monitored_conditions:
      - weather
      - temperature
      - feels_like_temperature
      - wind_speed
      - wind_direction
      - wind_gust
      - visibility
      - visibility_distance
      - uv
      - precipitation
      - humidity
  - platform: template
    sensors:
      value_template: {{ states.calendar.homecal.attributes.message }}
      friendly_name: "Next Event"

If I run the built in configuration checker, I get the following error message:

Testing configuration at /config
2018-01-19 19:56:14 ERROR (SyncWorker_0) [homeassistant.util.yaml] invalid key: “OrderedDict([(‘states.calendar.homecal.attributes.message’, None)])”
in “/config/configuration.yaml”, line 194, column 0
2018-01-19 19:56:14 ERROR (MainThread) [homeassistant.bootstrap] Error loading /config/configuration.yaml: invalid key: “OrderedDict([(‘states.calendar.homecal.attributes.message’, None)])”
in “/config/configuration.yaml”, line 194, column 0

Line 194 is the value_template line. If I reboot my Pi with this in the file, the interface won’t reappear and I have to remove the entire platform…entry and reboot via SSH. The entry for the weather sensors works fine and I’ve assumed from what I’ve learnt so far that I need to keep all the sensors together which is why I’ve added calendar entry below the weather one.

The entry {{ states.calendar.homecal.attributes.message }} gives me the relevant result in the template builder under the developer tools which leads me to believe that there is something wonky with how I’m defining the sensor.

What am I doing wrong?

Put single quotes around the template.

Thanks. I think I’ve tried every combination of single and double quotes but have given it another go. The line now reads:

  - platform: template
    sensors:
      value_template: {{ 'states.calendar.homecal.attributes.message' }}
      friendly_name: "Next Event"

Error code:

Testing configuration at /config
2018-01-19 20:40:36 ERROR (SyncWorker_0) [homeassistant.util.yaml] invalid key: “OrderedDict([(‘states.calendar.homecal.attributes.message’, None)])”
in “/config/configuration.yaml”, line 194, column 0
2018-01-19 20:40:36 ERROR (MainThread) [homeassistant.bootstrap] Error loading /config/configuration.yaml: invalid key: “OrderedDict([(‘states.calendar.homecal.attributes.message’, None)])”
in “/config/configuration.yaml”, line 194, column 0

If I put them outside the {{

  - platform: template
    sensors:
      value_template: '{{ states.calendar.homecal.attributes.message }}'
      friendly_name: "Next Event"

I get:

Failed config
sensor.template:
platform: template
sensors: [source /config/configuration.yaml:193]
friendly_name: Next Event
value_template: {{ states.calendar.homecal.attributes.message }}

Successful config (partial)
sensor.template:

If I try double quotes:

  - platform: template
    sensors:
      value_template: {{ "states.calendar.homecal.attributes.message" }}
      friendly_name: "Next Event"

I get:

Testing configuration at /config
2018-01-19 20:44:26 ERROR (SyncWorker_0) [homeassistant.util.yaml] invalid key: “OrderedDict([(‘states.calendar.homecal.attributes.message’, None)])”
in “/config/configuration.yaml”, line 194, column 0
2018-01-19 20:44:26 ERROR (MainThread) [homeassistant.bootstrap] Error loading /config/configuration.yaml: invalid key: “OrderedDict([(‘states.calendar.homecal.attributes.message’, None)])”
in “/config/configuration.yaml”, line 194, column 0

Outside the brackets.

Also from that error message, looks like you have sensor.template: in your config, should be sensor:

Ignore that bit, I misread the error message.

Put the quotes outside the brackets and save the file then run homeassistant and post the error message, will be more informative than the config checker.

#
#  Event Calendar Sensors
#
#
- platform: template
  sensors:
    event_title:
      friendly_name: 'Next Event'
      value_template: "{{ states.calendar.xxxxxxxgmailcom.attributes.message }}"

This is what I have in mine, tho’ mine only shows the all day events for some reason I can’t work out.

Seems to be something to do with the weather :stuck_out_tongue: since thats the all day event

1 Like

So it seems I can’t have tried every permutation of quotes after all! Putting the quotes outside the brackets and reinstating the event_title: seems to have done it. Thanks!

Would you mind showing your finished code, please and thank you? :slight_smile:

1 Like

Sure. It’s mostly the same as that posted by keithh666:

- platform: template
    sensors:
      event_title:
        value_template: "{{ states.calendar.homecal.attributes.message }}"
        friendly_name: "Next Event"
1 Like

awesome, thank you :slight_smile: I was able to reproduce the effects of the output.

One thing I"m having trouble with now, though; I’m trying to use a search term on one of the sensors, in order to populate an input selector. Specifically, I have information like “Kid1 #laundry, Kid2 #laundry, Kid3 #laundry” in the calendar as daily items. then, in the Google_Calendars.Yaml, I have the following:

  - device_id: laundry
    name: Laundry Calendar
    search: "#laundry"
    track: true

According to the documentation, the #laundry should be removed when the system parses the message information. My end result is actually the full message with the hashtag included.

- alias: Laundry Day
  trigger:
  - platform: state
    entity_id: calendar.laundry
    from: 'off'
    to: 'on'
  action:
  - service: input_select.select_option
    entity_id: input_select.laundry_day
    data_template:
      option: "{{ states.calendar.laundry.attributes.message }}"

This gives me Kid2 #Laundry, which of course doesn’t match the entries I have in the select list. (Of course, I’d also be happy just outputting the information without using the pick list, but I’m doing this all one step at a time, while learning the process).

Any suggestions?

2 Likes

Exactly the same issue: search and offset do not get removed from message.

I have managed to do it with a template like this:
{{ state_attr('calendar.test', 'message') | regex_replace('(#\S+)') }}

However, the issue remains about standard message attribute not working correctly.