Google Maps Travel Time - mode does not take value

Hi,

I’m trying to set up a model where I by using input-select can choose origin, destination and mode. However, when testing the configuration I get the answer that this is not acceptable for mode.

  - platform: google_travel_time
    name: Restid
    api_key: !secret google_travel_time_api
    origin: sensor.resa_start
    destination: sensor.resa_end
    options:
      mode: {{ states("sensor.resa_mode") }}

When testing the configuration I get the following:

Invalid config for [sensor.google_travel_time]: value is not allowed for dictionary value @ data[‘options’][‘mode’]. Got ‘sensor.resa_mode’. (See ?, line ?). Please check the docs at https://home-assistant.io/components/sensor.google_travel_time/

I have also tried the same thing using travel_mode:

  - platform: google_travel_time
    name: Restid
    api_key: !secret google_travel_time_api
    origin: sensor.resa_start
    destination: sensor.resa_end
    travel_mode: sensor.resa_mode

I get the same error:

Invalid config for [sensor.google_travel_time]: value is not allowed for dictionary value @ data[‘travel_mode’]. Got ‘sensor.resa_mode’. (See ?, line ?). Please check the docs at https://home-assistant.io/components/sensor.google_travel_time/

The setup getting the template sensor for an input_select is the same as I use for the sensors for origin and destination. I can also verify that the sensor has one of the four different modes as state (driving, bicycling, walking or transit).

It seems like the mode parameter cannot read a variable and needs a string. Is it possible to convert the variable so that mode reads it as a string?

I managed a work around! There always is one.

As mode cannot be set to a value I have made four google maps travel time sensors, one for each mode. Origin and destination are still variables and the same variables are used in each case.

  - platform: google_travel_time
    name: Restid med bil
    api_key: !secret google_travel_time_api
    origin: sensor.resa_start
    destination: sensor.resa_end
    options:
      mode: driving
    scan_interval: 14400

The only difference between the sensors is that the name is changed and that the mode is changed. (eg Restid med cykel/bicycling).

I then have four scripts to update the travel time:

updatera_restid_med_bil:
  alias: Uppdatera restid med bil
  sequence:
  - data:
      entity_id: sensor.restid_med_bil
    service: sensor.google_travel_sensor_update
  - data:
      entity_id: script.uppdatera_restid_med_bil
    service: script.turn_off
updatera_restid_med_cykel:
  alias: Uppdatera restid med cykel
  sequence:
  - data:
  entity_id: sensor.restid_med_cykel
service: sensor.google_travel_sensor_update
  - data:
  entity_id: script.uppdatera_restid_med_cykel
service: script.turn_off
updatera_restid_till_fots:
  alias: Uppdatera restid till fots
  sequence:
  - data:
  entity_id: sensor.restid_till_fots
service: sensor.google_travel_sensor_update
  - data:
  entity_id: script.uppdatera_restid_till_fots
service: script.turn_off
updatera_restid_med_kollektivtrafik:
  alias: Uppdatera restid med kollektivtrafik
  sequence:
  - data:
  entity_id: sensor.restid_med_kollektivtrafik
service: sensor.google_travel_sensor_update
  - data:
  entity_id: script.uppdatera_restid_med_kollektivtrafik
service: script.turn_off

Finally in my Lovelace ui I use the conditional card - if I change the mode (resesätt) the card displayed changes.

In the first case I have chosen the mode transit (Kollektivtrafik)

54

Then I can call the script to update the travel time using transit.

If I change the mode to driving (Bil) a different card is displayed which allows me to use the corresponding script to update the travel time.

11

A complicated work around but interesting to see that most problems can be solved.