mlowijs / tesla_api

Lightweight Python API client for the Tesla API.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

energy site id failures

blharveymi opened this issue · comments

if you have tesla vehicle as well as a solar/powerwall product, and you try to run the code in your readme file for pulling energy information it fails. I am not a good python programmer but it appears it is not able to parse the return correctly. I "fixed" it adding something like this to the init file.

async def list_energy_sites(self, _class=Energy):
d1, d2 = await self.get('products')
energy_id = d2['energy_site_id']
return [energy_id]

this will allow it to return an actual energy_site_id. I did the 2nd since it seems to always be the 2nd set of dictionary in my playing with it on postman. I converted the return to a list because a 2nd issue is then when the code from readme when to do len it couldnt. The convert addressed that.

now i am running into issue where i cant seem to pull any information about the site.

the line reserve = await energy_sites[0].get_backup_reserve_percent()
returns an error:
AttributeError: 'int' object has no attribute 'get_backup_reserve_percent'

this then continues down the entire list of other commands you provide in the readme.

This should be fixed in #26. Once @mlowijs makes the rounds, I'm sure this will get merged and put into the next release.

You can probably just grab that branch, and use that for now. The fixed line is:
https://github.com/mlowijs/tesla_api/pull/26/files#diff-61775cbe8551d10b95eff4f6e9a6d4ccR120

As the current code tries to create an Energy object for every product, it breaks when one of those is a vehicle. The correct fix was just to add if 'energy_site_id' in product to check if it references an energy site, rather than a vehicle.

FYI, the latter errors are because you've changed the function to return the ID, which is just an int, instead of creating an Energy instance.

This should be fixed in #26. Once @mlowijs makes the rounds, I'm sure this will get merged and put into the next release.

You can probably just grab that branch, and use that for now. The fixed line is:
https://github.com/mlowijs/tesla_api/pull/26/files#diff-61775cbe8551d10b95eff4f6e9a6d4ccR120

As the current code tries to create an Energy object for every product, it breaks when one of those is a vehicle. The correct fix was just to add if 'energy_site_id' in product to check if it references an energy site, rather than a vehicle.

FYI, the latter errors are because you've changed the function to return the ID, which is just an int, instead of creating an Energy instance.

thanks. i opened up some peoples forks of this and saw one that I got to work. I am now setting up an aws lambda function to pull every 5 minutes the live-status call to basically mimic the tesla app. I then want to pull my meter data from texas smart meter since i get free energy between 12-3am so i have a smartthings app that changes reserve to 100% at 12 and back to 20% at 3am. but i might try something different since it didnt change it last night even though it was scheduled too. I want to compare the findings. I also want to pull data from the Sense smart home reader to show the heavy energy users within the house. A lot of work cut out for me. then need to see if amazon quicksight is a good visualization for this or if should put the data into a managed ES cluster within aws or standup a free splunk instance on an ec2 or something.

This is fixed in master now (but, still needs a new release for pip).