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. markb1

    markb1 Active Member

    Joined:
    Feb 17, 2012
    Messages:
    2,985
    Location:
    San Diego, CA
    Some recent software update (presumably) on my Model S has broken my streaming script. Now, when I send a subscribe message, I simply get no response. It doesn't seem to matter if the car is asleep or awake. It seems much like how it behaves for Model 3, which I don't think anyone has figured out, so I don't have a lot of hope. But does anyone have any ideas?
     
  2. Dan203

    Dan203 Active Member

    Joined:
    Jul 10, 2019
    Messages:
    1,230
    Location:
    Northern Nevada
    Does anyone know what the end point...

    /api/1/users/command_token

    does?

    I figured out that if you send it your user name and password as JSON, like the auth function, you get a 200 OK with this...


    {
    "response": "ReallyLongStringThatIAssumeIsAKeyToSomething"
    }

    I tried using the returned string as an auth token and it wasn't valid. Not sure what it's for
     
  3. pjw65

    pjw65 Member

    Joined:
    Mar 19, 2016
    Messages:
    207
    Location:
    Switzerland
    As of Tesla JSON API there a some other "users" commands like "Powerwall order", "Service scheduling", "Referral data", "Roadside Assistance". What do they have in common?
    From the "Endpoints File" of the link above:

    Code:
     "POWERWALL_ORDER_SESSION_DATA": {
        "TYPE": "GET",
        "URI": "api/1/users/powerwall_order_entry_data",
        "AUTH": true
      },
      "POWERWALL_ORDER_PAGE": {
        "TYPE": "GET",
        "URI": "powerwall_order_page",
        "AUTH": true,
        "CONTENT": "HTML"
      },
      "ONBOARDING_EXPERIENCE": {
        "TYPE": "GET",
        "URI": "api/1/users/onboarding_data",
        "AUTH": true
      },
      "ONBOARDING_EXPERIENCE_PAGE": {
        "TYPE": "GET",
        "URI": "onboarding_page",
        "AUTH": true,
        "CONTENT": "HTML"
      },
      "SERVICE_SELF_SCHEDULING_ELIGIBILITY": {
        "TYPE": "GET",
        "URI": "api/1/users/service_scheduling_data",
        "AUTH": true
      },
      "SERVICE_SELF_SCHEDULING_PAGE": {
        "TYPE": "GET",
        "URI": "service_scheduling_page",
        "AUTH": true,
        "CONTENT": "HTML"
      },
      "REFERRAL_DATA": {
        "TYPE": "GET",
        "URI": "api/1/users/referral_data",
        "AUTH": true
      },
      "REFERRAL_PAGE": {
        "TYPE": "GET",
        "URI": "referral_page",
        "AUTH": true,
        "CONTENT": "HTML"
      },
      "ROADSIDE_ASSISTANCE_DATA": {
        "TYPE": "GET",
        "URI": "api/1/users/roadside_assistance_data",
        "AUTH": true
      },
      "ROADSIDE_ASSISTANCE_PAGE": {
        "TYPE": "GET",
        "URI": "roadside_assistance_page",
        "AUTH": true,
        "CONTENT": "HTML"
      },
     "AUTH_COMMAND_TOKEN": {
        "TYPE": "POST",
        "URI": "api/1/users/command_token",
        "AUTH": true
      },
      "SEND_DEVICE_KEY": {
        "TYPE": "POST",
        "URI": "api/1/users/keys",
        "AUTH": true
      },
     
  4. Dan203

    Dan203 Active Member

    Joined:
    Jul 10, 2019
    Messages:
    1,230
    Location:
    Northern Nevada
    I think they are things linked to the user and not a specific device.
     
  5. m3-ricardo

    m3-ricardo Member

    Joined:
    Oct 21, 2019
    Messages:
    155
    Location:
    Seattle
    I love the idea of using a real-world analog gauge for this .

    you can figure out the actual power used by logging the charging_state.charger_power field.

    it gives you the instant power being drawn from the wall . you have to do some math to figure out the actual kwh that were drawn over time .. you can then do chaging_state.charge_power_added / power_used to get efficiency if you care for that.. or calculate your costs for power using the power drawn rather than power added.
     
  6. John Rucker

    John Rucker Member

    Joined:
    Sep 4, 2019
    Messages:
    34
    Location:
    Illinois

    Yep I can also get access to the charger's instant voltage and current. This is on the AC side and if I use Volts times Current = Power I get the same number as charger_power. The problem with this is I poll the car for that data ever minute and that only gives me a snap shot of the AC voltage and current at that moment. I could just assume that the current and voltage was the same for the time period between polls and could probably get pretty close. But at best it is still a guess of what is going on between my poll cycles.

    So that is why I was looking for some percentage of overhead I could just add to the DC kWh being added to the battery. When I installed my home charger I put it behind a dedicated (calibrated) power meter. So what I did for about a month was just recorded the kWh readings from my dedicated meter and compared it to the DC kWh reported by my model X. Turns out there is an 8 to 10% overhead (90% to 92% efficiency ). So I just add 10% to my calculations to get my meter closer to really what is being used.

    It is cool having the information displayed on a wall gage. Every morning we take a quick peek at the gauge and see what it cost to drive the car the previous day. A trip to WallMart and back in the winter can cost $1.25 but in the summer it is $0.75.

    Just a FYI
    We have a 7kW solar system at home and the next gauge I want to make will compare our solar generated kWh to the Tesla kWh used for charging. Our local electric here in down state Illinois is from coal & natural gas. It would be cool to know if I'm driving on sunshine or coal.

    Thanks for the input!!
     
  7. scottmbritton

    scottmbritton New Member

    Joined:
    Jan 9, 2020
    Messages:
    3
    Location:
    Texas
    Looking for some assistance with API commands to start and stop charging. I have tried a tasker plugin and also home assistant Tesla integration and everything seems to work except starting and stopping charging. I have been able to unlock doors, honk the horn, turn on and off climate control, adjust charge limit (set to max and set from 50% to 90%). When I send the commands to stop charging I get a 200 response and "result": true response but the charging does not stop.

    Instead of using the apps I mentioned before I ended up doing some tests with Tesla Owner JSON API · Apiary and have the same results. I have been able to get everything to work except for stopping and starting charging. As a work around if I set the charge limit to the lowest it will go, which looks like 50% and the car has charged past that limit already it will stop charging. When I set the limit higher than what it is at it will start charging again but this isn't the best solution because if it is less than 50% charged it will continue charging.

    Using the Tesla android app I am able to stop and start charging so it works from there but not using any API calls. In searching and talking to the Tasker plugin author, I seem to be the only person that has this issue. Does anyone have any suggestions? Thanks.

    I have a 2016, MS 90D.
     
  8. scottmbritton

    scottmbritton New Member

    Joined:
    Jan 9, 2020
    Messages:
    3
    Location:
    Texas
    After setting up a packet capture I noticed that the Tesla App isn't actually working either. Commands are sent and the app looks like it stopped charging but after a minute the Tesla app updates and says it is still charging. Watching the car when I try to stop charging using the Tesla App, the charging is never actually interrupted at all. So I'll have to work with Tesla on why their Android app isn't working for me. I'm sure after that is resolved the API calls will work as well. Thanks
     

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