Pyhass / Pyhiveapi

A python library to interface with the hive home api
MIT License
24 stars 18 forks source link

Add Hive EV Charger #43

Open drt102 opened 2 years ago

drt102 commented 2 years ago

Is your feature request related to a problem? Please describe. Is it possible to add in the Hive EV Charger

Describe the solution you'd like I use Home Assistant and I'd like to be able to monitor and control my Hive EV Charger.

KJonline commented 2 years ago

@drt102 yes it would be possible is my presumption. Unfortunately even though I have an electric car I live in a terraced house so I can’t get the ev charger yet. If you would be happy to share some of your hive api data with me we can have a look at how to develop this?

drt102 commented 2 years ago

@KJonline I can certainly help with this. Let me know what you want me to do.

KJonline commented 2 years ago

@drt102 the easiest way is to login to the hive website with a browser and open up the debug console which I think is right click and inspect on chrome. Are you familiar with the tools?

From their if you go to the network tab and filter by XHR requests and reload the hive dashboard page you should see some requests called products and devices they are 2 separate requests.

If you could please extract the responses and share them we can have a look at the code. They may be quite large depending on how many hive products you have.

Please make sure you review the responses yourself before sharing and remove any identifiable information to you personally.

drt102 commented 2 years ago

I've extracted just the bits for the EV charger and masked out the individual IDs

Device device_masked.txt

Product product._masked.txt

KJonline commented 2 years ago

Thanks for that I can work with it. What actions can you take when you click on the ev charger in the app? I’m guessing turn it on and turn it off are there any other actions?

also I can some additional data which could add some sensors e.g plugged and miles added.

Next step now would be to do the same extract when the vehicle is charging and if there is and on and off action we need to capture the api call being made when that is called.

All this can be achieved using the same mechanism to get the data as you already have done

drt102 commented 2 years ago

My EV is not quite here yet (hopefully in next 2 weeks) so I haven't actually had the charger working yet but the config options are as follows:

  1. Charger - Eco-charging option to schedule charging to take place between 12am and 8am.
  2. Tariff - Chose your electricity supplier from a list and pick a single or multi-rate tariff and set the unit price
  3. Vehicle - Enter vehicle efficiency in miles per kWh
  4. Notifications - Charging started, charging completed, charging reminders

On the main screen is what looks like a button to override any schedules and force charging to start.

The charger is therefore not very smart but I was hoping that I would be able to trigger the charging to start through HA.

KJonline commented 2 years ago

Yep so when viewing the item on the hive website can you do the same as before with the debug tools in the browser out this time click the button to start charging now. This should show an api call to change the state we will need an example of that

drt102 commented 2 years ago

The Hive website doesn't show any of this for the EV charger - I just get a blank screen when I click on the device from the dashboard. I can only see all of the controls and options from the app.

KJonline commented 2 years ago

Ah ok, it can still be done. Are you familiar with http proxy’s and proxying your mobile device traffic through one?

drt102 commented 2 years ago

I've now get Charles Proxy set up and have tested recording traffic from my mobile. What do you need me to do to progress work on getting the Hive EV Charger set up?

KJonline commented 2 years ago

@drt102 have you gone through the process of install the certificate on your device so you can read ssl encrypted traffic.

Once you have done that and you are happy you can read and see the hive api calls.

first thing to start of with is record some api calls being made. So set recording going and then use the EV option in the hive app try and cover all functionality in it so changing mode if there is one turning it on and off etc

once you have done that as a start just copy the urls for hive endpoints into this chat.

there shouldn’t be but please double check there is no personal identifiable information. If there is just put a placeholder in the data e.g

drt102 commented 2 years ago

Hmm, I think there is an issue with Android App trying to use Charles Proxy:

Android As of Android N, you need to add configuration to your app in order to have it trust the SSL certificates generated by Charles SSL Proxying. This means that you can only use SSL Proxying with apps that you control.

Does this mean that I can't use this with the Hive Android App?

KJonline commented 2 years ago

@drt102 yes reading that it seems it won’t work unless you are developing the app