1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
|
# wallbox
Python Module interface for Wallbox EV chargers api
## Requirements
Python 3.7 or older Python modules "requests>=2.22.0", "simplejson>=3.16.0"
Python module "aenum>=3.1.8"
## Installation
```python
pip install wallbox
```
## Implemented methods
### authenticate()
- authenticates to the wallbox api.
### getChargersList()
- returns a list of chargers available to the account
### getChargerStatus(chargerID)
- returns a dictionary containing the charger status data
### unlockCharger(chargerId)
- unlocks charger
### lockCharger(chargerId)
- locks charger
### setMaxChargingCurrent(chargerId, chargingCurrentValue)
- sets charger Maximum Charging Current (Amps)
### pauseChargingSession(chargerId)
- pauses a charging session
### resumeChargingSession(chargerId)
- resumes a charging session
### resumeSchedule(chargerId)
- revert charger back to default schedule after manually starting a charging session, it reverts the charger back into "Eco Smart and Scheduled" charing mode, if used.
### getSessionList(chargerId, startDate, endDate)
- provides the list of charging sessions between startDate and endDate
- startDate and endDate are provided in Python datetime format (i.e. 2021-05-04 08:41:12.765644)
### setEnergyCost(chargerId, energyCost)
- sets the energy cost for the charger per kWh
### restartCharger(chargerId)
- restarts (reboots) charger
- a full charger reboot can take a few minutes. Charger status will be slow to update (ie: READY (10s) -> DISCONNECTED (90s) -> READY)
CAUTION: use this method with care!! Check if the charger is not in the middle of a firmware upgrade as this can brick your charger.
### setIcpMaxCurrent(chargerId, newIcpMaxCurrentValue)
- sets charger Maximum ICP Current available (Amps).
Please note that the wallbox may refuse this action if not setup properly of if not supported by your model
### getChargerSchedules(chargerId)
- gets the currently configured schedules for that charger.
Response is a JSON structure like the following:
```json
{
'schedules': [{
'chargerId': 42,
'enable': 1,
'max_current': 1,
'max_energy': 0,
'days': {'friday': true, 'monday': true, 'saturday': true, 'sunday': true, 'thursday': true,
'tuesday': true, 'wednesday': true},
'start': '2100',
'stop': '0500'
}]
}
```
### setChargerSchedules(chargerId, newSchedules)
- Create or replace an existing schedule.
`newSchedules` is a dictionary like the following:
```json
{
'schedules': [{
'id': 0,
'chargerId': 42,
'enable': 1,
'max_current': 1,
'max_energy': 0,
'days': {'friday': true, 'monday': true, 'saturday': true, 'sunday': true, 'thursday': true,
'tuesday': true, 'wednesday': true},
'start': '2100',
'stop': '0500'
}]
}
```
As schedules returned by `getChargerSchedules` are positional, the `id` field in the payload represents the position of the schedule to add/replace.
## Simple example
```python
from wallbox import Wallbox, Statuses
import time
import datetime
w = Wallbox("user@email", "password")
# Authenticate with the credentials above
w.authenticate()
# Print a list of chargers in the account
print(w.getChargersList())
# Get charger data for all chargers in the list, then lock and unlock chargers
for chargerId in w.getChargersList():
chargerStatus = w.getChargerStatus(chargerId)
print(f"Charger Status: {chargerStatus}")
print(f"Lock Charger {chargerId}")
endDate = datetime.datetime.now()
startDate = endDate - datetime.timedelta(days = 30)
sessionList = w.getSessionList(chargerId, startDate, endDate)
print(f"Session List: {sessionList}")
w.lockCharger(chargerId)
time.sleep(10)
chargerStatus = w.getChargerStatus(chargerId)
print(f"Charger {chargerId} lock status {chargerStatus['config_data']['locked']}")
print(f"Unlock Charger {chargerId}")
w.unlockCharger(chargerId)
time.sleep(10)
chargerStatus = w.getChargerStatus(chargerId)
print(f"Charger {chargerId} lock status {chargerStatus['config_data']['locked']}")
# Set charger Energy Cost to 0.1€/kWh
energyCost = w.setEnergyCost(chargerId, 0.1)
print(f"Charger {chargerId} energy cost {energyCost['energy_price']} {energyCost['currency']['symbol']}")
# Print the status the charger is currently in using the status id
print(f"Charger Mode: {Statuses(chargerStatus['status_id']).name}")
```
|