Help with Google Calendar Attributes and Show My Homework

Hi all, I’m based in the UK and trying to use the showmyhomework website along with the google calendar component so that I can announce when my son’s homework is due/what subject etc.

Problem is that the description attribute isn’t laid out in a very helpful way, and the message attribute has an annoying class name that doesn’t read out very well over a google home!

Is there anyway of extracting the information I may be interested in and excluding the other bits? Here is what is showing in my states attribute under calendar.smhw.calendar:

message: Karl *redacted* 08C2L/La German Homework
all_day: false
offset_reached: false
start_time: 2018-09-19 10:00:00
end_time: 2018-09-19 10:00:00
location: 
description:               German
          Class Name: 08C2L/La
          Homework Title: Year 8 German homework
          Set By: Mrs D. Rae
          Set On: Wed 12th Sep
          Due On: Wed 19th Sep
          View on *redacted* School's Homework Calendar
          https://www.showmyhomework.co.uk/redacted

friendly_name: SMHW Calendar

I’d probably want to use the homework title and due on date, and combine with a days until sensor which I am already able to set up.

This is an example of an automation that notifies when his homework has to be done within 16 hours:
Dates are hard to calculate, so its easier when converted to timestamps(Unix time, the number of seconds since 00:00:00 UTC on January 1, 1970)

 - alias: 'Work Notifications'
   trigger:
     platform: time
     minutes: /30
     seconds: 00
   condition:
     condition: and
     conditions:
   - condition: template
         value_template: '{% set start_date = as_timestamp(states.calendar.annoying_calendar_name.attributes.start_time) %}
                          {% set date = as_timestamp(now())  %}
                          {%set diff = start_date -date %}
                          {{ diff>57600 }}'  ### 16 hours in seconds, so should warn you at 6PM 
  action:
     service_template: notify.telegram
     data:
       title: "Homework to do!"
       message: '{{ states.calendar.annoying_calendar_name.attributes.description }}'

I run something similar to tell me to go to bed if I have a job before 8AM :wink:

You can also easily use the same template code to create template sensors :slight_smile:

Thanks for this. I’m already using a different automation for another calendar that tells me from 3 days before when an event is due. The issue I have is the description has a lot of information that I don’t need. Is there a way to filter out the stuff I don’t need? The information is provided by ical into my google calendar.

Have you thought of creating a template sensor that would extract what you need?
Assuming the format is the same for all classes
Class description (German):
value_template: '{{states.calendar.calendar_name.attributes.description.split("Class Name: ")[0] | trim}}'

Class name(08C2L/La):
value_template: '{{states.calendar.calendar_name.attributes.description.split("Class Name: ")[1].split("Homework Title: ")[0] | trim}}'

and so on…

This is what I think I’m after. Will give it a try later and update how I get on!

This worked great for me. Many thanks for the help, now have homework reminders set to nag my son over alexa when it’s due within 3 days!

1 Like