alandtse / tesla

Tesla custom integration for Home Assistant. This requires a refresh token be generated by third-party apps to login.
Apache License 2.0
588 stars 100 forks source link

Something keeps re-enabling the charger #514

Closed mtieltjes closed 1 year ago

mtieltjes commented 1 year ago

Versions

Tesla integration: 3.8.1 Tesla firmware: 2023.2.10

Configuration

Notes:

alias: Charge Tesla in optimal hours
description: >-
  Charges tesla to its limit in the cheapest hours
# Runs every 5 minutes instead of state-triggers to correct any incorrect behavior as a result of unreliability
trigger:
  - platform: time_pattern
    minutes: /5
condition:
  # Only run when the car is connected at home
  - condition: state
    entity_id: binary_sensor.tesla_wall_connector_vehicle_connected
    state: "on"
  # Don't run when charging takes less than 30 minutes (prevents trickle-charging)
  - condition: not
    conditions:
      - condition: template
        value_template: "{{ states('sensor.tesla_estimated_charging_time_needed')|round == 0 }}"
  # Don't run if it should charge and is already charging
  - condition: not
    conditions:
      - condition: and
        conditions:
          - condition: state
            entity_id: binary_sensor.optimum_charging_hour_active
            state: "on"
          - condition: state
            entity_id: binary_sensor.tesla_wall_connector_contactor_closed
            state: "on"
    alias: If not already charging when it should
  # Don't run if it should not charge and is not charging
  - condition: not
    conditions:
      - condition: and
        conditions:
          - condition: state
            entity_id: binary_sensor.optimum_charging_hour_active
            state: "off"
          - condition: state
            entity_id: binary_sensor.tesla_wall_connector_contactor_closed
            state: "off"
    alias: If not already stopped when it should
action:
  - choose:
      - conditions:
          - condition: state
            entity_id: binary_sensor.optimum_charging_hour_active
            state: "on"
        sequence:
          - service: script.start_charging_tesla
            data: {}
      - conditions:
          - condition: state
            entity_id: binary_sensor.optimum_charging_hour_active
            state: "off"
        sequence:
          - service: script.stop_charging_tesla
            data: {}
mode: restart

Scripts:

alias: Start charging tesla
sequence:
  - repeat:
      until:
        - condition: state
          entity_id: binary_sensor.tesla_wall_connector_contactor_closed
          state: "on"
      sequence:
        - service: switch.turn_on
          data: {}
          target:
            entity_id: switch.<CAR>_charger
        - delay:
            hours: 0
            minutes: 0
            seconds: 30
            milliseconds: 0
mode: single
icon: mdi:flash

alias: Stop charging tesla
sequence:
  - repeat:
      until:
        - condition: state
          entity_id: binary_sensor.tesla_wall_connector_contactor_closed
          state: "off"
      sequence:
        - service: switch.turn_off
          data: {}
          target:
            entity_id: switch.<CAR>_charger
        - delay:
            hours: 0
            minutes: 0
            seconds: 30
            milliseconds: 0
mode: single
icon: mdi:flash-off

Describe the bug

I run electricity on dynamic rating, meaning the price changes during the day. With HomeAssistant I can leverage the Tesla API to charge only on the cheapest hours.

The automation is running as expected, yet I see very odd behavior on the charger. There seems to be a battle going on over the charger between HomeAssistant and something else. Sometimes, after HomeAsssistant turns off the charger, something else turns it back on. This is on an observed interval of about 12 minutes after turning it off.

What I find interesting is the time between turning the charger off, and it turning on again being oddly close to the polling interval. Please not that I do not have any overrides on the polling interval, so I assume (see debug log section) it is polling every 660 seconds during this issue.

Could it be that the car re-thinks whether is should charge when it is woken up by the polling interval?

Notes:

image image

Debug log

Unfortunately I did not have the logger active at the time of writing this. This seems like a good next step to check if the polling interval might have anything to do with it. I will update this ticket once I have a log of such an event.

TBA
craigrouse commented 1 year ago

I believe this is a bug in the latest Tesla firmware. Confirmed with a friend who doesn't use this integration and is seeing the exact same behaviour. I have opened a case with Tesla, as this has only started happening since the update - the car has a mind of its own! The only thing that cures the issue is by setting a charge schedule in the Tesla app, e.g. "start charging at midnight" - it then respects this and doesn't start charging until that time.

ASomerN commented 1 year ago

I've contacted Tesla for the same thing. I've powered off Home Assistant and disabled all third party apps and it still happens. Seemed to be after last update

juicejuice commented 1 year ago

Yes, I've got the same thing since updating our car to Tesla firmware 2023.2.10. Just today I had turned the charger off then 42 mins later it came back on for no reason. This is used the Gen3 wall charger.

craigrouse commented 1 year ago

Yes, I've got the same thing since updating our car to Tesla firmware 2023.2.10. Just today I had turned the charger off then 42 mins later it came back on for no reason. This is used the Gen3 wall charger.

Please do raise a service request with Tesla - the more reports they have, the more likely they are to fix it. This is very clearly a firmware bug.

ASomerN commented 1 year ago

This is the response I've had from Tesla (please excuse my spelling mistakes):

image

This appears to be a "feature" now.

mtieltjes commented 1 year ago

This appears to be a "feature" now.

I read their response differently and think they might've misunderstood your report, thinking you don't want it to automatically start charging after plugging in the cable.

I'm still awaiting response on my report, in which I have made no references to (3rd party) integrations, basically telling them I keep stopping the charger through the official app.

This issue may be bigger than just an annoyance for automating, people could pop their breaker circuits when Tesla randomly starts charging during peak power consumption without load balancing.


By the way, did anyone try working around this by (ab)using the scheduled charging feature? I did use the scheduled charging feature to prevent automatic charging after plugging in, but if the scheduled time was in a no-charge hour it would still ping-pong with my automation for a few hours.

Maybe there's a solution to be found in re-setting the scheduled time after each charging period. It would make the automation more complex though.

anhaff commented 1 year ago

This or something similar has been discussed here before. The behavior as Tesla describes has always been this way according to my experience.

My charging related automation is triggered by any state change of the charger (ON/OFF) and then decides if charging shall continue or be terminated (in wait for hours with cheaper power).

ASomerN commented 1 year ago

I've asked them to leave the ticket open as I retest with the Tesla app set to "off-peak charging".

Yes, they may have misunderstood, but previously I've been supplying timestamps of it starting randomly on its own and they seemed to understand the scope of the issue at that point, I suspect I've just been switched over to someone else who want's a quick "out".

It's simple to have some automation set your SOC down during your "peak" and have an input that changes your target charge at off-peak, but we shouldn't have to make this adjustment.

I'll be interested to hear what others are experiencing with Tesla and hopeful that you get more traction than me. I've raised it on forums here too: https://teslamotorsclub.com/tmc/threads/car-starts-charging-without-prompt.293594/#post-7435954

craigrouse commented 1 year ago

@ASomerN they are fobbing you off. It's correct that the normal behaviour is to start charging as soon as the car is plugged in, but then if you press "stop charging" in the app (or though this integration, or by Octopus [UK power utility company with Tesla integration for anyone not aware], the car shouldn't start charging again until the next "start charging" button press, or API call.

A temporary workaround is to set the off-peak charging schedule to start charging at a later time - I confirmed the car no longer tries to charge randomly by itself when this setting is active. It is possible to set this up with this integration through a custom API call, which I haven't got round to doing yet.

I plan to wait for my Intelligent Octopus times to be published, then set the off-peak "start charging at" time to a later time than the latest timeslot they give me. This should then allow Octopus to start and stop charging as necessary, and should prevent the car from charging during the peak period. I think this is what @mtieltjes was suggesting - great minds think alike 😃

I will also drop an email to Octopus, since they almost certainly have a direct line to someone at Tesla who can help, and will understand the problem. I always avoid telling Tesla about any 3rd party integrations so they can't use that as a get out of jail free card, but with regard to Octopus, they are a Tesla partner, so that integration shouldn't be considered 3rd-party in the same sense the HA integration is.

alandtse commented 1 year ago

This is unrelated to the component so I'll go ahead and close this. You can continue to discuss it if you like.

craigrouse commented 1 year ago

I had a reply from Octopus Energy:

Thanks for reaching out to us. This is something we have now fixed alongside Tesla, please can you ensure you have the latest version of our app installed, I would then recommend de-authenticating your EV and reconnecting it, please follow these steps: ⦿ Click the profile button in the top left corner of the app’s dashboard. ⦿ Select ‘Intelligent Octopus Settings’. ⦿ Scroll down and tap ‘Disconnect Car’ and confirm. ⦿ This will disconnect your device and log you out of the app.

Once this is complete, you can then go through the onboarding process again, do not worry, you will still be on the Intelligent Octopus tariff.

Seems a little odd, considering it was still happening when I disabled "smart charging" in the Octopus app. Will see if it works.

Edit: and a later reply: "Tesla has done some work on their API which has helped corrected the issue."

ASomerN commented 1 year ago

I suspect that if this is happening to people not on Octopus (which it is) then it isn't an Octopus issue. I'll update here too when I get a response from them.

craigrouse commented 1 year ago

@ASomerN totally agree, but since Octopus said they'd been cooperating with Tesla on the issue, I thought I'd give them the benefit of the doubt. Anyway, my hope was in vain - after following Octopus' instructions and re-linking my car (actually a nightmare due to a recent bug in their Android app, forcing me to use an old iOS device), the issue resurfaced almost immediately. I've gone back to Octopus to let them know. At least they have a line to the right people at Tesla to get it resolved. I'm pretty sure it's a firmware bug on the car that will only be fixable with a firmware update.

mtieltjes commented 1 year ago

Update from my side.

Tesla has asked me for timestamps of these events where the charger turned itself on, no older than 7 days. With these, they will further diagnose the issue.

craigrouse commented 1 year ago

I also provided them some timestamps around a week ago. I was hopeful that the latest bugfix update (2023.2.12) might solve the issue, but it hasn't.

mtieltjes commented 1 year ago

Tesla asked me to disable all 3rd parties, reset the account password and run it again for a while. As expected, this had the same results and behavior.

They did some internal testing with a Tesla + Wall Connector Gen 2 on their end (whereas I have this issue with a Gen 3) and saw the same issue.

The bug has been acknowledged and forwarded to the engineering team. The service rep couldn't tell me when a fix can be expected, since it is all based on issue priority.

When asked if they confirmed it to be a firmware issue or perhaps a wall connector issue, he couldn't really give an answer and thus assumed it to be a firmware issue. So whether the bug has already been found or just internally reported, I don't know, at least they acknowledged it.

So with that said, I will wait 2-3 updates and if nothing has been fixed by then, Tesla asked me to report again.


I also asked if they received multiple reports. They have an internal forum where things get discussed, and the rep said he didn't find any other reports on their internal network. This was the first case he has heard of.

The more people that report the issue, the higher priority a fix will likely get.

mtieltjes commented 1 year ago

In the meantime, I did find a workaround that works for me, which is to 'rotate' the scheduled charging so the car never starts on its own.

At 00:00 -> move scheduled charging to 15:00 at 12:00 -> move scheduled charging to 03:00

The automation works by rescheduling charging ahead of reaching its scheduled time. That way there is some margin and the car never gets close enough to its scheduled charging time to start. From then on, you can start/stop the charger through other automations without issues.

alias: Rotate Tesla scheduled charging
description: Prevents the car from automatically starting the charger
trigger:
  - platform: time
    at: "00:00:00"
    id: midnight
  - platform: time
    at: "12:00:00"
    id: noon
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: midnight
        sequence:
          - service: tesla_custom.api
            data:
              command: SCHEDULED_CHARGING
              parameters:
                path_vars:
                  vehicle_id: <YOUR ID>
                enable: true
                time: 900
                wake_if_asleep: true
      - conditions:
          - condition: trigger
            id: noon
        sequence:
          - service: tesla_custom.api
            data:
              command: SCHEDULED_CHARGING
              parameters:
                path_vars:
                  vehicle_id: <YOUR ID>
                enable: true
                time: 180
                wake_if_asleep: true
mode: single

Please note that if the car is charging while the scheduled time is being moved, the car might stop charging. For me this is not an issue since I check the charger state every few minutes and adjust when necessary

craigrouse commented 1 year ago

@mtieltjes Thanks so much for confirming. They have definitely had other reports (they also claim my report is with the engineering team), and Octopus Energy are also talking to them about it. Thanks also for sharing the automation details - I haven't had time to set this up yet, so you've saved me some effort. Did you speak to them only through the chat in the app, or do you have another line of communication with them?

mtieltjes commented 1 year ago

I started the report through the in-app service request, providing the same screenshots as I posted in the opening post here. Here's the timeline:

Feb 23rd, service request created with detailed information about the issue I'm experiencing. Feb 24th they called me, asking for any external influences like 3rd party apps and asked me to disable them and test again over the weekend to rule out any 3rd party causes. A new call was scheduled on the 27th to discuss any findings. Feb 27th we had another call, after which I provided them with new timestamps of the weekend. They took this internal and would call me once they knew more. Mar 1st they returned the call telling me they acknowledge the issue and forwarded it to engineering. We agreed on waiting 2-3 updates and report again if nothing changes.

The service request is now closed.

As a potential workaround they suggested lowering the charging limit if the car shouldn't be charging. For me personally that wouldn't be enough as I also want to control the charging times below 50% (which is the minimum limit)

craigrouse commented 1 year ago

@mtieltjes Someone from Tesla called me this morning, and confirmed it's definitely a firmware bug, and they're looking into it. He checked my car and confirmed there was nothing untoward. It was nice that they bothered to phone me, anyway.

Your automation is working well for me, but I spotted that it wasn't working if the car was away from home. I forgot that the schedule is location-aware, which explains it. I've modified the automation slightly to wait till the car comes home if it's currently away.

juicejuice commented 1 year ago

In case this helps anyone, here is an FAQ and solution from ChargeHQ app website: https://chargehq.net/kb/tesla-random-charging-start-issue. Similar to @mtieltjes their recommendation is to use the scheduled charging features to override the random charging.