Skip to content

Instantly share code, notes, and snippets.

@karl-gustav
Last active May 20, 2021 08:53
Show Gist options
  • Save karl-gustav/4daac9eeca0d53b38842c462a1ba4c57 to your computer and use it in GitHub Desktop.
Save karl-gustav/4daac9eeca0d53b38842c462a1ba4c57 to your computer and use it in GitHub Desktop.
control easee charger over internet
# Source https://community.home-assistant.io/t/easee-ev-charging-station/186474/7
import requests, json, time
from pprint import pprint
class connect:
def __init__(self,
access_token=None,
):
if (access_token is None):
access_token_resp = self.get_access_token()
access_token = access_token_resp["accessToken"]
self.headers = {"Authorization": "Bearer {}".format(access_token)}
def get_access_token(self):
return requests.post("https://api.easee.cloud/api/accounts/token", json={"grantType":"password","username":"+46xxxxxxxx","password":"xxxxxxxx"}).json()
def get_state(self):
return requests.get(
'https://api.easee.cloud/api/chargers/EH<serial>/state',headers=self.headers).json()
def get_sites(self):
return requests.get(
'https://api.easee.cloud/api/sites',headers=self.headers).json()
def get_site_info(self):
return requests.get(
'https://api.easee.cloud/api/sites/<site-id>?detailed=true',headers=self.headers).json()
def set_current(self, current):
return requests.post("https://api.easee.cloud/api/sites/<site-id>/circuits/<circuit-id>/settings", headers=self.headers, json={"dynamicCircuitCurrentP1":current, "dynamicCircuitCurrentP2":current, "dynamicCircuitCurrentP3":current}).json()
def pause(self):
return requests.post("https://api.easee.cloud/api/chargers/EH<serial>/commands/pause_charging", headers=self.headers).json()
def resume(self):
return requests.post("https://api.easee.cloud/api/chargers/EH<serial>/commands/resume_charging", headers=self.headers).json()
my_charger = connect()
resp = my_charger.get_sites()
pprint(resp)
resp = my_charger.get_site_info()
pprint(resp)
resp = my_charger.set_current(10)
pprint(resp)
resp = my_charger.pause()
pprint(resp)
resp = my_charger.resume()
pprint(resp)
resp = my_charger.get_state()
pprint(resp)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment