Google travel time don't work with new release 2022.2.x

Hi

when I install the new version 2022.2.1 or 2 or 3 my my google travel time don’t calculate.
I rollbacked to the last version where work 2021.12.9.
This configuration running well for years.

My configuration is:

Travel Time

  • platform: google_travel_time
    api_key: *************************
    origin: person.fabio
    destination: sensor.cal_location
    name: Viaggio
    options:
    units: metric

person.fabio get the position from my phone.

 cal_location:
    value_template: '{{ states.calendar.*********************.attributes.location }}'
    friendly_name: 'Calendar Location'

Cal_location get the address from the location of the next meeting red from my google calendar.

What has changed in the new version?
I read all pages about release notes, but I haven’t found anything connected.

Thanks in advance.

1 Like

Same problem here. Have been trying to fix it all morning. The only way I have been able to get it to work was to setup a new work zone, but since my work location can change daily this won’t work.

This is a bug introduced in the newest release and a PR to fix it is open https://github.com/home-assistant/core/pull/66081

Many thanks for your reply.
I will check the issue linked by you, waiting the solution that I hope will came asap.

Regards

I tested the changes locally with this PR and everything seems to work again:

I will update this post as soon as it is released.

That’s great. Thanks for fixing it!

Hey guys @febo7011 @joe.j.davis I am pretty new to all of this but I would love to get this to work too. Every day my morning starts by driving to a different job site and having a way to get HA to put out the travel time to my next calendar event would just be awesome.
Would any of you be willing to explain in detail how to achieve this or at least give some hints and share your full code?
This has the potential to be the greatest thing HA could do for me.

  1. Create the object for the source of the time travelling calculation.
    In my case the source is my phone position.
    Install home assistant application on your phone and connect with your home assistant server.
    Activate the location and all other permissions on this application in this way the application shared your position with your home assistant. This point is very important. If you don’t activate all location permissions the application doesn’t share the position with Home assistant server.
    You have to keep the GPS activate in the phone every time.
    This activity create new device tracker with this name ‘device_tracker.’
    Create a new person in home assistant with your name and connect the new entity ‘device_tracker.’.
    image

  2. Create the object for the destination of the time travelling calculation.

Connect your Google Calendar with your home assistant server.
Follow the instructions in this link. Google Calendars - Home Assistant
When you have connected your Google Calendar, automatically in your home assistant there is this file google_calendars.yaml.
This file is in the same folder of configuration.yaml.
In this file you can insert the rule to extract only the meeting that you need.
This is my setting.

- cal_id: <yourmail>
  entities:
  - device_id: <yourmail>gmailcom
    ignore_availability: true
    name: <yourmail>
    track: true
    search: "Rem."

You can see the line with the search.
In my case I prefer to insert in the meeting title a key world (‘Rem.’ Reminder).
Home assistant receive only the meeting information that have in the title this word (Ex. ‘Work Rem.’ or ‘Dinner with Friends Rem.’) You can change with your word.
Now you have in home assistant some entity with the next meeting from your calendar.
Location: (the address)
calendar..attributes.location

Title
calendar..attributes.message

Start Time
calendar..attributes.start_time

I put this 3 value in 3 new sensor in my configuration.yaml.

      cal_location:
        value_template: '{{ states.calendar.<yourmail>.attributes.location }}'
        friendly_name: 'Calendar Location'

      cal_title:
        friendly_name: 'Calendar Title'
        value_template: '{{ states.calendar.<yourmail>.attributes.message }}'

      cal_start_time:
        value_template: '{{ states.calendar.<yourmail>.attributes.start_time }}'
        friendly_name: 'Calendar Start'
        unit_of_measurement: 'time'
  1. Calculate travelling time.
    We need to configure the google travel time
    Follow these instructions: Google Maps Travel Time - Home Assistant
    This is my setting in the configuration.yaml
  - platform: google_travel_time
    api_key: <YourAPIKeyGooglecloud>
    origin: person.fabio
    destination: sensor.cal_location
    name: Viaggio
    options:
      units: metric

This setting creates a new sensor with the time to travel from your phone location to the calendar address location by car (default) every 5 minute recalculate.
sensor.viaggio
You can change the name Viaggio with your name (Ex. Travel)
Now I have all the value to create some automation.

  1. Time calculation
    I need 3 warning message with 3 different lead time.
    Create 3 input numbers with the lead time that you prefer.
  tempo_di_preparazione:
    name: Tempo di preparazione
    min: 0
    max: 200
    step: 1
    mode: box
    unit_of_measurement: 'Min.'
    icon: mdi:timer
  
  tempo_di_warning:
    name: Tempo di warning
    min: 0
    max: 200
    step: 1
    mode: box
    unit_of_measurement: 'Min.'
    icon: mdi:timer
    
  tempo_di_anticipo:
    name: Tempo di anticipo
    min: 0
    max: 200
    step: 1
    mode: box
    unit_of_measurement: 'Min.'
    icon: mdi:timer

In my case I set these numbers in:

I get a message 35 min. before the time to leave for my preparation.
I get a message 15 min. before the time to leave for Warning.
I get a message 5 min. before the time to leave. To Leave with a little margin.
I get the message with 0 min in advance this is the last time to leave without delay.
I calculate the correct time for each message in a different sensor.

      calc_leave_time:
        value_template: '{{ ((as_timestamp(states.calendar.<yourmail>.attributes.start_time) - (states.sensor.viaggio.state | int * 60) - (states.input_number.tempo_di_anticipo.state | int * 60)) | timestamp_custom("%Y-%m-%d %H:%M") ) }}'
        friendly_name: 'Leave Time'
        unit_of_measurement: 'time'

      calc_last_time:
        value_template: '{{ ((as_timestamp(states.calendar. <yourmail>.attributes.start_time) - (states.sensor.viaggio.state | int * 60)  ) | timestamp_custom("%Y-%m-%d %H:%M") ) }}'
        friendly_name: 'Last Time'
        unit_of_measurement: 'time'

      calc_prep_time:
        value_template: '{{ ((as_timestamp(states.calendar. <yourmail>.attributes.start_time) - (states.sensor.viaggio.state | int * 60) - (states.input_number.tempo_di_preparazione.state | int * 60) ) | timestamp_custom("%Y-%m-%d %H:%M") ) }}'
        friendly_name: 'Prep Time'
        unit_of_measurement: 'time'

      calc_warn_time:
        value_template: '{{ ((as_timestamp(states.calendar. <yourmail>.attributes.start_time) - (states.sensor.viaggio.state | int * 60) - (states.input_number.tempo_di_warning.state | int * 60) ) | timestamp_custom("%Y-%m-%d %H:%M") ) }}'
        friendly_name: 'warn Time'
        unit_of_measurement: 'time'

Now I have the time for each message.
calc_prep_time = start time meeting – travel time – prep time (35 min.)
calc_warn_time = start time meeting – travel time – warn time (15 min.)
calc_leave_time = start time meeting – travel time – leave time (5 min.)
calc_last_time = start time meeting – travel time

  1. Automation for message
    To check in automation I need another sensor with the sys time with the same format of the time of the 4 sensor calculated in the previous point.
    Sensor
      sys_time:
        value_template: '{{ (as_timestamp(strptime(states.sensor.date_time.state, "%Y-%m-%d, %H:%M")))  | timestamp_custom("%Y-%m-%d %H:%M")  }}'
        friendly_name: 'Sys Time'
        unit_of_measurement: 'time'

Automation

- id: Ultima chiamata
  alias: Ultima chiamata
  trigger:
    platform: time_pattern
    minutes: /1
    seconds: 15
  condition:
  - condition: template
    value_template: '{{ states.sensor.sys_time.state == states.sensor.calc_last_time.state }}'
  action:
  - service: script.ann_lastpartenza
  - service: script.ann_lastpartenza_remote

- id: Annuncio partenza
  alias: Annuncio partenza
  trigger:
    platform: time_pattern
    minutes: /1
    seconds: 15
  condition:
  - condition: template
    value_template: '{{ states.sensor.sys_time.state == states.sensor.calc_leave_time.state
      }}'
  action:
  - service: script.ann_partenza
  - service: script.ann_partenza_remote


- id: Annuncio warning
  alias: Annuncio warning
  trigger:
    platform: time_pattern
    minutes: /1
    seconds: 15
  condition:
  - condition: template
    value_template: '{{ states.sensor.sys_time.state == states.sensor.calc_warn_time.state
      }}'
  action:
  - service: script.ann_warning
  - service: script.ann_warning_remote


- id: Annuncio preparazione
  alias: Annuncio preparazione
  trigger:
    platform: time_pattern
    minutes: /1
    seconds: 15
  condition:
  - condition: template
    value_template: '{{ states.sensor.sys_time.state == states.sensor.calc_prep_time.state
      }}'
  action:
  - service: script.ann_preparazione
  - service: script.ann_preparazione_remote

Script
For each message, I have two different scripts one when I stay home and one when I stay out
The normal script when I stay home send a vocal message to my home assistant.
The script when I stay out to send the same message to my telegram.

ann_lastpartenza:
  sequence:
  - condition: state
    entity_id: person.fabio
    state: home
  - service: script.send_vocal_message
    data_template:
      device: '{{states.input_select.stanza_fabio.state}}'
      message: cosa What ci fai ancora a casa devi andare via subito 
      volume: 0.7
      wait: 10

ann_lastpartenza_remote:
  sequence:
  - condition: state
    entity_id: person.fabio
    state: not_home
  - service: notify.fabio_telegram
    data_template:
      message: cosa ci fai ancora a casa devi andare via subito

ann_partenza:
  sequence:
  - condition: state
    entity_id: person.fabio
    state: home
  - service: script.send_vocal_message
    data_template:
      device: '{{states.input_select.stanza_fabio.state}}'
      message: è ora di partire per {{ states.calendar.fabiofava70gmailcom.attributes.message
        | replace('Rem.', '') }} Ci vorranno {{ states.sensor.viaggio.state }} minuti. destinazione {{ states.sensor.cal_location.state }}
      volume: 0.7
      wait: 15
  - condition: numeric_state
    entity_id: sensor.viaggio
    above: 0
  - service: switch.turn_on
    entity_id: switch.cancello

ann_partenza_remote:
  sequence:
  - condition: state
    entity_id: person.fabio
    state: not_home
  - service: notify.fabio_telegram
    data_template:
      message: è ora di partire per {{ states.calendar.fabiofava70gmailcom.attributes.message
        | replace('Rem.', '') }} Ci vorranno {{ states.sensor.viaggio.state }} minuti. destinazione {{ states.sensor.cal_location.state }} 

ann_warning:
  sequence:
  - condition: state
    entity_id: person.fabio
    state: home
  - service: script.send_vocal_message
    data_template:
      device: '{{states.input_select.stanza_fabio.state}}'
      message: Tra {{ states.input_number.tempo_di_warning.state | int }} minuti devi partire per {{ states.calendar.fabiofava70gmailcom.attributes.message | replace('Rem.', '') }} 
     volume: 0.7
      wait: 8

ann_warning_remote:
  sequence:
  - condition: state
    entity_id: person.fabio
    state: not_home
  - service: notify.fabio_telegram
    data_template:
      message: Tra {{ states.input_number.tempo_di_warning.state | int }} minuti devi partire per {{ states.calendar.fabiofava70gmailcom.attributes.message | replace('Rem.', '') }}

ann_preparazione:
  sequence:
  - condition: state
    entity_id: person.fabio
    state: home
  - service: script.send_vocal_message
    data_template:
      device: '{{states.input_select.stanza_fabio.state}}'
      message: Ti devi preparare tra {{ states.input_number.tempo_di_preparazione.state | int }} minuti devi partire per {{ states.calendar.fabiofava70gmailcom.attributes.message | replace('Rem.', '') }} 
      volume: 0.7
      wait: 8

ann_preparazione_remote:
  sequence:
  - condition: state
    entity_id: person.fabio
    state: not_home
  - service: notify.fabio_telegram
    data_template:
      message: Ti devi preparare tra {{ states.input_number.tempo_di_preparazione.state | int }} minuti devi partire per {{ states.calendar.fabiofava70gmailcom.attributes.message| replace('Rem.', '') }} 

send_vocal_message:
  fields:
    device:
      description: nome del dispositivo
      example: soggiorno
    message:
      description: testo del messaggio da spedire
      example: prova messaggio
    volume:
      description: volume del massaggio
      example: '0.6'
    wait:
      description: secondi di attesa
      example: '5'
  sequence:
  - service: media_player.volume_set
    data_template:
      entity_id: media_player.{{ device }}
      volume_level: '{{ volume }}'
  - delay:
      seconds: 2
  - service: tts.cloud_say
    data_template:
      entity_id: media_player.{{ device }}
      message: '{{ message }}'
      language: it-IT
      options:
        gender: female
  - delay:
      seconds: '{{ wait }}'
  - service: media_player.volume_set
    data_template:
      entity_id: media_player.{{ device }}
      volume_level: 0.5
1 Like

Wow @febo7011 thank you so much for taking the time!
I already messed around a bit but I cant seem to get the following part to work. I have a separate sensor.yaml but no matter if I post this in my config or sensor file I always get an error. I guess there is something missing right before those 3 entrys?

I know that procedure is a little bit complex. I hope my document is sufficient clear.

Pay attention in you have to insert your mail ex. daKazze@gmail.
If you have used this name in the calendar setting.
you have to use the name that you have inserted in device id in the calendar setting.
In the below example you have to insert daKazzegmailcom.
But when you have connected the calendar reboot the HA and check if in your system you have all the entity with the data from calendar.

- cal_id: daKazze@gmail
  entities:
  - device_id: daKazzegmailcom
    ignore_availability: true
    name: daKazze@gmail
    track: true

states.calendar.dakazzegmailcom.attributes.location

This here is my configuration.yaml and here is the error I get when checking config via settings menu:
I am sure it´s just a completely simple newbie-mistake -.-

Integration error: cal_title - Integration ‘cal_title’ not found.
Integration error: cal_start_time - Integration ‘cal_start_time’ not found.
Integration error: cal_location - Integration ‘cal_location’ not found.


# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:

# Text to speech
tts:
  - platform: google_translate

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
input_boolean: !include input_boolean.yaml
sensor: !include sensor.yaml

switch:
  - platform: wake_on_lan
    mac: "18:C0:4D:94:B1:27"

google:
  client_id: "xxxxxxxxxxxxx"
  client_secret: "xxxxxxxxxxx"
  
cal_location:
  value_template: '{{ states.calendar.xxxxxxxx_gmail_com.attributes.location }}'
  friendly_name: 'Calendar Location'
    
    
cal_title:
  friendly_name: 'Calendar Title'
  value_template: '{{ states.calendar.xxxxxxxxx_gmail_com.attributes.message }}'
    
    
cal_start_time:
  value_template: '{{ states.calendar.xxxxxxxxxx_gmail_com.attributes.start_time }}'
  friendly_name: 'Calendar Start'
  unit_of_measurement: 'time'

edit: and if I put 2 spaces in front of all the lines the error is:

Invalid config for [google]: [cal_location] is an invalid option for [google]. Check: google->google->cal_location. (See /config/configuration.yaml, line 19).

edit2: the g-cal.yaml seems to be fine since in dev options I can view my next calendar event:

- cal_id: [email protected]
  entities:
  - device_id: xxxxx_gmail_com
    ignore_availability: true
    name: [email protected]
    track: true

if you have a sensor.yaml you have to insert

cal_location:
  value_template: '{{ states.calendar.xxxxxxxx_gmail_com.attributes.location }}'
  friendly_name: 'Calendar Location'
    
    
cal_title:
  friendly_name: 'Calendar Title'
  value_template: '{{ states.calendar.xxxxxxxxx_gmail_com.attributes.message }}'
    
    
cal_start_time:
  value_template: '{{ states.calendar.xxxxxxxxxx_gmail_com.attributes.start_time }}'
  friendly_name: 'Calendar Start'
  unit_of_measurement: 'time'

in sensor.yaml

what is the name of the entity where you can see the meeting information?
Should be cal_location:
calendar.xxxxx_gmail_com

Ah, I found the issue :smiley:

  • platform: template

was missing at the top… told you I am a total noob ^^

Now I am met with another and hopefully last issue:

The location gets read from my calendar same as it is input “Street X, ZipCode City” = sensor.cal_location

When I try to feed this to travel time I get no result, the only way to receive a travel time is if I manually input coordinates for the destination.
I also tried different ways to spell out the location “City, Country” / “street city country” etc. but the only thing that works is coordinates.
What exactly am I doing wrong here? Doest travel_time not work with “clear text” addresses?

It is currently broken in the latest release. A fix is on its way

@eifinger thanks, if it wasnt for you I would have kept looking for mistakes

@febo7011 thanks again for all the time you put into this awesome walkthrough, I am pretty sure I can get this to work as soon as travel time is fixed.
Since your writeup is so detailed it would be great to have it linked somewhere so other people can find this easier.

daKazze
Yes now for the release 2022.2.x not work well.
This is the reason for this Post.
I’m waiting for the solution but to have this procedure ok now in my HA I leave the release 2021.12.9.
I will install the new releases 2022.2.x only when the problem will be solved.

I am happy that you like my solution.
I use it every day and it wakes me up in my bedroom in the morning.

Regards

My fix got merged and will be part of the 2022.3 release: Full Changelog for Home Assistant Core 2022.3 - Home Assistant

Hi eifinger

Very good news.
Many thanks for your bug fixing.

I look forward to the new release,

Regards