Smart home with SMA PV and wallbox, Wolf heat pump and LEDA wood oven

hey all,

I wanna share my small project with you.
I have following goals:

  • maximum self-consumption of solar power
  • a punctual message when wood must be added
  • a message when to charge the car.
    These are small wishes, but there are major challenges. The smaller issues are not a problem: messages when children leave the skylight open, and so on.

Currently, I am still stuck on the integration of various devices:

  • Leda wood stove with Ledatronic LT3: The integration does not work at this moment.
  • Wolf heat pump CHA10: So far, access is via the web portal. Here I have frequent disconnections and would like to fall back on a local solution.
  • The SMA EV Charger wallbox does not yet have a Modbus interface and is also not yet integrated.

What works well so far is the collection of SMA data via Modbus.
This is an SMA Tripower STP15000 and an SMA Sunny Boy Storage 3.7.

I will keep you informed about the progress.

Best Regards, Alois

What integration is that?

good morning @nickrout,

regarding Leda controller “Ledatronic LT3 integration” I am talking about that Python-script:
Ledatronic integration on Github

I got support on this site:
thread in Heimnetz-Forum

If this way does not work, I have some other ideas:

  • reading LEDA’s internal CAN-BUS with additional hardware
  • getting values by using LEDA CAN/RS232-converter (really expensive for that simple converter: 250-320€)

Best Regards, Alois

That forum’s advice is way out of date. So might the intergraation be, but let’s keep trying.

Set up a directory /config/custom_components.ledatroniclt3

Then take that ledatroniclt3.py file and rename it to sensor.py and put it in the directory you just made.

Then in the same dir create a file named __init__.py and simply put a comment in it like

''' the ledatroniclt3 component'''

Lastly create a file called manifest.json containing

{
"version":  "1.0"
}

restart HA and see what the log says :slight_smile:

I created these files, and sensors are shown. This part is OK now I think.
The sensors do not get valid values, so I think there is another problem on LEDA-side. Maybe they’ve changed their communication:


grafik

Hello together,

I have another point where I need your help:
I am using “Riemann sum integral” for calculating daily energy consumption for my heat pump.

native power signal:

The integral result is looking like this:
grafik

I have a lot of vertical steps within my integral calculations. As result, the calculations is sending back too big values. I see the same steps within other entities.

Any ideas about the mistake?

Best Regards, Alois

Code for the calculation:

sensor: 
  - platform: integration
    source: sensor.leistungsaufnahme_wp_ehz
    name: Energieverbrauch WP kWh
    unit_prefix: NONE
    round: 2

nobody with hints solving my problem?

Do you mean the jump in your energy graph just after 9:00? I am not sure about that. The rest looks normal though.

Hey nick,
yes that jump at 9:10. I checked the signal “Leistungsaufnahme” which is integrated to “Energieverbrauch”. I do not see any spikes etc, so I guess there is an error in calculating “Riemann sum integration”.
Is it possible to check native values of “Leistungsaufnahme” by exporting a CSV-file?

You can get the data direct from the database, but easier to install this fantastic card which allows csv export. GitHub - alexarch21/history-explorer-card: A card for Home Assistant Lovelace for exploring the history of your entities interactively and in real time.

You can just query information from the EV Charger using http and its API.

You can just query information from the EV Charger using http and its API.

I just got my SMA EV Charger and would like to implement it into HA.
Could give a bit more information about this?

Thank you!

I’ve used the information found here: HomeMatic liest und ändert Daten der Wallbox SMA EV Charger 22 - HomeMatic-Forum / FHZ-Forum

Thank you! (Danke :-))

This seems to be the right direction, but i have to admit to be lost how to implement it in HA (as there are scripts with curl (which i dont know) and Homematic).
Are there any specific instructions/help for HA? Would you mind to share some of your knowledge? :slight_smile:
Thanks a lot!

Hello together,
I also have a SMA EV Charger and would like to intigrate it in HA. Therefore, I would also be interested in a tutorial.

Many Thanks

As some others posted before - I just wanted to add I tried implementing this in Home Assistant as well - but failed. I was able to query the information on the command line, but automating this in Home Assistant was a real nightmare.

@tmeringer: if you could post the configuration you used for the EV charger and maybe a few sentences with a short explanation maybe this should be enough to help all of us :slight_smile:

Sure, but keep in mind that I am no php expert at all, so the script provided might not be the best in the universe, plus I am only reading data from the SMA EV Charger (for now) using an Apache webserver that is running on my Home Assistant server, so YMMV.
IOW: my Apache webserver is returning a JSON string that can be consumed by Home Assistant then.

Here’s the php script:

<?php
$SMA_EV_IP = "<ev_charger_ip>";
$SMA_EV_user = "<ev_charger_username>";
$SMA_EV_pass = "<ev_charger_password>";

$URL_EV_token = "http://$SMA_EV_IP/api/v1/token";
$URL_EV_data = "http://$SMA_EV_IP/api/v1/measurements/live/";

// Get data from SMA EV charger
// 1st: get bearer token after authentication
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); 
curl_setopt($ch, CURLOPT_POSTFIELDS, "grant_type=password&username=$SMA_EV_user&password=$SMA_EV_pass"); 
curl_setopt($ch, CURLOPT_URL, $URL_EV_token);
$SMA_EV_token = curl_exec($ch);
curl_close($ch);

$SMA_bearer_token = json_decode($SMA_EV_token, true);
$SMA_bearer_access_token = $SMA_bearer_token[access_token];

// 2nd: get live data

$SMA_EV_header = array(
        "Authorization: Bearer $SMA_bearer_access_token"
);
$SMA_EV_data = "[{\"componentId\":\"IGULD:SELF\"}]";


$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $URL_EV_data);
curl_setopt($ch, CURLOPT_HTTPHEADER, $SMA_EV_header); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); 
curl_setopt($ch, CURLOPT_POST ,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $SMA_EV_data);

$SMA_EV_return = curl_exec($ch);
curl_close($ch);

echo  $SMA_EV_return;
?>

Thank you very much for the script.

Since I had to do a bit trial and error, for future reference the steps i took in my Debian system:

sudo apt update
sudo apt install apache2
sudo apt-get install php
sudo apt-get install php-curl
service apache2 restart

This gave me a working setup, so I could save your script in /var/www/html and open it in a browser. By the way, since the debugging gave me a warning: I changed the line

$SMA_bearer_access_token = $SMA_bearer_token[access_token];

to

$SMA_bearer_access_token = $SMA_bearer_token['access_token'];

Now my final problem is: how can I process this data in Home Assistant?
I tried something like this in configration.yaml:

rest:
# SMA EV charger
  - resource: http://hass/sma.php
    scan_interval: 30
    sensor:
      - name: Wallbox
        value_template: 'OK'
        json_attributes:
          - Measurement.Metering.GridMs.TotWIn.ChaSta
          - Measurement.Metering.GridMs.TotWhIn.ChaSta

Also tried the other variation I found on https://www.home-assistant.io/integrations/rest/#fetch-multiple-json-values-and-present-them-as-attributes - nothing seems to work. The sensor is there, but only has a value of “friendly_name: Wallbox”. Seems to me the values provided by the script are formatted strangely - the browser only displays everything as plain text, too:


Whereas another JSON request I am using shows a formatted text in the same browser:
grafik

An hint on this? How did you integrate the PHP results into Home Assistant?

Sorry, it took a while.
I decided to go for a Home Assistant only route so that there is no need for an external dependency (using Apache).That caused my some headache, but I finally came up with a solution.

I came across Extracting data from JSON array from rest sensor that is longer than 255 characters - #5 by tmeringer which contains a very useful and clever trick.

So what I did: I am using Command Line - Home Assistant with a bash script.

This is the bash script that’s called from Home Assistant:

#!/bin/sh

IP_EV_Charger='<IP.OF.YOUR.EV22>';

USER='<USERNAME>';
PASSWORD='<SUPERSECRETPASSWORD>';

TOKENREQUEST=$(curl --silent http://$IP_EV_Charger/api/v1/token -d "grant_type=password&username="$USER"&password="$PASSWORD)
bearer_token_string=$(echo $TOKENREQUEST | jq -r .access_token) # -r removes surrounding quotes

SMA_EV_Return=$(curl --silent http://$IP_EV_Charger/api/v1/measurements/live/ -d "[{\"componentId\":\"IGULD:SELF\"}]" -H "Authorization: Bearer $bearer_token_string")

echo "{\"sma_ev_json\":"$SMA_EV_Return"}"

And the sensor being used is

- platform: command_line
  name: SMA EV Charger
  scan_interval: 60
  command_timeout: 30
  command: "/opt/homeassistant/sma-ev-getdata.sh"
  value_template: 'SMA_EV_CHG'
  json_attributes:
    - sma_ev_json

This results in a new sensor that contains the json data from the SMA EV Charger as attributes:

Data can be accessed like this then:

{{ states.sensor.sma_ev_charger.attributes['sma_ev_json'][1]['values'][0]['value'] }}

Result:

1 Like

Thanks a lot! That worked for me, too!
It might also be possible to change values with this method, extending the script a bit - but this version is a beginning and should be enough for what I want to do at the moment.
And even though they announced it quite a while ago and nothing happened until now, maybe SMA will update the wallbox to support modbus in the near future so all will be easier…