Hi,
I’m stuck integrating my wallbox (SMA EV charger) into Home Assistant. The only way to access it is web-based.
On the command line, I found out I can get the token required to get the data with this command:
curl http://192.168.8.55/api/v1/token -d "grant_type=password&username=username&password=password##" | jq
… and then use this token to access the information with this command:
curl http://192.168.8.55/api/v1/measurements/live/ -d "[{\"componentId\":\"IGULD:SELF\"}]" -H "Authorization: Bearer <Token>" | jq
This gives following result (shortened for better readability):
[
{
"channelId": "Measurement.ChaSess.WhIn",
[...]
},
{
"channelId": "Measurement.Metering.GridMs.TotWhIn",
"componentId": "IGULD:SELF",
"values": [
{
"time": "2022-05-19T05:10:59.252Z",
"value": 398196
}
]
},
{
"channelId": "Measurement.Metering.GridMs.TotWhIn.ChaSta",
[...]
]
I tried integrating this in a REST sensor in Home Assistant configuration.yaml like this:
rest:
- resource: http://192.168.8.55/api/v1/measurements/live
headers:
Authorization: >
Bearer {{ states("eyJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE2NTI5MzU5MDUsInN1YiI6InRlc3QiLCJ1aWQiOiI3ZWEzZjQzNi1kM2E5LTRjOTktODNjZC1kMDRhNGUyNDQxMzEiLCJleHAiOjE2NTI5Mzk1MDV9.OeVcHEsfaVM7PTKzeBjx-j5zNecIFsLm_IztmELUJPA") }}
scan_interval: 10
sensor:
- name: "Wallbox Total charging"
value_template: "{{ value_json['Measurement.Metering.GridMs.TotWhIn']['value'] }}"
Unfortunately this does not seem to work. The errors in HASS log don’t help much, the message seems to be cut off:
“Error fetching data: http://192.168.8.55/api/v1/measurements/live failed with”
Second problem in this context:
Since in my experiments the token received in the first request seems to be valid quite a while, I started with the fixed token included in the request to see if I can get it running at all. But I guess to have it fully working I would have to use a dynamic token. Should not be too complicated, but my knowledge is limited to a bit of scripting. How could this be done in Home Assistant? Does this have to be programmed in Python, or is there a much simpler way?
Thanks in advance for any hint that can point me in the right direction!