google_travel_time sensor provides travel time from the Google Distance Matrix API.
You need to register for an API key by following the instructions here. You only need to turn on the Distance Matrix API.
Google now requires billing to be enabled (and a valid credit card loaded) to access Google Maps APIs. The Distance Matrix API is billed at US$10 per 1000 requests, however, a US$200 per month credit is applied (20,000 requests). The sensor will update the travel time every 5 minutes, making approximately 288 calls per day. Note that at this rate, more than 2 sensors will likely exceed the free credit amount. While this call frequency can not be decreased, you may have a use case which requires the data to be updated more often, to do this you may update on-demand (see automation example below).
A quota can be set against the API to avoid exceeding the free credit amount. Set the ‘Elements per day’ to a limit of 645 or less. Details on how to configure a quota can be found here
To add the Google Maps Travel Time integration to your Home Assistant instance, use this My button:
If the above My button doesn’t work, you can also perform the following steps manually:
- Origin and Destination can be the address or the GPS coordinates of the location (GPS coordinates have to be separated by a comma). You can also enter an entity ID that provides this information in its state, an entity ID with latitude and longitude attributes, or zone friendly name (case sensitive).
Tracking can be setup to track entities of type
person. If an entity is placed in the Origin or Destination then every 5 minutes when the platform updates it will use the latest location of that entity.
Origin: device_tracker.mobile_phone Destination: zone.home
Origin: zone.home Destination: Eddies House
- If state is a zone then the zone location will be used
- If state is not a zone it will look for the longitude and latitude attributes
- Uses the longitude and latitude attributes
- Can also be referenced by just the zone’s friendly name found in the attributes.
- If state is a zone or zone friendly name then will use the zone location
- All other states will be passed directly into the Google API
- This includes all valid locations listed in the Configuration Variables
Using automatic polling can lead to calls that exceed your API limit, especially when you are tracking multiple travel times using the same API key. To use more granular polling, disable automated polling.
You can use the
homeassistant.update_entity service to update the sensor on-demand. For example, if you want to update
sensor.morning_commute every 2 minutes on weekday mornings, you can use the following automation:
- id: update_morning_commute_sensor alias: "Commute - Update morning commute sensor" initial_state: "on" trigger: - platform: time_pattern minutes: "/2" condition: - condition: time after: "08:00:00" before: "11:00:00" - condition: time weekday: - mon - tue - wed - thu - fri action: - service: homeassistant.update_entity target: entity_id: sensor.morning_commute
For more detailed steps on how to define a custom polling interval, follow the procedure below.
If you want to define a specific interval at which your device is being polled for data, you can disable the default polling interval and create your own polling service.
Go to Settings > Devices & Services, and select your integration.
On the integration entry, select the three dots.
- Then, select System options and toggle the button to disable polling.
To define your custom polling interval, create an automation.
Go to Settings > Automations & Scenes and create a new automation.
Define any trigger and condition you like.
Under action, select Call service and use the
Example in YAML.
automation: - alias: "Only update weather information every 20 minutes when I'm home" trigger: - platform: time_pattern minutes: "/20" condition: - condition: state entity_id: device_tracker.cynthia state: home action: - service: homeassistant.update_entity target: entity_id: weather.home
Save your new automation to poll for data.