Dynamic Polling Frequency - alandtse/tesla Wiki

The features in this page requires version 1.5.0 of the tesla_custom integration.


With the default Polling Policy and Polling Interval we try to be very conservative to be certain that polling is not causing any problems. We want to be sure the car is allowed to sleep to conserve the battery, and we want to be sure the integration do not cause you to be banned from the Tesla API by polling data too frequently.

See Polling Policy for more information on how these settings influence the polling of data from Teslas APIs.

However, these precautions might lead to certain updates of the car status being missed due to the deliberately long default Polling Interval.

For instance, if the car is woken up and unlocked, this will quickly be noticed by the integration and updated in Home Assistant. However, if the car is then locked and have time to go back to sleep before we do another poll we will never get notified that the car has been locked again. If you have enabled notifications from Home Assistant about the car being unlocked for a longer period of time or other automations enabled that depend on the status of the car, these might be triggered unneccesary and cause concern or confusion.

The following is an example of how you can adjust the Polling Interval dynamically to minimze the chance of missing updates, while still trying to balance the energy conservation and traffic against Teslas APIs.

It is strongly recommended to read and understand the information on this page before you go any further. Please ask questions in the Discussions section if you need help understanding the potential impacts of implementing this.

Base config

Confiugure the integration with default Polling Interval (660 seconds) and set Polling Policy to connected.

Automations

Use a set of automations to adjust the Polling Interval based on certain events.

Replace "your_car" in the sensor names with the correct name for your sensors.

On HA startup

We adjust the polling interval down to 30 seconds to ensure we receive updates every minute on HA startup if the car is connected to a charger. We add a delay to ensure that everything is settled before we try to adjust the interval.

Again, read this page if you have any questions about the meaning of the Polling Interval setting.

- alias: Tesla set polling time short on startup if charger is connected
  description: When HA starts up. We adjust the Polling Interval down from the configured value if we are connected to a charger
  trigger:
    - platform: homeassistant
      event: start
  condition:
    - condition: state
      entity_id: binary_sensor.your_car_charger_sensor
      state: "on"
  action:
    - delay: '00:01:00'
    - service: tesla_custom.polling_interval
      data:
        scan_interval: 30

We also adjust the polling interval down to 30 seconds on HA startup if the car is driving. We add a delay to ensure that everything is settled before we try to adjust the interval.

- alias: Tesla set polling time short on startup if car is driving
  description: When HA starts up. We adjust the Polling Interval down from the configured value if we are driving
  trigger:
    - platform: homeassistant
      event: start
  condition:
    - condition: state
      entity_id: binary_sensor.your_car_parking_brake_sensor
      state: "off"
  action:
    - delay: '00:01:00'
    - service: tesla_custom.polling_interval
      data:
        scan_interval: 30

On charger connect/disconnect

When the charger is connected, we adjust the Polling Interval down to ensure we don't miss any updates.

- alias: Tesla set polling time short when charger is connected
  description: We adjust the Polling Interval down from the configured value if we are connecting to a charger
  trigger:
    - platform: state
      entity_id: binary_sensor.your_car_charger_sensor
      to: "on"
  action:
    - service: tesla_custom.polling_interval
      data:
        scan_interval: 30

When the charger has been disconnected for some minutes, and we are not driving, we adjust the Polling Interval up to ensure the car is allowed to sleep.

- alias: Tesla set polling time long when charger is disconnected
  description: We adjust the Polling Interval up to the configured value if we are disconnecting from the charger
  trigger:
    - platform: state
      entity_id: binary_sensor.your_car_charger_sensor
      to: "off"
      for: "00:15:00"
  condition:
    - condition: state
      entity_id: binary_sensor.your_car_parking_brake_sensor
      state: "on"
  action:
    - service: tesla_custom.polling_interval
      data:
        scan_interval: 660

Start driving or park the car

When the car starts driving, we adjust the polling interval down

- alias: Tesla set polling time short when car is driving
  description: We adjust the Polling Interval down from the configured value if we are driving
  trigger:
    - platform: state
      entity_id: binary_sensor.your_car_parking_brake_sensor
      to: "off"
  action:
    - service: tesla_custom.polling_interval
      data:
        scan_interval: 30

After the car is parked for a while without a connected charger, we adjust the Polling Interval up to allow the car to sleep.

- alias: Tesla set polling time long when car is parked
  description: We adjust the Polling Interval up to the configured value when we are parked if the charger is not connected
  trigger:
    - platform: state
      entity_id: binary_sensor.your_car_parking_brake_sensor
      to: "on"
      for: "00:15:00"
  condition:
    - condition: state
      entity_id: binary_sensor.your_car_charger_sensor
      state: "off"
  action:
    - service: tesla_custom.polling_interval
      data:
        scan_interval: 660