TMC is an independent, primarily volunteer organization that relies on ad revenue to cover its operating costs. Please consider whitelisting TMC on your ad blocker and becoming a Supporting Member. For more info: Support TMC

Model S REST API

Discussion in 'Model S: User Interface' started by timdorr, Feb 2, 2013.

  1. dpskipper

    dpskipper Developer

    Joined:
    Aug 4, 2016
    Messages:
    186
    Location:
    Australia
    Yep they work.
    How are you sending the API request? More often than not your implementation is wrong.
     
  2. nasatech

    nasatech Member

    Joined:
    May 19, 2016
    Messages:
    263
    Location:
    Oslo
    Thank you for replying :)

    I use this: https://owner-api.teslamotors.com/api/1/vehicles/<vehicleid>/command/actuate_trunk?which_trunk=rear

    All other commands work.
     
  3. mianesva

    mianesva Member

    Joined:
    Oct 2, 2018
    Messages:
    6
    Location:
    NH

    Your request likely looks like:

    POST /api/1/vehicles/zzzzzzz/command/actuate_trunk?which_trunk=rear HTTP/1.1
    User-Agent: yyyyy
    Authorization: Bearer xxxxx
    Host: owner-api.teslamotors.com
    Connection: close
    Content-Length: 0


    with your values for x,y,z....

    I duplicated your current result of:

    {"response":{"reason":"invalid_value","result":false}}


    Instead of passing the commend as parameter on the url just pass them as value in the body. Note the additional Content-Type header and its value to indicate the type of data you are passing in the body for the POST request

    POST /api/1/vehicles/zzzzzz/command/actuate_trunk HTTP/1.1
    User-Agent: yyyyy
    Authorization: Bearer xxxxxx
    Content-Type: application/json
    Host: owner-api.teslamotors.com
    Connection: close
    Content-Length: 22

    {"which_trunk":"rear"}


    Which yields a valid response:

    {"response":{"reason":"","result":true}}
     
    • Helpful x 1
  4. nasatech

    nasatech Member

    Joined:
    May 19, 2016
    Messages:
    263
    Location:
    Oslo
    Perfect! Got it working. Thanks :)
     
  5. hans

    hans P631

    Joined:
    Sep 27, 2012
    Messages:
    1,132
    Location:
    Menlo Park
    I have done an `npm publish` of the latest teslams.js (version 1.3.0) so it should work from either source on github or via `npm install`.

    Special thanks to cbrandlehner for the fix.
     
  6. ACDriveMotor

    ACDriveMotor Member

    Joined:
    Aug 11, 2013
    Messages:
    865
    Location:
    Seattle, WA
    Tesla Control lets you schedule start and stop times. It’s done with background tasks.
     
  7. lonertic

    lonertic Member

    Joined:
    Feb 2, 2017
    Messages:
    29
    Location:
    Sydney
    I can find the start/stop charging commands (no details about what the httpbody payload should be though?)... however, is there such a command that could set the charging current remotely? I haven't seen one in the official app but I'm wondering if an API for it exists (or if someone managed to sniff one out)?
     
  8. Dazboj

    Dazboj Member

    Joined:
    May 9, 2017
    Messages:
    76
    Location:
    UK
    Unfortunately not. This is a holy grail I have been waiting for (And tweeting Elon).
    If the API allowed us to set the charge rate, I could utilise much more of my solar export by keeping the charge rate the same as solar excess.
     
    • Love x 1
  9. lonertic

    lonertic Member

    Joined:
    Feb 2, 2017
    Messages:
    29
    Location:
    Sydney
    EXACTLY the reason why I asked for it too :) Tweet him again, I'd imagine we're not the only ones thinking about this... Since my solar inverter can't work in island mode, and I can't send any predetermined amount of power towards the car first before exporting excess, having the car "pull" a corresponding amperage out of the inverter in line with solar output seems to make a lot of sense!

    I'm guessing you already tried obvious stuff like command/set_charge_current (as opposed to set_charge_limit) just to see if the API actually exists right? (i just tested it now, got a 400 bad request).. that makes me think, i wonder what other hidden APIs there are.. possible able to just guess a bunch i think
     
  10. dpskipper

    dpskipper Developer

    Joined:
    Aug 4, 2016
    Messages:
    186
    Location:
    Australia
    Mate it doesn't exist
     
  11. markb1

    markb1 Active Member

    Joined:
    Feb 17, 2012
    Messages:
    2,816
    Location:
    San Diego, CA
    There's a different way to achieve this, by using the load sharing protocol of the Tesla Wall Connector. (This requires wiring something to the wall connector.) There's a thread here:

    New Wall Connector load sharing protocol

    And source code here:

    cdragon/TWCManager
     
  12. lonertic

    lonertic Member

    Joined:
    Feb 2, 2017
    Messages:
    29
    Location:
    Sydney
    Nice! But unfortunately my car is 2015, so is my HPWC... so I can only assume it's the "older" model with older firmware/hardware that can't run that... and it wouldn't be as precise as the car controlling draw either, because HPWC selector is still in stepped amps, whereas car is single digit amp changes... really wish an API was available! :( What about canbus message within the car? anyone?
     
  13. markb1

    markb1 Active Member

    Joined:
    Feb 17, 2012
    Messages:
    2,816
    Location:
    San Diego, CA
    It requires a second generation wall connector, but I believe it will work with any Model S/X/3.
     
  14. dpskipper

    dpskipper Developer

    Joined:
    Aug 4, 2016
    Messages:
    186
    Location:
    Australia
    That's doable, as the car is the one that talks to EVSE and requests the current
     
  15. insaneoctane

    insaneoctane Active Member

    Joined:
    Apr 6, 2016
    Messages:
    2,655
    Location:
    Southern California
    Don't know if anyone here cares, but the newest firmware 46.x changed the timestamp format for charging start time again. It's back to long-UNIX style UTC, no longer readable with the "T" in the middle. Re-broke some of my scripts after the update. Just had to go back to before Nov. 2 to see what I had changed so that I could undo it.
     
    • Informative x 1
    • Funny x 1
  16. ACDriveMotor

    ACDriveMotor Member

    Joined:
    Aug 11, 2013
    Messages:
    865
    Location:
    Seattle, WA
    I had coded Tesla Control to handle both formats guessing they would switch back at some point.
     
    • Like x 1
  17. SG57

    SG57 Former Vendor

    Joined:
    Jul 24, 2016
    Messages:
    400
    Location:
    Spokane, WA
    So I'm digging into the latest app version and like the new nearby charging station APIs.

    Endpoint: api/1/vehicles/{vehicle_id}/nearby_charging_sites
    Method: GET
    * Bearer Token auth header required

    Response Sample:

    Code:
    {
       "response":{
          "congestion_sync_time_utc_secs":1545270496,
          "destination_charging":[
             {
                "location":{
                   "lat":60.480312,
                   "long":22.327951
                },
                "name":"Unique Home",
                "type":"destination",
                "distance_miles":1.645089
             },
             {
                "location":{
                   "lat":60.460714,
                   "long":22.290152
                },
                "name":"Holiday Club Caribia",
                "type":"destination",
                "distance_miles":2.673828
             },
             {
                "location":{
                   "lat":60.4554,
                   "long":21.9516
                },
                "name":"Kultaranta Resort",
                "type":"destination",
                "distance_miles":14.195284
             },
             {
                "location":{
                   "lat":60.163116,
                   "long":22.732845
                },
                "name":"K-Supermarket Kompass",
                "type":"destination",
                "distance_miles":24.419037
             }
          ],
          "superchargers":[
             {
                "location":{
                   "lat":60.442961,
                   "long":22.605621
                },
                "name":"Paimio, Finland - Tammisilta",
                "type":"supercharger",
                "distance_miles":8.271776,
                "available_stalls":8,
                "total_stalls":8,
                "site_closed":false
             },
             {
                "location":{
                   "lat":61.181106,
                   "long":23.885075
                },
                "name":"Akaa, Finland - Toijala",
                "type":"supercharger",
                "distance_miles":71.047409,
                "available_stalls":8,
                "total_stalls":8,
                "site_closed":false
             }
          ],
          "timestamp":1545271308686
       }
    }

    -

    And on that note, I'm excited my Model S got the latest software update earlier today so I'm gonna try to guess the new seat heater / steering wheel heater control endpoint seeing as the mobile app update with support for it hasn't been released yet. :eek:
     
    • Like x 3
  18. ckoval7

    ckoval7 Mild One

    Joined:
    Sep 19, 2018
    Messages:
    304
    Location:
    Maryland
    I just came here to ask if anyone found it yet! Hopefully we see the app update soon!
     
    • Like x 1
  19. ACDriveMotor

    ACDriveMotor Member

    Joined:
    Aug 11, 2013
    Messages:
    865
    Location:
    Seattle, WA
    Yes, I just got the update as well so I'll be adding support for nearby charging to Tesla Control. I may have missed it, do we know the endpoints for seat heaters yet?
     
    • Like x 1
  20. SG57

    SG57 Former Vendor

    Joined:
    Jul 24, 2016
    Messages:
    400
    Location:
    Spokane, WA
    #2500 SG57, Dec 20, 2018
    Last edited: Dec 20, 2018
    @ACDriveMotor , haven't found it yet. I've tried 50+ different combinations of "set", "heater", "seat", "level", "limit", "heating", "element", etc. If you get a 400 status code it's wrong, if you get anything else then we're in business.

    There's a chance Tesla doesn't enable the endpoint until the 3.8.0 app release as well.
     

Share This Page

  • About Us

    Formed in 2006, Tesla Motors Club (TMC) was the first independent online Tesla community. Today it remains the largest and most dynamic community of Tesla enthusiasts. Learn more.
  • Do you value your experience at TMC? Consider becoming a Supporting Member of Tesla Motors Club. As a thank you for your contribution, you'll get nearly no ads in the Community and Groups sections. Additional perks are available depending on the level of contribution. Please visit the Account Upgrades page for more details.


    SUPPORT TMC