tesla-api icon indicating copy to clipboard operation
tesla-api copied to clipboard

Add support for Calendar API

Open mseminatore opened this issue 9 years ago • 11 comments

mseminatore avatar Apr 25 '16 22:04 mseminatore

I don't believe there is an API, it's the iPhone app syncing with the car directly.

dewski avatar Apr 25 '16 23:04 dewski

Yep, @dewski is correct. The connection is done directly via Bluetooth.

timdorr avatar Apr 26 '16 02:04 timdorr

there is an API, the bluetooth connection is just controlling which calendar the car will display

ahimberg avatar Apr 26 '16 02:04 ahimberg

there is an API, the bluetooth connection is just controlling which calendar the car will display

The car says you need to keep the phone backgrounded. Do you have any requests/responses that support an API?

dewski avatar Apr 26 '16 04:04 dewski

Here’s a sample from 2014 when I first hooked it up. The official apps send just a couple days worth of data. I never set up background tasks in my app and just have a manual push at the moment.

POST https://owner-api.teslamotors.com/api/1/vehicles/###########/command/upcoming_calendar_entries HTTP/1.1
Content-Type: application/json; charset=utf-8
Authorization: Bearer xxx
Content-Length: 444
Host: owner-api.teslamotors.com
Connection: Keep-Alive
User-Agent: Model S 1.1.72 (Nexus 5; Android REL 4.4.4; en_US)
Accept-Encoding: gzip,deflate

{"calendar_data":{"access_disabled":false,"calendars":[{"color":"ff9a9cff","events":[{"color":"ff9a9cff","location":"1 LaLa St, Fremont CA","start":1411941600000,"organizer":"[email protected]","name":"Testlled":false,"all_day":false,"tentative":false,"end":1411945200000}],"name":"[email protected]"},{"color":"ff71aea7","[email protected]"}],"phone_name":"Nexus 5","uuid":"333239059961777"}}

This is for an event from 3-4pm on Sunday 9/28/2014, with a Red category color on the appointment. in this same I had 2 accounts on the device with calendars but only 1 had events coming up. btw the colors don't seem to be used by the car right now, and not all fields are required (organizer at least isn't always available in a calendar item and its worked to send blank)

Note the times here are milliseconds since 1970 (vs seconds since 1970 for the scheduled timer time) For the phone name, it appears just one of the name or id need to match, so what I did was have the user set up the phone name manually and send some random unique value as the uuid, which seems to work (neither value is exposed to apps on Windows Phone, well at least in the older APIs, uuid is available in WinPhone 8.1 apps but I still support 7.5 with my app)

ahimberg avatar Apr 26 '16 04:04 ahimberg

That looks valid. Sorry for closing so quickly.

The phone_name is most likely the Bluetooth name for the phone. That's what the Summon and Homelink APIs use. I'll check the Android source for that uuid field. It's probably a hash of some stuff (BT name, broadcast MAC, etc etc).

timdorr avatar Apr 26 '16 04:04 timdorr

Yes, thanks Andy this is great info. Is the Bluetooth name typically what the car displays as the phone name?

mseminatore avatar Apr 26 '16 04:04 mseminatore

@mseminatore Yes, it's the Bluetooth name. On Android, you can set this via the Bluetooth settings. I believe on iOS, it's pulled from the name of the device (which applies in multiple contexts).

timdorr avatar Apr 26 '16 04:04 timdorr

Hey Andy,

The JSON you shared looks like it may have some errors. Specifically "name:Testled:false" and "[email protected]" without a key. Would you mind re-pasting?

{"calendar_data":{"access_disabled":false,"calendars":[{"color":"ff9a9cff","events":[{"color":"ff9a9cff","location":"1
LaLa St, Fremont CA","start":1411941600000,"organizer":"[email protected]
","name":"Testlled":false,"all_day":false,"tentative":false,"end":1411945200000}],"name":"
[email protected]"},{"color":"ff71aea7","[email protected]"}],"phone_name":"Nexus
5","uuid":"333239059961777"}}

mseminatore avatar Apr 29 '16 22:04 mseminatore

@ahimberg @timdorr Still looking to get some working calendar code. If anyone has valid POST payload for a calendar command that would be greatly appreciated!

mseminatore avatar Dec 03 '16 21:12 mseminatore

Hi @mseminatore and @timdorr I piped the json-code above through jq . on my Linux-machine, but jq complained about several syntax errors. After some tweaking, I managed to make this, which at least are legal json-syntax:

{
  "calendar_data": {
    "access_disabled": false,
    "calendars": [
      {
        "color": "ff9a9cff",
        "events": [
          {
            "color": "ff9a9cff",
            "location": "1 LaLa St, Fremont CA",
            "start": 1411941600000,
            "organizer": "[email protected]",
            "name": "Testlled",
            "all_day": false,
            "tentative": false,
            "end": 1411945200000
          }
        ],
        "name": "[email protected]"
      },
      {
        "color": "ff71aea7",
        "name": "[email protected]"
      }
    ],
    "phone_name": "Nexus 5",
    "uuid": "333239059961777"
  }
}

karekaa avatar Dec 04 '19 16:12 karekaa