Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle sleep behavior of MCU2 upgraded cars #3262

Closed
wants to merge 34 commits into from

Conversation

micves
Copy link
Contributor

@micves micves commented Jun 26, 2023

There is a lot more info in this issue: #3084

The short story is:
Older cars upgraded to MCU2 have a little wakeup every hour to check subsystems.
They report online but if vehicle_data is requested they wake up completely (cars clicks) and is awake for 15 minutes instead of a 2-3 minutes.
The only difference (known at this moment) is stream reports power=nil in subsystem online and reports power as a number when it is a real online.

Fix implemented by staying in state :start when online is detected on non-vehicle_data.
Stream receives data and new variable fake_online is set dependent on power is nil or a number.
The variable fake_online is used to decide whether to get only non-vehicle_data or the full blown wakeup vehicle_data
In suspended only non-vehicle_data is allowed to be better at going to sleep. Usage is detected if power>0 to go back to online state.

Other things:

  • Handle stream getting vehicle offline and change to state :offline in vehicle
  • Try to suspend in online when getting error on fetch_result
    This will lay of vehicle_data and use non-vehicle_data instead and
    hopefully not keep the car awake when errors suddenly stop again
  • I'm not quite into nice coding guidelines for Elixir, so some code-review might be good :)
  • I don't have possibility to test on other types of cars than my own 2017 Model S with upgraded MCU2.

micves and others added 6 commits May 27, 2023 22:45
…check subsystems.

They report online but if vehicle_data is requested they wake up completely (cars clicks) and is awake for 15 minutes instead of a 2-3 minutes.
The only difference (known at this moment) is stream reports power=nil in subsystem online and reports a power as a number when it is a real online.

Stay in state :start when online is detected on non-vehicle_data
stream receives data and new variable fake_online is set dependent on power is nil or a number

There are still some TODO's around the code.

Also handle stream getting vehicle offline and change to state offline in vehicle
…te is offline or asleep.

Before it caused a vehicle_data request in suspended even though not intended (since it actually went to state start where vehicle_data is allowed when false_online=false, which it is in online and suspended)

Added a clause in suspended if power > 0 to go back to online (e.g. if climate is turned on remotely with app.
That works, not sure if opening door without climate on is enough to trigger this (power seems to be integers, but hopefuly rounded up)
This will lay of vehicle_data and use non-vehicle_data instead and
hopefully not keep the car awake when errors suddenly stop again

Changed some comment and logger texts
Could otherwise give a irrelevant warning from try_to_suspend function. (E.g. User present)
@JakobLichterfeld JakobLichterfeld added area:tesla api Related to the Tesla API area:teslamate Related to TeslaMate core labels Nov 16, 2023
@oivindoh
Copy link
Contributor

This is Beautiful - I've been wondering about this for a couple of years now but never thought to dig more into why the MCU2 upgraded car behaved differently to the other MCU2 car in the account

@micves
Copy link
Contributor Author

micves commented Nov 19, 2023

Would it make sense to make different PR's to the things that are not directly related to the MCU2 issue?
Especially the first to points in the PR description/comment under "other things":

  • Handle stream getting vehicle offline and change to state :offline in vehicle
  • Try to suspend in online when getting error on fetch_result
    This will lay of vehicle_data and use non-vehicle_data instead and
    hopefully not keep the car awake when errors suddenly stop again

Just to make it easier to review this, but also for me to actually get CI tests working for both this MCU2 issue and the other things

@USAFPride
Copy link

Is this PR still active?

@micves
Copy link
Contributor Author

micves commented Nov 19, 2023

Is this PR still active?

Yes, it just fails some of the workflow tests, so I think I need to figure that out.

Besides that I once in a while merge teslamate:master in to keep the PR up-to-date

@USAFPride
Copy link

USAFPride commented Nov 24, 2023

Currently installing 2023.38.9. Will report back

Works fine with 2023.38.9

@oivindoh
Copy link
Contributor

I can’t see any runs on this PR - @JakobLichterfeld do we have any elixir gurus who could take a look at this one?

@JakobLichterfeld
Copy link
Collaborator

I can’t see any runs on this PR - @JakobLichterfeld do we have any elixir gurus who could take a look at this one?

Run needs manual approval. I didn't push the button till now since this branch seems outdated in regards to workflow files

@micves
Copy link
Contributor Author

micves commented Nov 26, 2023

I just synced the fork, but I know from last run that there are a lot of test failures.
I just set up an test environment next to my running environment to try to fix those failures.

Previously I used WSL on windows for test, but it seems to fail even on master.
I think there is some timing that doesn't match. And it's also insanely slow to test on WSL

Copy link

netlify bot commented Dec 7, 2023

Deploy Preview for teslamate ready!

Name Link
🔨 Latest commit 21e1fc2
🔍 Latest deploy log https://app.netlify.com/sites/teslamate/deploys/673198a519a4010008bba59b
😎 Deploy Preview https://deploy-preview-3262--teslamate.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@USAFPride
Copy link

Can we get this merged into the master?

@JakobLichterfeld
Copy link
Collaborator

JakobLichterfeld commented Dec 19, 2023

Can we get this merged into the master?

Once our 321 test cases run successfully and we are sure that we are not breaking anything with non-MCU2 upgraded cars, the answer will be yes.

@JakobLichterfeld JakobLichterfeld added the note:needs investigation The issue must be investigated first label Dec 19, 2023
@JakobLichterfeld JakobLichterfeld marked this pull request as draft December 19, 2023 13:08
brianmay pushed a commit that referenced this pull request Jan 2, 2025
brianmay pushed a commit that referenced this pull request Jan 2, 2025
JakobLichterfeld added a commit that referenced this pull request Jan 3, 2025
changes from @micves from #3262

Co-authored-by: Jakob Lichterfeld <[email protected]>
brianmay pushed a commit that referenced this pull request Jan 3, 2025
brianmay pushed a commit that referenced this pull request Jan 3, 2025
brianmay pushed a commit that referenced this pull request Jan 3, 2025
brianmay pushed a commit that referenced this pull request Jan 4, 2025
brianmay pushed a commit that referenced this pull request Jan 4, 2025
brianmay pushed a commit that referenced this pull request Jan 4, 2025
brianmay pushed a commit that referenced this pull request Jan 5, 2025
power > 0 is when e.g. the climate is on which could be scheduled
preconditioning or starting preheat from the app.

This code will make sure it doesn't enter 'trying to sleep' (the internal state
suspended) when power > 0.

changes from @micves from #3262
brianmay pushed a commit that referenced this pull request Jan 5, 2025
…o online

When power > 0.

power > 0 is when e.g. the climate is on which could be scheduled preconditioning or starting preheat from the app.

changes from @micves from #3262
brianmay pushed a commit that referenced this pull request Jan 5, 2025
Only goes to Charging when the car is plugged in (power < 0) and its not preconditioning or in dog mode.

changes from @micves from #3262
brianmay pushed a commit that referenced this pull request Jan 5, 2025
brianmay pushed a commit that referenced this pull request Jan 5, 2025
…o online

When power > 0.

power > 0 is when e.g. the climate is on which could be scheduled preconditioning or starting preheat from the app.

changes from @micves from #3262
brianmay pushed a commit that referenced this pull request Jan 5, 2025
Only goes to Charging when the car is plugged in (power < 0) and its not preconditioning or in dog mode.

changes from @micves from #3262
brianmay pushed a commit that referenced this pull request Jan 5, 2025
brianmay pushed a commit that referenced this pull request Jan 6, 2025
power > 0 is when e.g. the climate is on which could be scheduled
preconditioning or starting preheat from the app.

This code will make sure it doesn't enter 'trying to sleep' (the internal state
suspended) when power > 0.

changes from @micves from #3262
brianmay pushed a commit that referenced this pull request Jan 6, 2025
…o online

When power > 0.

power > 0 is when e.g. the climate is on which could be scheduled preconditioning or starting preheat from the app.

changes from @micves from #3262
brianmay pushed a commit that referenced this pull request Jan 6, 2025
Only goes to Charging when the car is plugged in (power < 0) and its not preconditioning or in dog mode.

changes from @micves from #3262
brianmay pushed a commit that referenced this pull request Jan 6, 2025
senmizu pushed a commit to senmizu/teslamate_cn that referenced this pull request Jan 14, 2025
senmizu pushed a commit to senmizu/teslamate_cn that referenced this pull request Jan 14, 2025
power > 0 is when e.g. the climate is on which could be scheduled
preconditioning or starting preheat from the app.

This code will make sure it doesn't enter 'trying to sleep' (the internal state
suspended) when power > 0.

changes from @micves from teslamate-org#3262
senmizu pushed a commit to senmizu/teslamate_cn that referenced this pull request Jan 14, 2025
…o online

When power > 0.

power > 0 is when e.g. the climate is on which could be scheduled preconditioning or starting preheat from the app.

changes from @micves from teslamate-org#3262
senmizu pushed a commit to senmizu/teslamate_cn that referenced this pull request Jan 14, 2025
Only goes to Charging when the car is plugged in (power < 0) and its not preconditioning or in dog mode.

changes from @micves from teslamate-org#3262
senmizu pushed a commit to senmizu/teslamate_cn that referenced this pull request Jan 14, 2025
senmizu pushed a commit to senmizu/teslamate_cn that referenced this pull request Jan 14, 2025
power > 0 is when e.g. the climate is on which could be scheduled
preconditioning or starting preheat from the app.

This code will make sure it doesn't enter 'trying to sleep' (the internal state
suspended) when power > 0.

changes from @micves from teslamate-org#3262
senmizu pushed a commit to senmizu/teslamate_cn that referenced this pull request Jan 14, 2025
…o online

When power > 0.

power > 0 is when e.g. the climate is on which could be scheduled preconditioning or starting preheat from the app.

changes from @micves from teslamate-org#3262
senmizu pushed a commit to senmizu/teslamate_cn that referenced this pull request Jan 14, 2025
Only goes to Charging when the car is plugged in (power < 0) and its not preconditioning or in dog mode.

changes from @micves from teslamate-org#3262
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:tesla api Related to the Tesla API area:teslamate Related to TeslaMate core elixir Pull requests that update Elixir code enhancement New feature or request note:help wanted Extra attention is needed note:needs investigation The issue must be investigated first
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Missing sleep state, long wake times and errors in log with MCU2 updated cars