tesla
tesla copied to clipboard
Turning on charger not reflected in HA until next car poll?
Version of the custom_component
v3.14.0
Configuration
- service: switch.turn_on
data: {}
target:
entity_id: switch.tesla_charger
Describe the bug
I have an automation that switches on the charger, but also some other automations that depend on the state of the charger (e.g. setting the charging amps to match excess solar) and I also have the switch displayed on the HA UI.
Since around the time of upgrading to HA 2023.6.3 calling the switch.turn_on service for the car's charger (I have a very dumb wall charger) causes the car to start charging, but the switch on the HA UI doesn't update for anything from a 20 seconds to several minutes and during this time the other automations also think the charger is off.
I've tried tailing the log with debugging on while opening the car app on the phone to check if it really charging, and as far as I can tell, the first line in the debug logging below causes the car to start charging, but HA doesn't think the car is charging until the 2nd line.
Note that around the same time the car also updated to 2023.20.7 so it is hard to say what changed this behaviour.
Another thing I have noticed is that as a result my automations sometimes send the start charging command when the car is already charging - I wonder if the integration is seeing this as a failure to start charging (even though the reason is that it is already charging) and setting the switch state in HA to off as a result even though what it actually means is the switch is on.
Since the update to HA 2023.6.3 (with python 3.11) things have been a fair bit quicker, so it could be that this race is happening more often and it has been a bug in my automations for a while.
It's also possible the car update to 2023.20.7 has changed the behaviour of asking the car to start charging when it was already charging.
2023-07-04 11:35:33.961 DEBUG (MainThread) [teslajsonpy.connection] 200: {"response":{"reason":"is_charging","result":false}}
2023-07-04 11:35:33.962 DEBUG (MainThread) [teslajsonpy.car] Response from command START_CHARGE: {'response': {'reason': 'is_charging', 'result': False}}
Sorry - fair bit of speculation as to the cause.
Debug log
2023-06-29 13:34:18.229 DEBUG (MainThread) [teslajsonpy.connection] post: https://owner-api.teslamotors.com/api/1/vehicles/**********/command/charge_start {}
2023-06-29 13:34:47.464 DEBUG (MainThread) [teslajsonpy.controller] 32838: online. Polling policy: normal. Update state: normal. Since last park: 341. Since last wake up: 340. Idle interval:
600. shift_state: None sentry: False climate: False, charging: Charging
Thanks for reporting. There should be code to change the state if the API call is successful. However, I don't know if it will cover a 200 where it reports "false" like you found. I'll leave this as a bug report since this does seem wrong. Hopefully someone will submit a PR to cover this use case.