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

That works like a charm! Thank you very much.

The only thing i am missing is the “Car connected to Wallbox”.
But if i am reading this right, the api only returns the data that is presented via the "webui/monitoring/live view (“Momentanwerte” ), right?
Maybe we find a way for the “connected” status sometime.

There might be other endpoints too. I am still waiting for my BEV to arrive, so can’t check the “connected” status at the moment.

I found something here in post #19 - it’s in German, but since SMA does not seem to have huge market shares outside Germany I guess you might understand it :slight_smile:

According to the comments in this script, the connection state is represented by this value:

- channelId: Measurement.Operation.EVeh.ChaStt
  componentId: IGULD:SELF
  values:
    - time: '2022-06-20T19:44:27.350Z'
      value: 200112

… where
200111 = not connected
200112 = connected
200113 = charging

And by the way, in this thread mentioned above there is a link to another forum (also in German) that contains information about how to read and change settings - obviously with the same method, but the URL

[IP]/api/v1/parameters/search/
1 Like

Ah, great, thank you for pointing that out!

I did find this channel exposed via the api (just missed it due to “200111” and not being something readable ;-).
I can now read out the numeric state and convert it to text with a template:

Read out the numeric state:

- name: "sma_wallbox_car_connected"
  unique_id: "sma_wallbox_car_connected"
  state: "{{ states.sensor.sma_ev_charger.attributes['sma_ev_json'][17]['values'][0]['value'] }}"

and convert it into a human readable state (at least for a german) :slight_smile: :

- name: "sma_wallbox_car_status"
  unique_id: "sma_wallbox_car_status"
  state: "{%if states.sensor.sma_wallbox_car_connected.state == '200111' %}nicht angeschlossen
       {% elif states.sensor.sma_wallbox_car_connected.state == '200112' %}angeschlossen
       {% elif states.sensor.sma_wallbox_car_connected.state == '200113' %}lädt
       {% endif %}"

PS: i wonder if one could put these two sensors into one. I like to keep the sensor count as low as possible…

For the ability to change settings: for me the actual readout of

  • connection status (nothing connected, car connected, charging)
  • charging power in kW
  • total value of charged kWh

is enough, as i always (at least at the moment) use spare solar power to charge the battery.
if i have to go “full throttle” on charging i do have to walk to the wallbox and physically flip the switch anyway.

As my scripting abilities tend to be mostly zero, i sadly cannot make much out of the project you pointed out.

A bit off topic, but still my 2 cents: you can also do this by setting a charge limit in the smartphone app, e.g. 40 kWh to be charged in 2 hours. Then it will start charging at full speed. Big advantage of this approach: after the set time limit it will automatically revert to charging with spare solar power. This might be possible using Home Assistant as well, but since my setup seems to be very similar to yours (charging almost exclusively with solar power) that is no big deal.

2 Likes

You’re absolutely right.
I just tried that a few days ago and it seems to work as expected. (although it seems to drop the charging every now and then for no obvious reason - this don’t happen if i physically flip the switch).

Thanks for pointing that out.

I’ve managed to get this into one sensor with attributes for the different measurements:

template:                                                                                                                                                                                                                                                                                                                  
  - sensor:                                                                                                                                                                                                                                                                                                                
      - name: "Wallbox"
        icon: mdi:ev-station                                                                                                                                                                                                                                                                                               
        state: >                                                                                                                                                                                                                                                                                                           
          {% set s = states.sensor.sma_ev_charger.attributes['sma_ev_json'][17]['values'][0]['value'] | int(0) %}                                                                                                                                                                                                          
          {% if   (s == 200111) %} disconnected                                                                                                                                                                                                                                                                            
          {% elif (s == 200112) %} connected                                                                                                                                                                                                                                                                               
          {% elif (s == 200113) %} charging                                                                                                                                                                                                                                                                                
          {% else %} unknown                                                                                                                                                                                                                                                          
          {% endif %}                                                                                                                                                                                                                                                                                                      
        attributes:                                                                                                                                                                                                                                                                                                        
          energy_current_session: "{{ states.sensor.sma_ev_charger.attributes['sma_ev_json'][0]['values'][0]['value']  }}"                                                                                                                                                                                                 
          mode_switch:            "{{ states.sensor.sma_ev_charger.attributes['sma_ev_json'][1]['values'][0]['value']  }}"                                                                                                                                                                                                 
          grid_frequency:         "{{ states.sensor.sma_ev_charger.attributes['sma_ev_json'][5]['values'][0]['value']  }}"                                                                                                                                                                                                 
          power_charging_station: "{{ states.sensor.sma_ev_charger.attributes['sma_ev_json'][14]['values'][0]['value'] }}"                                                                                                                                                                                                 
          total_energy:           "{{ states.sensor.sma_ev_charger.attributes['sma_ev_json'][16]['values'][0]['value'] }}"                                                                                                                                                                                                 
          status:                 "{{ states.sensor.sma_ev_charger.attributes['sma_ev_json'][17]['values'][0]['value'] }}"                                                                                                                                                                                                 
1 Like

Hey,

I am a real noob in this and got some problems with the implementation.

I created the bash script sma-ev-getdata.sh under /config/bash/. In the configuration.yaml i added this:

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

It also creates the sensor but doesn’t get any data as you can see in the image:

The logs show me this:

If i run the script in terminal i get paramters returned like this:

image

Where could be the problem?

Regards
Philipp

Hello Alois,
I am trying to add my STP 20000 to HA. How you did it?
Thanks for helping
alpha

Hi,
I found another solution for the SMA EV Charger just by using the RESTful integration. The idea is to define a sensor to obtain the token in specified intervals.
The other sensors provide the corresponding values. This works better for me as I have full control over each sensor (like the unit of measurement) without the need of any template sensors.
Additional sensors can be added as usual.

rest:
  - resource: "http://<HOST>/api/v1/token"
    method: POST
    payload: "grant_type=password&username=<USERNAME>&password=<PASSWORD>"
    scan_interval: 3000
    headers:
      Content-Type: "application/x-www-form-urlencoded"
    sensor:
      - unique_id: SMA-Token
        name: "SMA EV Charger Token"
        value_template: "OK"
        json_attributes:
          - access_token

  - resource: "http://<HOST>/api/v1/measurements/live"
    method: POST
    payload: "[{\"componentId\":\"IGULD:SELF\"}]"
    scan_interval: 10
    headers:
      Authorization: "Bearer {{ state_attr('sensor.sma_ev_charger_token', 'access_token') }}"
      Content-Type: "application/x-www-form-urlencoded"
    sensor:
      - unique_id: SMA-Measurement.ChaSess.WhIn
        name: "SMA EV Charger Energy Charging"
        value_template: "{{ value_json[0]['values'][0]['value'] | float }}"
        unit_of_measurement: Wh
    
      - unique_id: SMA-Measurement.Chrg.ModSw
        name: "SMA EV Charger Mode Switch"
        value_template: >
          {% set mode=value_json[1]['values'][0]['value'] %}
          {% if mode == 4950 %} Smart charging
          {% elif mode == 4718 %} Fast charging
          {% else %} unknown
          {% endif %}

I have a STP15 which is almost the same. Had to add it with modbus:

modbus:
  # SMA STP 15.0
  - type: tcp
    name: inverter_pv_stp15
    host: 192.168.8.54
    port: 502
    sensors:
      - name: Power_STP15
        address: 30775
        input_type: input
        count: 2
        slave: 3
        unit_of_measurement: W
        data_type: int32
      - name: Total_revenue_STP15
        address: 30529
        input_type: input
        count: 2
        slave: 3
        unit_of_measurement: Wh
        data_type: int32
      - name: Daily_revenue_STP15
        address: 30535
        input_type: input
        count: 2
        slave: 3
        unit_of_measurement: Wh
        data_type: int32
      - name: Temperature_STP15
        address: 30953
        input_type: input
        count: 2
        slave: 3
        unit_of_measurement: °C
        data_type: int32

Thank you very much for sharing. That’s easier and more flexible than using the script provided earlier.
I have to test it on the weekend with my charger, but do I understand correctly that you only read values with this method? It would be especially interesting to also set values, thus being able to program smart charging for dynamic power prices and things like that.

Up to now it’s only for reading values. There are also RESTful Switch and a RESTful Command integrations which should work similar as the sensor but of course with different endpoints. I haven’t tried it yet.
But I guess it will be a little bit more messy in your configuration as you will need to use helpers and templates to achieve a nice user experience.

I will try and see if I can get it to work, with the first steps opened by your approach…
I have helpers anyway for the NodeRed version linked in on of my earlier posts, but I would prefer doing it the direct way (never became a friend with NodeRed).

I found out that it is possible to change values using the rest_command integration.

First of all you can read several parameters with the following example (charging mode in this case). Note that you need to also setup the token sensor from my previous example.

rest:
  - resource: "http://<HOST>/api/v1/parameters/search"
    method: POST
    payload: '{"queryItems":[{"componentId":"IGULD:SELF"}]}'
    scan_interval: 10
    headers:
      Authorization: "Bearer {{ state_attr('sensor.sma_ev_charger_token', 'access_token') }}"
      Content-Type: application/json
    sensor:
      - unique_id: SMA-Parameter.Chrg.ActChaMod
        name: "SMA EV Charge Mode"
        value_template: >
          {% set charge_mode=value_json[0]['values'][28]['value'] | int %}
          {% if charge_mode == 4719 %} Excess
          {% elif charge_mode == 4720 %} Target
          {% elif charge_mode == 4721 %} Stop
          {% else %} unknown
          {% endif %}

Setting a parameter can be done with the rest_command integration. This is an example also for the charging mode. The value is set as a parameter which can be later used in a template, script or automation.

rest_command:
  set_charge_mode:
    url: "http://<HOST>/api/v1/parameters/IGULD:SELF"
    method: "PUT"
    payload: >
      {
        "values":[{
          "channelId":"Parameter.Chrg.ActChaMod",
          "value":"{{ mode }}"
        }]
      }
    headers:
      Authorization: "Bearer {{ state_attr('sensor.sma_ev_charger_token', 'access_token') }}"
      Content-Type: "application/json"

The rest_command service can then be called with:

service: rest_command.set_charge_mode
data:
  mode: 4719

Basically it is possible to set up helpers, automations, template entities, etc., now. But this will be a lot of yaml-code.
We definetely need a dedicated integration. :wink:

Thank you so much!
It took a while, but now I added what you shared and it seems to work quite fine!
What I was wondering though, and I could not find an answer to that (sorry, I am really unexperienced with rest, curl and all that stuff): Is it possible to get all json-output into one sensor, so I can see what format the results from the API have and specifically select all the values I need?
I tried it with following code, but that sensor always is “unknown” instead of returning all values:

  - resource: "http://<IP>/api/v1/parameters/search"
    method: POST
    payload: '{"queryItems":[{"componentId":"IGULD:SELF"}]}'
    scan_interval: 5
    headers:
      Authorization: "Bearer {{ state_attr('sensor.sma_ev_charger_token', 'access_token') }}"
      Content-Type: application/json
    sensor:
      - unique_id: SMA-Parameter.Chrg.param
        name: "SMA EV Charger Parameter"
        value_template: "{{ value_json }}"

At least changing values should be easier, since the technical names are listed in the web-GUI of the EV Charger.
But also for that, these numeric values - like the charge mode - show up nowhere except in the API output. Plus, for setting the EV Charger to a charging target, the end time is required, which seems to be stated in seconds. Might have a hard time converting a datetime value into that number. There still are many obstacles to overcome…

I totally agree with you, having an integration or at least modbus support as promised by SMA for years would be so much easier!

And it’s finally done! I wrote a custom component which you can find here: SMA EV Charger integration for Home Assistant.
Have fun! :slight_smile:

2 Likes

Thank you very much @alengwengus, this integration works well.

  • SMA EV-Charger:
    I have made a small change: Power limitation was not working, so I switched from “Wmax” to “WmaxIn” in your number.py. Now it is working.
  • LedaTronic Integration:
    is working now, too. Some CANBus-bytes were mixed in my setup, so I re-engineered them by polling all bytes.

now I only face some HASS-specific problems and I am working on visualisation now :slight_smile:

I am struggling with units:
As you can see, power values are not the same: some are kW, some are W. I would also like to show only one digit after “.”…

I still have some problems:

  • utility-meters:
    creation in “helper”-section cannot be edited:
    after creation: If you want do delete unit-frefix, you only can change this by editing /homeassistant/-storage/core.config_entries
  • utility-meters:
    is there a “best-practice” to create utility-meters for “Energy”-dashboard?
  • Aquara ZigBee:
    after re-connecting some sensor get lost and have to be re-synced manually. That is really annoying. I will try another ZigBee-stick (at the moment: Sonoff stick)

so, more details to my integration-sensors:

one sensor is showing the “unit”-section, but this field is missing at the first sensor:

Does anybody know the reason?
All sensors were created by “Helper” - “add”… and not via YAML.
How can I fix the unit?

So, I thought deleting and re-configuring of the helper would be the solution, but some data is stored in background and all helpers come back with same unit and historical data:


let’s see, how I can fix that.