Monitoring Anderssen Konnect A2
Home Assistant has an excellent system for monitoring energy usage/solar generation/grid usage/gas usage, etc.
One of the features is the ability to monitor specific devices, i.e., anything that can show electricity usage in kWh. We’ve been able to monitor many devices, like the fish tank, computers, etc., using plugs that can monitor power usage. However, many things are harder to measure, and it’s not economical to add monitors to everything in the house. This means that the gap between usage and monitored usage shows up as “Untracked consumption”.
This “Untracked consumption” will be things like lighting, the oven, kettles etc. One of the largest of these is the car charger, so this is a gap I decided to try and bridge.
Our car charger is an Anderssen Konnect A2 charger that currently has no direct integrations into Home Assistant. The charger does have a basic phone app that allows you to lock the charger, schedule times and monitor consumption. After a bit of digging online, I found an excellent Python package that has been developed to allow access to the charger. strobejb/andersen-ev: Python package to enable control of the Andersen A2 EV charger
The issues tab discusses Home Assistant(HA) integration and offers an approach to get the data into the system without a full-blown integration. (Although I am looking at building a formal integration as a background project). HA Integration · Issue #1 · strobejb/andersen-ev
The basic approach is to use the AppDaemon support add-on in HA. This allows a Python script to run periodically and expose data into HA. I tweaked the script a little as follows :
from andersen_ev import AndersenA2
from gql.transport.exceptions import TransportQueryError
import hassapi as hass
import datetime
a2 = AndersenA2()
class AndersenCharger(hass.Hass):
def login(self):
a2.authenticate(email=self.args["username"], password=self.args["password"])
def initialize(self):
self.login()
deviceId = a2.get_current_user_devices()[0]['id']
time = datetime.time(0, 0, 0)
self.run_minutely(self.run_minutely_c, time, device=deviceId)
def run_minutely_c(self, cb_args):
deviceId=cb_args["device"]
try:
status = a2.get_device_status(deviceId)['deviceStatus']['chargeStatus']['chargePower']
self.log(status)
self.set_state("sensor.AndersenA2ChargePower",state=status,attributes={"device_class":"power","unit_of_measurement":"W"})
history = a2.get_device_calculated_charge_logs(deviceId)
for i in history['deviceCalculatedChargeLogs']:
if (i['duration'] > 60):
self.log(i)
self.set_state("sensor.AndersenA2LastCharge",state=round(i['chargeEnergyTotal'],1),attributes=i)
break
except:
self.log("Auth failure...logging in")
self.login()
To turn the power info into a power usage value I also needed to create a sensor in home assistant by adding the following to configuration.yaml in my sensor block.
- platform: integration
source: sensor.andersena2chargepower
name: andersena2_usage
unit_prefix: k
round: 2
Adding andersena2_usage to my monitored devices tab then means all usage through the charger can be tracked.