-
Notifications
You must be signed in to change notification settings - Fork 99
Dynamic Polling Frequency
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.
Configure the integration with default Polling Interval (660 seconds) and set Polling Policy to connected.
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.
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
state: "on"
action:
- delay: '00:01:00'
- service: tesla_custom.polling_interval
data:
vin: "{{ state_attr('binary_sensor.your_car_online','vin') }}"
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
state: "off"
action:
- delay: '00:01:00'
- service: tesla_custom.polling_interval
data:
vin: "{{ state_attr('binary_sensor.your_car_online','vin') }}"
scan_interval: 30
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
to: "on"
action:
- service: tesla_custom.polling_interval
data:
vin: "{{ state_attr('binary_sensor.your_car_online','vin') }}"
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
to: "off"
for: "00:15:00"
condition:
- condition: state
entity_id: binary_sensor.your_car_parking_brake
state: "on"
action:
- service: tesla_custom.polling_interval
data:
vin: "{{ state_attr('binary_sensor.your_car_online','vin') }}"
scan_interval: 660
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
to: "off"
action:
- service: tesla_custom.polling_interval
data:
vin: "{{ state_attr('binary_sensor.your_car_online','vin') }}"
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
to: "on"
for: "00:15:00"
condition:
- condition: state
entity_id: binary_sensor.your_car_charger
state: "off"
action:
- service: tesla_custom.polling_interval
data:
vin: "{{ state_attr('binary_sensor.your_car_online','vin') }}"
scan_interval: 660
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.carA_parking_brake
- binary_sensor.carB_parking_brake
to: "off"
action:
- service: tesla_custom.polling_interval
data:
vin: "{{ state_attr('binary_sensor.' ~ trigger.entity_id.split('.')[1].split('_')[0] ~ '_online','vin') }}"
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.carA_parking_brake
- binary_sensor.carB_parking_brake
to: "on"
for: "00:15:00"
condition:
- condition: template
value_template: "{{ is_state('binary_sensor.' ~ trigger.entity_id.split('.')[1].split('_')[0] ~ '_charger', 'off') }}"
action:
- service: tesla_custom.polling_interval
data:
vin: "{{ state_attr('binary_sensor.' ~ trigger.entity_id.split('.')[1].split('_')[0] ~ '_online','vin') }}"
scan_interval: 660
This is a suggested single automation that could be used on it's own without any of the above. It has two triggers:
- Whenever the car asleep state changes to 'off' - This would be detected in 60 seconds, after which we start polling the vehicle every 30 seconds (or an interval of your choice). If no user is present after 10 minutes, it reverts to the integration default polling interval by setting the polling interval to -1, or remains at 30 seconds if the user present state is 'on'.
- Whenever the user present state changes to 'off' - This would be detected within 30 seconds (due to us setting the interval to 30 seconds on wake up). After no user is present for 10 minutes, the polling interval once again reverts to the integration default polling interval by setting the polling interval to -1
alias: Tesla - Automate Polling Interval
description: When car wakes up, poll every 30 seconds then revert after 10 mins
trigger:
- platform: state
entity_id:
- binary_sensor.your_car_asleep
to: "off"
id: SleepOff
- platform: state
entity_id:
- binary_sensor.your_car_user_present
to: "off"
id: UserNotPresent
- platform: state
entity_id:
- binary_sensor.your_car_user_present
to: "on"
id: UserPresent
condition: []
action:
- if:
- condition: or
conditions:
- condition: trigger
id:
- SleepOff
- condition: trigger
id:
- UserPresent
then:
- service: tesla_custom.polling_interval
data:
vin: YOUR_VIN
scan_interval: 30
- delay:
hours: 0
minutes: 10
seconds: 0
milliseconds: 0
- if:
- condition: state
entity_id: binary_sensor.your_car_user_present
state: "off"
then:
- service: tesla_custom.polling_interval
data:
vin: YOUR_VIN
scan_interval: -1
mode: restart
If you need to start gathering data ASAP and don't want the 60 second gap at the start, here is an additional automation to force a data refresh based on your phone's connected bluetooth devices. You will need:
- To be running the Home Assistant app on your phone
- To use the Home Assistant developer page to observe EXACTLY how your Tesla appears in the 'connected_paired_devices' e.g. ''4C:FC:AA:AA:AA:AA (Tesla Model Y)'
- The sensor name of your bluetooth connections
This is tested with Android, iPhone may differ slightly.
alias: Tesla - Force data update when phone connects to bluetooth
description: "When the vehicle is seen in the connected bluetooth devices of your phone, force a data refresh"
trigger:
- platform: template
value_template: >-
{{'4C:FC:AA:AA:AA:AA (Tesla Model Y)' in state_attr('sensor.your_phone_bluetooth_connection','connected_paired_devices') }}
condition: []
action:
- service: button.press
data: {}
target:
entity_id: button.your_car_force_data_update
mode: single