-
Notifications
You must be signed in to change notification settings - Fork 61
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
Exposing more data from the api-calls #52
Comments
Exposing anything in HA would be difficult because of the review process in pushing code. If you describe what you want to specifically have access to in HA that would be easier. There are a bunch of sites that allow you to browser the known Tesla API. The question is to consider how to represent data in HA. |
Listing a few from the top of my mind that could be useful Last successful api-call (timestamp) in combination with state: online/asleep Managing online/asleep would be a good thing (that I do not know enough about yet) |
Thanks. Please think about how they would be displayed in HA. We can easily expose the data you want through the API as it's all collected but the question will be how to properly display it in HA. I have a charging rate sensor PR to try to get more info for charging so I'm not sure if that's what you needed. |
@alandtse your PR looks great.. awake/sleep could be represented by a binary_sensor.tesla_awake ? (I could not find any of the device classes the seems to fit awake/sleep) Is there any guidelines when sensors don't fit devices classes? Like car_version: for instance? |
I just started out using HA and are currently setting up the development environment for it. I'm also interested in this as well as have the ability to read remaining charge time, charge current and turn on or off individual seat heaters. I guess things like on/off of each seat heater should be switches, but everything that is read only seems logical to have registered as sensors, for instance, current location, speed, cabin temperature etc. |
@alandtse your latest PR works fine in the pre-release! Wondering why I always have 2Volts charger voltage even when disconnected :) |
@magnussand We did expose a bunch of the charger related stuff. We don't have the seat heaters yet, but do check the component as some of the other temperature stuff and gps stuff is already exposed. @alandtse Glad to hear. Waiting for it to go live so I can benefit from the work on my production system. ;) |
@tobbensoft Online binary sensor can be easily added by replacing two files in teslajsonpy. EDIT: Btw |
Thank guys for the effort. Problem is: I never succeeded in changing the poll interval in HA during runtime. As far as I saw, it's always 30s but with throttle constraint. Or we can implement this state machine in teslajsonpy. Would be a lot easier and more manageable, avoiding HA approval cycles as mentionned by @alandtse. |
@llluis by the looks of the logs in "teslafi" it seems to be 60s for the /api/1/vehicles/{id} polling. And I assume you mean 300s :) |
Yes, a connector switch has those default naming. Templates will respond with
This is the behavior more or less (but using 300 instead of 60). The tesljsonpy controller updates the online state every So to changes in HA, if you have a
Ignore the HA logs for updates. That 30s polling is coming from HA and will get the cached value. The controller operates at Now there could be a question about letting the |
@alandtse will try to catch the offline mode and match it with the sensor state. (only seen it a few times) Is it possible to get a timestamp when last successful API-call was made? (I like to know that everything is ok and polling when car is asleep) |
No. That data isn't saved anywhere. You'll only see it in teslajsonpy logs. I'm not aware of any HA property or attribute where we'd save that info as the philosophy is the api is supposed to handle things like that. You can assume it's polling per my description above and you can check the logs. |
I thought that the online status were polled at the same time as everything else. That means that if the car is sleeping, independent of the online switch, it will detect it became online? Because what we need is to detect the car sucessfully slept to reduce polling time and detect a drive or charge right away. I need to make a few tests.
Online status could always be 60s. Only the car requests would be afftected by scan_interval. But I believe we can live with as is.
Yeah, I forgot the throttle is done at the controller and not in the update method in the HA integration. Good, then we can expose the "scan_interval" to dynamically change it through a service call.
My TeslaFi polls it every 60s, and so far so good, no problem of being kicked out. But it's dynamic. If it detects a situation of "can sleep", it changes to 15 min. Once the car slept, it goes back to 60s to catch the wake up. If driving or charing, it kleeps the 60s. |
@tobbensoft, Yes, Teslafi is always checking online status every 60s.
HA calls the controller method every 30s. But the controller throttles this request to scan_interval, which is 300s. So the car is only called every 300s. |
Yes, it will detect if online if Tesla says it's online. The Update switch does not do anything to the online check.
No need to expose a new service, just change the config flow option. However, no idea if the config_flow options are changeable programmatically and that would be a HA feature request if it isn't. That said, you can just turn off the Update switch for periods you want the car to be sleeping. You don't have to change the |
@alandtse I think I got the update/sleeping working as it should by using the update switch and automations. Will test for a little longer. (Maybe write a little FAQ for the docs?) 2 things are not perfect yet though :)
|
Not opposed to allowing someone to set the online check to 60 but should keep the default. Please note there are people with multiple cars so we can't set the default too low. There is a forced wake up on restart so assuming the cars respond, it will populate. Of course we can't force cars to respond so templates will need to wait for data to populate. Some templates use a uptime sensor and require at least 5 minutes of HA uptime before they activate. |
|
It's the scan_interval. We need to up the floor, but that can be 60. Your template can then manage how often any vehicles are polled. If we really want to expose to scan_intervals, see if the HA constants has more than one else we'll have to create a new variable which will need to be approved by HA.
|
Can I hack some file to change
What I see in the logs is that the So the I can try this again tonight to make sure I'm not missing anything. |
Probably makes sense to message me on discord instead of trying to chat in github.
Ok, there's a bug in the code. async with self.__lock[vin]:
if (
online
and ( # pylint: disable=too-many-boolean-expressions
self.__update.get(vin)
) should be: async with self.__lock[vin]:
if (
(online or wake_if_asleep)
and ( # pylint: disable=too-many-boolean-expressions
self.__update.get(vin)
) Try that and confirm the behavior for me. |
Added some additional fixes in master...alandtse:online_sensor. Will probably push that as a new version over the weekend. If you could let me know if it breaks anything, that would be great. |
Installed... looks good so far... |
Everything all good so far. I'm experimenting a few other changes and your branch is great. I've changed the online check to 60s and independent of the main polling: Seems to be working pretty good. I put some additional logging to verify. Few changes so far: alandtse/teslajsonpy@online_sensor...llluis:master |
Please test this version. #57. Websockets should connect and automatically update various drive states every few seconds if driving is ever detected (during regular scan_interval check). Unfortunately, HA will still only update the device tracker at 30 second intervals as the websocket update is transparent and I didn't figure out how to increase poll rate for the device tracker only. |
I merged #57 and added control to switch from 60 to 600 polling along with automations to control it. I believe it will be the way to do it. Also, I loved the attributes in the controls. I added a few more, awesome!!! Gives all the info without creating additional entities. Even if needed, templates will solve it. |
Closing this since we have the component now to talk about changes there. https://github.com/alandtse/tesla/issues If we're missing api calls, then we should open a new issue here. |
During debugging to fix #51 and seeing the available data from the api..
Is it a big thing to expose this in HA without any "processing" just so we could start using it to display information?
That could probably bring more interest and contributors to the project.
The text was updated successfully, but these errors were encountered: