Skip to main content

A simple, Pythonic wrapper for the ChargePoint API.

Project description

python-chargepoint

A simple Pythonic wrapper around the ChargePoint EV Charging Network API.

DISCLAIMER

I, nor this project, are in any way associated with ChargePoint. Use this project at your own risk. ChargePoint is a registered trademark of ChargePoint, Inc.

I just wanted a way to retrieve and store charging data from my ChargePoint Home Flex in a way that is easy to model and query. This project is the first step in getting that data into a more robust time series database.

Use

Login

from python_chargepoint import ChargePoint

client = ChargePoint(username="user", password="password")
print(client.user_id)
# 1234567890

Home Chargers

from python_chargepoint import ChargePoint

client = ChargePoint(username="user", password="password")
chargers = client.get_home_chargers()
print(chargers)
# [12345678]

for charger_id in chargers:
    charger = client.get_home_charger_status(charger_id=charger_id)
    print(charger)
# HomeChargerStatus(
#   brand='CP', 
#   plugged_in=True, 
#   connected=True, 
#   charging_status='NOT_CHARGING', 
#   last_connected_at=datetime.datetime(2022, 1, 30, 15, 14, 36), 
#   reminder_enabled=False, 
#   reminder_time='21:00', 
#   model='CPH50-NEMA6-50-L23', 
#   mac_address='0024B10000012345',
#   amperage_limit=25,
#   possible_amperage_limits=[20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32])

Account Charging Status and Session

from python_chargepoint import ChargePoint

client = ChargePoint(username="user", password="password")
charging = client.get_user_charging_status()
if charging:
    print(charging)
# UserChargingStatus(
#   session_id=1234567890,
#   start_time=datetime.datetime(2022, 1, 30, 13, 32, 45), 
#   state='fully_charged', 
#   stations=[
#     ChargePointStation(
#       id=12345678,  
#       name='CP HOME ',
#       latitude=30.0000000,
#       longitude=-90.0000000)
#     ])

    session = client.get_charging_session(charging.session_id)
    print(session)
#  ChargingSession(
#    session_id=1234567890, 
#    start_time=datetime.datetime(2022, 1, 30, 13, 32, 45), 
#    device_id=12345678, 
#    device_name='CP HOME', 
#    charging_state='fully_charged', 
#    charging_time=2426000, 
#    energy_kwh=4.3404, 
#    miles_added=15.024461538461539, 
#    miles_added_per_hour=0.0, 
#    outlet_number=1, 
#    port_level=2, 
#    power_kw=0.0, 
#    purpose='PERSONAL', 
#    currency_iso_code='USD', 
#    payment_completed=True, 
#    payment_type='none', 
#    pricing_spec_id=0, 
#    total_amount=0.67, 
#    api_flag=False, 
#    enable_stop_charging=True, 
#    has_charging_receipt=False, 
#    has_utility_info=True, 
#    is_home_charger=True, 
#    is_purpose_finalized=True, 
#    last_update_data_timestamp=datetime.datetime(2022, 1, 30, 15, 12, 48), 
#    stop_charge_supported=True, 
#    company_id=12345, 
#    company_name='CP Home', 
#    latitude=30.0000000, 
#    longitude=-90.0000000, 
#    address='Home Charger', 
#    city='City', 
#    state_name='State', 
#    country='United States', 
#    zipcode='12345', 
#    update_data=[
#      ChargingSessionUpdate(
#        energy_kwh=0.0,
#        power_kw=0.0002, 
#        timestamp=datetime.datetime(2022, 1, 30, 13, 32, 57)),
#      ChargingSessionUpdate(
#        energy_kwh=0.0001,
#        power_kw=0.1568,
#        timestamp=datetime.datetime(2022, 1, 30, 13, 33, 9)),
#      ChargingSessionUpdate(
#        energy_kwh=0.0025, 
#        power_kw=3.7337, 
#        timestamp=datetime.datetime(2022, 1, 30, 13, 33, 12)),
#      ChargingSessionUpdate(
#        energy_kwh=0.0161, 
#        power_kw=1.3854, 
#        timestamp=datetime.datetime(2022, 1, 30, 13, 33, 33)),
#      ...],
#    update_period=300000, 
#    utility=PowerUtility(
#      id=0, 
#      name='Energy Company', 
#      plans=[
#        PowerUtilityPlan(
#          code='R', 
#          id=12345, 
#          is_ev_plan=False, 
#          name='Residential')
#      ]))

Starting or Stopping a Session

from python_chargepoint import ChargePoint

client = ChargePoint(username="user", password="password")
charging = client.get_user_charging_status()

if charging:
    session = client.get_charging_session(charging.session_id)
    session.stop()

    # If you wanted to charge again, you can start a new session.
    session = client.start_charging_session(session.device_id)

You can also start a new session by providing any device ID you want to start charging on.

from python_chargepoint import ChargePoint

client = ChargePoint(username="user", password="password")
home_flex_id = client.get_home_chargers()[0]
home_flex = client.get_home_charger_status(home_flex_id)

if home_flex.charging_status == "AVAILABLE":
    session = client.start_charging_session(home_flex_id)

Setting the amperage limit

from python_chargepoint import ChargePoint

client = ChargePoint(username="user", password="password")
home_flex_id = client.get_home_chargers()[0]

# Print out valid amperage values.
print(client.get_home_charger_status(home_flex_id).possible_amperage_limits)
# [20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32]

client.set_amperage_limit(home_flex_id, 23)
print(client.get_home_charger_status(home_flex_id).amperage_limit)
# 23

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python_chargepoint-1.9.2.tar.gz (13.5 kB view details)

Uploaded Source

Built Distribution

python_chargepoint-1.9.2-py3-none-any.whl (15.2 kB view details)

Uploaded Python 3

File details

Details for the file python_chargepoint-1.9.2.tar.gz.

File metadata

  • Download URL: python_chargepoint-1.9.2.tar.gz
  • Upload date:
  • Size: 13.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.8

File hashes

Hashes for python_chargepoint-1.9.2.tar.gz
Algorithm Hash digest
SHA256 bf2009fa606560f0b4b7b89154a20f85ce648163f62cbf98e39b46aa1869c0e8
MD5 69bca910995c588beb326c6168947f61
BLAKE2b-256 724c976910165b196f3b7cadf369197699b3c57c914cc434a6d22fbaf1894393

See more details on using hashes here.

File details

Details for the file python_chargepoint-1.9.2-py3-none-any.whl.

File metadata

File hashes

Hashes for python_chargepoint-1.9.2-py3-none-any.whl
Algorithm Hash digest
SHA256 05ac01b11a55c981554e9d7555e31202d8c61318c782815328159c9f4d7a19bc
MD5 e3104c784cbb455a15e6b45c6e1608d3
BLAKE2b-256 4045c6d237e17caf6f994a69dd3e27f1a34a73d36ea1d95f4bfa1498f3d8bb2f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page