According to my dialogue with charge amps support, there is NO communication happening directly between the ampguard and the charger, they only communicate via their cloud service.
I did some basic sniffing on my network which seems to confirm that they both communicate outbound to chargepointapi.azurewebsites.net only.
One interesting thing though when looking at the traffic from the amp-guard specifically is that it continuously tries to initiate a session towards a (nonexistant) local ip as follows: <ampGuard>.47048 > 10.1.0.99.1883: Flags [S]
… And I agree @fredrike , using the approach as with your plugin, it would most likely be possible to achieve what I want, not sure I have the necessary skills to make that happen though, as I have not coded for more than a decade now
Ok, so I couldn’t resist to test this… so I created a new vlan and deployed a mqtt server as to be able to listen on the IP and port my guard tries to talk to, and it immediately added itself as “smartpi12345” and started reporting perfectly the amps used on each of my three phases every 5 seconds…
If I could only also find a way to tell it to report to a specific mqtt server…
So you are saying that we could push data to my.charge.space w/o paying the premium price of the load “balancer”.
Also there is quite a bit of delay between updates on the web untin things happens with the charger. The api documentation mentions a local api and a webhook…
You mean to push this type of data to the API from a 3rd party device…
njaee, while technically this is of course possible, it will need development/support from the vendor, as there is currently no official support for even querying this data back from the API, which is what I was hoping to achieve. (And the API license prohibits any type of reverse-engineering of their API’s)
What I found out though was that the AmpGuard (ie the load balancer) by default happily registers to a mqtt server located at 10.1.0.99 with the topic smartpi12345 and populates/updates this topic with all sorts of measuring details every 5 seconds. Among the details it populates is the current load on the phases, which is the data I wanted to get out from the API and graph via my Home Assistant instance.
So I ended up solving this specific need by going outside the API and setting up a linux server on that specific IP, and just configuring a mqtt-server to act as a bridge to my homeassistant (which also allowed me to remap the topic to something more appropriate)
I now wonder if I dare ask their support if they would allow me to reconfigure the built-in mqtt client in the AmpGuard to send to another IP instead, or if this would result in them sending out an update to plug this hole down instead… So far I feel the support are very friendly, so I am thinking of giving it a go…
And yes, there is definitely a delay in the communication between the web and the charger. My conclusion is that this is due to the communication only polling the API for updates every 30 seconds, and not using any push.
You could either NAT the 10.1.0.99 to something apropriate, your MQTT server for instance. Or you could set a secondary IP on the MQTT server if they are in the same VLAN.
The Pi inside the case is probably running from a SD card, is it easily accessible? Then it should be easy to access the root partition and rewrite config. Have you tried SSH into it, user pi and password smart4pi?
In regards to local API to the Charger, I’ve sniffed the traffic but it seems it only polls for settings and then sends updates with a certain interval. The polling is done over HTTP port 80 but payload seems encrypted or hashed.
If one could decode the format/encryption we could probably figure out how to implement something local.
Thanks for the tip @Farfar .
No luck on the default logins for smartpi (which I guess is actually a good thing in the greater sense of this ). Yeah, I could have NAT:ed, just not an option available in the GUI of my USG, and I am trying to avoid any low-level configurations as they always seem to revert on every upgrade. As long as this works I’ll probably just leave it as it is.
Huge thanks to you for creating this component!
I’ve used it about a month now. All since I got my Charge Amp and Kia Optima and it’s working great.
I wanted a way to see if the car is currently charging or not, how much energy put into the battery on this ongoing charging cycle and the total amount of enery on the last ended cycle.
What I also would have wanted is to see the charge level of the battery but that would have to come from the car and that’s nothing Charge Amp can provide unfortunately.
To give something back to the community I like to share the config I did to make it happen in my HA setup. Yes, some pieces of the config comes from @fredrike config. Thank you.
Don’t know if it is possible in this component to retreive the result of the last charging session so I had to do the calculations myself with a variable prev_or_current_charge. It’s not the exact end value but pretty close.
sensor.garage is how I named my Charge Amp in HA.
In configuration.yaml
#Variables to keep track of the energy of the current or ended charging cycle. Max set to 16 (my car battery can maximum hold 11kWh).
input_number:
prev_or_current_charge:
name: Energy value of current or latest charge cycle
min: 0.0
max: 16.0
initial: 1.5
#Updates the value every 30 seconds
automation car
- trigger:
- platform: time_pattern
seconds: "/30"
id: "time_pattern_test"
action:
- service: input_number.set_value
entity_id: input_number.prev_or_current_charge
data:
value: "{% if state_attr('sensor.garaget_2102023157m_1', 'total_consumption_kwh') > 0 %} {{ state_attr('sensor.garaget_2102023157m_1', 'total_consumption_kwh') }} {% else %} {{ states('input_number.prev_or_current_charge') }} {% endif %}"
chargeamps:
username: <my Charge Amp account user name. Same as if you login to the Charge Amp official app or website>
password: <Charge Amp pw>
api_key: <requested and received from Charge Amp support>
In my lovelace config file (yaml mode).
- content: >
{{states("sensor.garaget_2102023157m_1")}}. {% if state_attr("sensor.garaget_2102023157m_1", "total_consumption_kwh") > 0 %} Bilen laddas. Denna laddning hittils **{{ state_attr("sensor.garaget_2102023157m_1", "total_consumption_kwh") }} kWh** @ {{state_attr("switch.garaget_2102023157m_1", "max_current") | int }} Amp {% else%} Bilen laddas **inte**. Förra laddningen var: **{{ states("input_number.prev_or_current_charge") }} kwh.** {% endif%}
type: markdow
Btw: The enery gauge on the top of the pictures is coming from my ESPHome (ESP8266 microcontroller) showing my energy consumption for my whole house. But that’s a nother story.
Edit 2021-12-08: Added else-statement to the automation in configuration.yaml. Now there is not type cast error in the logs. Thanks @klotan
Tja Fredrik
Hur får du till din den där dashboarden?
Har sett din kod men vart skriver du in den?
Jag är ganska ny på Home Assistant men har fått in chargeamps redan så det fungerar men hur man kodar in i lovelace har jag inte fattat än.
Så har du lust att förklara för en nyfiken en så hade jag blivit glad.
Om jag redan har data i home assistant för faserna kan jag då sköta lastbalansering via home assistant genom att sänka laddstyrkan genom home assistant?
Jag får inte din kod att fungera i configure.yaml, får felmeddelande i loggen.
Error while executing automation automation.automation_3: expected float for dictionary value @ data[‘value’]
Och
automation 3: Error executing script. Invalid data for call_service at pos 1: expected float for dictionary value @ data[‘value’]
Vet du varför det blir så?
Provade att skapa en template sensor från attributet total_consumption_kwh och la in den i stället, tar jag då bort > 0 från koden så får jag inga felmeddelanden men givetvis får jag inget set value i input_number.prev_or_current_charge heller och förra laddningen går tillbaka till 0.0 igen.
Har testat allt men kan inte komma på hur jag ska få den att sätta value.
Har jobbat vidare på @Disse kod då den är vad jag var ute efter men den gav några errors i loggen.
Efter några dagars försökande så kom jag till slut fram till fungerande kod som gör vad den ska utan errors.
Så här är hela automationen för den som är intresserad.
Det den gör ser ni i Disses tidigare tråd här ovanför.
input_number:
prev_or_current_charge:
name: Energy value of current or latest charge cycle
min: 0.0
max: 16.0
initial: 1.5
#Updates the value every 30 seconds
automation:
- alias: Billaddning prev current
trigger:
- platform: time_pattern
seconds: "/30"
id: "time_pattern_test"
action:
- service: input_number.set_value
entity_id: input_number.prev_or_current_charge
data:
value: "{% if state_attr('sensor.halo_1', 'total_consumption_kwh')|float > states('input_number.prev_or_current_charge')|float %} {{state_attr('sensor.halo_1', 'total_consumption_kwh')|float}} {% else %} {{states('input_number.prev_or_current_charge')|float}} {% endif %}"
- alias: Reset senaste laddning
description: ''
trigger:
- platform: state
entity_id: sensor.halo_1
from: Available
to: Charging
for:
hours: 0
minutes: 0
seconds: 1
milliseconds: 0
condition: []
action:
- service: input_number.set_value
data:
value: 0
target:
entity_id: input_number.prev_or_current_charge
mode: single
I have this error since a couple of weeks, im om the latest release of both HA and this integration. Is this a know problem or is it “shit behind the levers” ?
This error originated from a custom integration.
Logger: homeassistant.setup
Source: custom_components/chargeamps/__init__.py:111
Integration: chargeamps (documentation, issues)
First occurred: 6 december 2021 11:32:06 (1 occurrences)
Last logged: 6 december 2021 11:32:06
Error during setup of component chargeamps
Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/aiohttp/connector.py", line 969, in _wrap_create_connection
return await self._loop.create_connection(*args, **kwargs) # type: ignore # noqa
File "/usr/local/lib/python3.9/asyncio/base_events.py", line 1081, in create_connection
transport, protocol = await self._create_connection_transport(
File "/usr/local/lib/python3.9/asyncio/base_events.py", line 1111, in _create_connection_transport
await waiter
ConnectionResetError
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/setup.py", line 254, in _async_setup_component
result = await task
File "/config/custom_components/chargeamps/__init__.py", line 111, in async_setup
for cp in await client.get_chargepoints():
File "/usr/local/lib/python3.9/site-packages/chargeamps/external.py", line 82, in get_chargepoints
response = await self._get(request_uri)
File "/usr/local/lib/python3.9/site-packages/chargeamps/external.py", line 66, in _get
await self._ensure_token()
File "/usr/local/lib/python3.9/site-packages/chargeamps/external.py", line 47, in _ensure_token
response = await self._session.post(
File "/usr/local/lib/python3.9/site-packages/aiohttp/client.py", line 520, in _request
conn = await self._connector.connect(
File "/usr/local/lib/python3.9/site-packages/aiohttp/connector.py", line 535, in connect
proto = await self._create_connection(req, traces, timeout)
File "/usr/local/lib/python3.9/site-packages/aiohttp/connector.py", line 892, in _create_connection
_, proto = await self._create_direct_connection(req, traces, timeout)
File "/usr/local/lib/python3.9/site-packages/aiohttp/connector.py", line 1051, in _create_direct_connection
raise last_exc
File "/usr/local/lib/python3.9/site-packages/aiohttp/connector.py", line 1020, in _create_direct_connection
transp, proto = await self._wrap_create_connection(
File "/usr/local/lib/python3.9/site-packages/aiohttp/connector.py", line 975, in _wrap_create_connection
raise client_error(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host eapi.charge.space:443 ssl:False [None]
Jag försöker också styra lasten via HA då jag ofta skjuter en säkring när jag laddar bilen plus allt annat som körs under natten.
Men jag lyckas inte använda tjänsten för att ändra set_max_current. I vilket format skall jag mata in tex max 10A här:
Hi Magnus!
Nice solution, I also have the amp guard and have done the same thing you did. Created a vlan and hooked up a raspberry pi as a MQTT bridge. But I’m not sure how to get hass mqtt to auto discover the values (if thats even possible?). Can you share your hass configs and if possible also the remapping config for the bridge?
I could not stop myself… I googled a bit and the Amp Guard is based on an product that in turn is based on open source. I found out that it has a web API that can be used to gather the values. And it is not protected by any auth. This is ofc a bad practice, but for me its not a problem as I have the device locked inside a separated vlan with no access from internet.
Docs: API - nD-enerserve GmbH
@jschlyter & @fredrike any possibility that you might be interested in adding support for the Amp Guard inside the ChargeAmp HA integration? It could be a optional function for those that have it. I would happily participate as a beta tester!