Welcome to Tesla Motors Club
Discuss Tesla's Model S, Model 3, Model X, Model Y, Cybertruck, Roadster and More.
Register

Model S Amazon Echo Integration

This site may earn commission on affiliate links.
That resolved the error, but 2 things: I noticed that there are several references to 'charge_state' in application.py - I wonder if they all need to be changed? Also, although this resolved the error, it returns the temperature of the car -- only in the Amazon Service Simulator though. It works as it should with an actual Alexa. Weird.
I think you may be okay in the other instances. The charge_state is confusing as charge_state is part of the URL that you send to Tesla to get the whole dump of info on the charge, but the key in the JSON data is actually called 'charging_state'.

I don't know about the other issues - most of them are working for me. But there can be issues around local time zones, etc. that could be causing the issues.
 
I got the 401 error until I just switched to using my oauth key instead. (still haven't been able to get it to work with the username and password)

@wayner reports that dropping the quote marks around TESLA_USER and TESLA_PASSWORD in Line 36 of application.py may fix this. It should read:

tesla_connection = teslajson.Connection(TESLA_USER, TESLA_PASSWORD)

The Dedham Service Center is holding my Model X "hostage" (routine service that turned into a two-week stay), so I can't readily test this. But I will update the application.py file in the repository
 
@wayner reports that dropping the quote marks around TESLA_USER and TESLA_PASSWORD in Line 36 of application.py may fix this. It should read:

tesla_connection = teslajson.Connection(TESLA_USER, TESLA_PASSWORD)

The Dedham Service Center is holding my Model X "hostage" (routine service that turned into a two-week stay), so I can't readily test this. But I will update the application.py file in the repository
Unfortunately, I made those changes and still no luck. I've run out of brain power for the day ;)but tomorrow I'll take a shot at getting the oauth method working.
 
@wayner revealed to me something overnight that affects Model S users of the Nikola skill code quite a bit. He reports that Model S does not report internal or external temperatures with the climate controls off via API, thought Model X does. Since Nikola was developed for my Model X, the functions work great -- but they can fail on the Model S. I was frankly not aware there was a difference, though I also wonder whether that is still true for newly-built Model S vehicles.

This affects all of the temperature, climate, and status functions.

Fair warning -- some refactoring will be necessary to get this skill fully working for Model S.
 
  • Informative
Reactions: sbtz
@wayner revealed to me something overnight that affects Model S users of the Nikola skill code quite a bit. He reports that Model S does not report internal or external temperatures with the climate controls off via API, thought Model X does. Since Nikola was developed for my Model X, the functions work great -- but they can fail on the Model S. I was frankly not aware there was a difference, though I also wonder whether that is still true for newly-built Model S vehicles.

This affects all of the temperature, climate, and status functions.

Fair warning -- some refactoring will be necessary to get this skill fully working for Model S.

When my S has been idle for long, the interior/exterior temp doesn't report in TeslaFi. That said, I know my Model S will periodically check that data because sometimes I'll open the app in the middle of the day and a temp is displayed rather than be unavailable until I turn on climate controls. I have a classic/pre-autopilot S.
 
When my S has been idle for long, the interior/exterior temp doesn't report in TeslaFi. That said, I know my Model S will periodically check that data because sometimes I'll open the app in the middle of the day and a temp is displayed rather than be unavailable until I turn on climate controls. I have a classic/pre-autopilot S.
Thanks for that additional info. I'm going to make a change today that can handle the case where a temperature query returns "None", so that the app reports that "Temperatures for your car are currently unavailable." That's better than failing.
 
  • Like
Reactions: Cyclone
My fork of the Echo Skill is ready for testing GitHub - wayner9/nikola-tesla-alexa: Nikola: An Alexa Skill for interacting with a Tesla Automobile. See the instructions on the github readme for how to use this.

I have largely taken the work of Michael Kolowich and made a few changes. Since I am in Canada my code is a little more adapted to cars outside of the US, namely it will return the province name for Canada (but if you are in the US you will still get the state name) and it can also report distances in either miles or kms. When running the python code you supply your email and password so you never have to store those in the cloud.

I think I have fixed a few bugs but I probably introduced a few as well.

I would highly recommend that you try out this Flask-ask tutorial to learn more about how to set up an Echo Skill Flask-Ask: A New Python Framework for Rapid Alexa Skills Kit Development : Amazon Developer Blogs. My methodology for the Tesla skill leverages off of that.

This skill also works without requiring a cloud server of any type as the code runs on your local computer. You also never have to give out your password - you just enter it as an argument in the command line when running the program.

Please give me any feedback.
 
Ok, I think I got this - you can redownload the nikola.py file or just remove the quotes from around tempunits in line 370 of the file.
I'm a bit confused, as now it's not working for any case (even after changing it back). I have no Python experience (although I do know a few languages) so I haven't yet figured out what's going on, but I'm still poking around.

Here is the stack dump:

Code:
  File "C:\Tools\TeslaEcho\nikola.py", line 343, in GetStatus
    FetchTemps(tempunits)
  File "C:\Tools\TeslaEcho\nikola.py", line 204, in FetchTemps
    inside_temp= ConvertTemp(data['inside_temp'], scale)
  File "C:\Tools\TeslaEcho\nikola.py", line 194, in ConvertTemp
    temperature = (temperature * 1.8) + 32
TypeError: unsupported operand type(s) for *: 'NoneType' and 'float'

It looks somewhat like perhaps the temperature in the data structure is stored as a string, and you need to cast it to a numeric value first, but I could be way off.
 
Another thing I noticed - the ClimateStart commands issue a voice response, but the climate system doesn't actually get turned on. I can issue a command several times in a row, and each time I get this response:

"OK, I have started your car's climate system."
 
More information. The reason for the errors is that the values for inside_temp and outside_temp were none, or null, or however Python refers to this. I figured this out because when I asked for temperatures, I kept getting this response:

"I can't get the temperatures right now. Try turning on the climate and trying again"

That made me think that the temperature variables weren't getting set, so I tried an experiment. I went to the car and opened the door to wake it up. Then I came back and did the quick and full status queries again, as well as asking for the temperature, and they all worked.
 
Ok, I fixed the ClimateStart issue and I think I have the temperature issue now.

The problem is that sometimes the Tesla API returns None in the JSON string for the inside and outside temperatures. This get read into Python as a special kind of variable with a None type that isn't a string, it is kind of like a Null variable. I think I am now checking for that. But I use Celsius and Celsius is what is returned by the car so it would just be reported as None or ignored, which is what we have the code do. But when you want Fahrenheit it has to do a conversion which kicks out the error as you can't multiply a None variable.

edit - I fixed the nikola.py file. Download it and try again.