Integration with SMA Solar STP 10000TL-20 via SBFspot

I have spent few days trying to integrate my SMA inverter STP 10000TL-20 with HA and finally today I managed to pull all the data I needed.

The possible solutions I have found looking online didn’t quite work with my inverter, until I found this fantastic tool https://github.com/SBFspot/sbfspot-config
Let me walk you through the options I found in the forum, and the approach + configuration I used.

1: Direct integration using the SMA integration.
In my case this doesn’t work, as the inverter doesn’t accept direct connections.

2: Scraping www.sunnyportal.com public page
Register your inverter to www.sunnyportal.com, make the web page available publicly (e.g. https://www.sunnyportal.com/Templates/PublicPage.aspx?page=XXXXX) and scrape the data from there with the scrape integration.
See for example Scrape sensor for SMA Sunny Portal
Again, in my case this doesn’t work for a number of reasons:

  • Public page data is obsolete - I can retrieve system power from 2/3 hours ago
  • Page loads asynchronously; scrape integration can use only the original HTML, not the data updated via js calls.
  • Limited data is available: not all the parameters are available.
  • Custom page logic: complex templates have to be used to compensate for the web page business logic, e.g. sometime the values displayed are kW, others are W…
  • Lot of timeouts

Again, no go.

3: SBFspot
This is the perfect solution, also available with installer.


This is what I like:

  • It works, and connects to my inverter
  • High frequency of sampling
  • Solution can run fully locally
  • A lot of parameters are available. As we speak, this is the list available:
# Possible keywords are (if supported by your inverter):
# SBFspot Alias   Code                Description
# =======================================================================
# Timestamp                           Current date/time
# InvTime                             Inverter date/time
# SunRise                             Sunrise time
# SunSet                              Sunset time
# InvSerial                           Serial Number
# InvName         NameplateLocation   Device name
# InvClass        NameplateMainModel  Device class
# InvType         NameplateModel      Device type
# InvSwVer        NameplatePkgRev     Software package
# InvStatus       OperationHealth     Condition
# InvTemperature  CoolsysTmpNom       Operating condition temperature
# InvGridRelay    OperationGriSwStt   Grid relay/contactor
# ETotal          MeteringTotWhOut    Total yield
# EToday          MeteringDyWhOut     Day yield
# PACTot          GridMsTotW          Power
# PDC1/PDC2       DcMsWatt            DC power input String 1/2
# UDC1/UDC2       DcMsVol             DC voltage input String 1/2
# IDC1/IDC2       DcMsAmp             DC current input String 1/2
# OperTm          MeteringTotOpTms    Operating time
# FeedTm          MeteringTotFeedTms  Feed-in time
# PAC1            GridMsWphsA         Power L1
# PAC2            GridMsWphsB         Power L2
# PAC3            GridMsWphsC         Power L3
# UAC1            GridMsPhVphsA       Grid voltage phase L1
# UAC2            GridMsPhVphsB       Grid voltage phase L2
# UAC3            GridMsPhVphsC       Grid voltage phase L3
# IAC1            GridMsAphsA_1       Grid current phase L1
# IAC2            GridMsAphsB_1       Grid current phase L2
# IAC3            GridMsAphsC_1       Grid current phase L3
# GridFreq        GridMsHz            Grid frequency
# BatTmpVal       BatTmpVal           Battery temperature
# BatVol          BatVol              Battery voltage
# BatAmp          BatAmp              Battery current
# BatChaStt       BatChaStt           Current battery charge status

The tool runs a cron job that connects to the inverter, and stores data locally in a database or in CSV files. It also uploads the data to PVOutput. Recently also to MQTT… Bingo!

Depending on your preferences, to connect to HA you can use:

  • PVOutput integration: not my favourite option, as I have to push my data to an external service and retrieve it from there. I prefer to keep the solution limited to my local network.
  • Database integration: it’s an option.
  • MQTT: my favourite option.

How to get it working?

1: Install SBFspot as per https://github.com/SBFspot/sbfspot-config
2: Complete the setup using the UI.
Once completed, check your setup file - in my case the path was /usr/local/bin/sbfspot.3/SBFspot.cfg

Some important settings to get MQTT working with HA:

MQTT_Topic=sbfspot/serialnumber
MQTT_ItemFormat="{key}": {value}
MQTT_ItemDelimiter=comma
MQTT_PublisherArgs=-h {host} -t {topic} -m "{{message}}"

if your MQTT has user/password, don’t forget to include them

MQTT_PublisherArgs=-h {host} -t {topic} -m "{{message}}" -u username -P password

MQTT_Data=SunRise,SunSet,InvStatus,InvTemperature,InvGridRelay,ETotal,EToday,PACTot,PDC1,PDC2,UDC1,UDC2,IDC1,IDC2,OperTm,FeedTm,PAC1,PAC2,PAC3,UAC1,UAC2,UAC3,IAC1,IAC2,IAC3,GridFreq

In MQTT_Data you can select what fields will be published.
IMPORTANT: Check the json generated, by subscribing to the topic via mosquitto_sub or HA. If the payload is too long, the json is truncated and cannot be parse by HA (bug). The list of parameters I have published above works for me.

3: Subscribe to the MQTT topic and check what is getting published. Amend your config file as required. In my case I would use:

mosquitto_sub -h localhost -t sbfspot/serialnumber -d -u username -P password

To force a reading to be generated, you can find the scripts used by running

crontab -l

In my case it was

/usr/local/bin/sbfspot.3/daydata

4: Add the setup to HA.
For my data, the setup is as follows:

configuration.yaml:

sensor Solar:
  - platform: mqtt
    state_topic: "sbfspot/123456"
    name: "Inverter Sunrise"
    value_template: "{{ value_json.SunRise }}"
  - platform: mqtt
    state_topic: "sbfspot/123456"
    name: "Inverter Sunset"
    value_template: "{{ value_json.SunSet }}"
  - platform: mqtt
    state_topic: "sbfspot/123456"
    name: "Inverter Status"
    value_template: "{{ value_json.InvStatus }}"
  - platform: mqtt
    state_topic: "sbfspot/123456"
    name: "Inverter Temperature"
    value_template: "{{ value_json.InvTemperature }}"
    unit_of_measurement: '°F'
    device_class: temperature
  - platform: mqtt
    state_topic: "sbfspot/123456"
    name: "Inverter Grid Relay/Contactor"
    value_template: "{{ value_json.InvGridRelay }}"
  - platform: mqtt
    state_topic: "sbfspot/123456"
    name: "Inverter Total Yeld"
    value_template: "{{ value_json.ETotal }}"
    unit_of_measurement: 'kWh'
    icon: mdi:solar-power
  - platform: mqtt
    state_topic: "sbfspot/123456"
    name: "Inverter Today Yeld"
    value_template: "{{ value_json.EToday }}"
    unit_of_measurement: 'kWh'
    icon: mdi:solar-power
  - platform: mqtt
    state_topic: "sbfspot/123456"
    name: "Inverter Instant Power"
    value_template: "{{ value_json.PACTot | int }}"
    unit_of_measurement: 'W'
    device_class: power
    icon: mdi:solar-power
  - platform: mqtt
    state_topic: "sbfspot/123456"
    name: "DC Power String 1"
    value_template: "{{ value_json.PDC1 }}"
    unit_of_measurement: 'W'
    device_class: power
    icon: mdi:solar-power
  - platform: mqtt
    state_topic: "sbfspot/123456"
    name: "DC Power String 2"
    value_template: "{{ value_json.PDC2 }}"
    unit_of_measurement: 'W'
    device_class: power
    icon: mdi:solar-power
  - platform: mqtt
    state_topic: "sbfspot/123456"
    name: "DC Voltage String 1"
    value_template: "{{ value_json.UDC1 }}"
    unit_of_measurement: 'V'
    icon: mdi:solar-power
  - platform: mqtt
    state_topic: "sbfspot/123456"
    name: "DC Voltage String 2"
    value_template: "{{ value_json.UDC2 }}"
    unit_of_measurement: 'V'
    icon: mdi:solar-power
  - platform: mqtt
    state_topic: "sbfspot/123456"
    name: "DC Current String 1"
    value_template: "{{ value_json.IDC1 }}"
    unit_of_measurement: 'A'
    icon: mdi:solar-power
  - platform: mqtt
    state_topic: "sbfspot/123456"
    name: "DC Current String 2"
    value_template: "{{ value_json.IDC2 }}"
    unit_of_measurement: 'A'
    icon: mdi:solar-power
  - platform: mqtt
    state_topic: "sbfspot/123456"
    name: "Inverter Operating time"
    value_template: "{{ value_json.OperTm }}"
    unit_of_measurement: 's'
  - platform: mqtt
    state_topic: "sbfspot/123456"
    name: "Inverter Feed-in time"
    value_template: "{{ value_json.FeedTm }}"
    unit_of_measurement: 's'
  - platform: mqtt
    state_topic: "sbfspot/123456"
    name: "AC Power L1"
    value_template: "{{ value_json.PAC1 }}"
    unit_of_measurement: 'W'
    device_class: power
    icon: mdi:solar-power
  - platform: mqtt
    state_topic: "sbfspot/123456"
    name: "AC Power L2"
    value_template: "{{ value_json.PAC2 }}"
    unit_of_measurement: 'W'
    device_class: power
    icon: mdi:solar-power
  - platform: mqtt
    state_topic: "sbfspot/123456"
    name: "AC Power L3"
    value_template: "{{ value_json.PAC3 }}"
    unit_of_measurement: 'W'
    device_class: power
    icon: mdi:solar-power
  - platform: mqtt
    state_topic: "sbfspot/123456"
    name: "AC Voltage L1"
    value_template: "{{ value_json.UAC1 }}"
    unit_of_measurement: 'V'
    icon: mdi:solar-power
  - platform: mqtt
    state_topic: "sbfspot/123456"
    name: "AC Voltage L2"
    value_template: "{{ value_json.UAC2 }}"
    unit_of_measurement: 'V'
    icon: mdi:solar-power
  - platform: mqtt
    state_topic: "sbfspot/123456"
    name: "AC Voltage L3"
    value_template: "{{ value_json.UAC3 }}"
    unit_of_measurement: 'V'
    icon: mdi:solar-power
  - platform: mqtt
    state_topic: "sbfspot/123456"
    name: "AC Current L1"
    value_template: "{{ value_json.IAC1 }}"
    unit_of_measurement: 'A'
    icon: mdi:solar-power
  - platform: mqtt
    state_topic: "sbfspot/123456"
    name: "AC Current L2"
    value_template: "{{ value_json.IAC2 }}"
    unit_of_measurement: 'A'
    icon: mdi:solar-power
  - platform: mqtt
    state_topic: "sbfspot/123456"
    name: "AC Current L3"
    value_template: "{{ value_json.IAC3 }}"
    unit_of_measurement: 'A'
    icon: mdi:solar-power
  - platform: mqtt
    state_topic: "sbfspot/123456"
    name: "Inverter Grid Frequency"
    value_template: "{{ value_json.GridFreq }}"
    unit_of_measurement: 'hz'
    icon: mdi:solar-power

groups.yaml:

sma_inverter:
  name: SMA Inverter 
  entities:
    - sensor.ac_current_l1
    - sensor.ac_current_l2 
    - sensor.ac_current_l3
    - sensor.ac_power_l1
    - sensor.ac_power_l2
    - sensor.ac_power_l3
    - sensor.ac_voltage_l1
    - sensor.ac_voltage_l2
    - sensor.ac_voltage_l3
    - sensor.dc_current_string_1
    - sensor.dc_current_string_2
    - sensor.dc_power_string_1
    - sensor.dc_power_string_2
    - sensor.dc_voltage_string_1
    - sensor.dc_voltage_string_2
    - sensor.inverter_feed_in_time
    - sensor.inverter_operating_time
    - sensor.inverter_grid_frequency
    - sensor.inverter_grid_relay_contactor
    - sensor.inverter_status
    - sensor.inverter_sunrise
    - sensor.inverter_sunset
    - sensor.inverter_temperature
    - sensor.inverter_instant_power
    - sensor.inverter_today_yeld
    - sensor.inverter_total_yeld

5: Restart everything, and it should work!
Forgot to mention… Once the sun is down, you won’t be able to connect to the inverter, hence all the “unknown” in my screenshot!

11 Likes

Thanks for this - I’ve been sitting on an older version of SBFSpot for years, and was “integrating” via PVOutput. Have now upgraded and got the option of both MQTT and PVOutput now.

1 Like

Just wanted to add my thanks! Just got this working on my SMA 2000 which doesn’t have webconnect.

I installed SBFSpot on a new Windows 10 install. During install got two separate missing DLL errors which were solved by installing Visual Basic 2015 C+= redistributables for BOTH x64 and x86.

On Windows the command to generate a reading is:
"C:\\Program Files (x86)\SpfSpot.3\SBFSpot.exe" -v -finq -nocsv -mqtt
This is the command you’ll repeat in Task Scheduler every X minutes.

Don’t make the same mistake I did and type “-p” for password in MQTT_PublisherArgs . Copy and paste instead! The lowercase p will give you an “Invalid Port” error which takes hours to figure out :stuck_out_tongue:

Hi @thoughton,
I allready use SBF spot for exporting a CSV to PVDiary, a solar panel logging system.

That works fine, and now I would like to extend this and export MQTT to HA.

Can I just add -mqtt to my export string?
What exacty do I need to put in my configuration .Yaml?

Kind regards,

My configuration.yaml looks very much like poggialb posted above, except my topic ID numbers are different. It’s mqtt sensors and nothing else.

From memory you just add your mqtt details in the sbfspot config file (poggialb discusses this in his post when he says “Some important settings to get MQTT working with HA:”.

And then just execute sbfspot with the -mqtt argument every X minutes.

Hi

Im using SBFspot in Windows to read my SMA. I works fine, and now tried to get it to work in HA. NO GO.

I copied the config above, even tried many other setting (to the point i confuse myself…lol)

If is do a manual “pub” i get the value into HA, but SBFSpot dont want to send values when it runs.

Please help

Works (XX just for security)
Manual send : mosquitto_pub -h 192.168.x.xx -p 1883 -u xx -P xx -t sbfspot/PDC1 -m “100”

But SBFSpot with this DONT WORK

MQTT_Publisher=%ProgramFiles%\mosquitto\mosquitto_pub.exe
MQTT_Host=192.168.1.73
MQTT_Port=1883
MQTT_Topic=sbfspot
MQTT_ItemFormat="{key}": {value}
MQTT_ItemDelimiter=comma
MQTT_PublisherArgs=-h {host} -p {port} -t {topic} -m “{{message}}” -u xx -P xx
MQTT_Data=SunRise,SunSet,InvStatus,InvTemperature,InvGridRelay,ETotal,EToday,PACTot,PDC1,PDC2,UDC1,UDC2,IDC1,IDC2,OperTm,FeedTm,PAC1,PAC2,PAC3,UAC1,UAC2,UAC3,IAC1,IAC2,IAC3,GridFreq

What am i missing ?

…can SBFSpot do MQTT and MySQL at the same time.

Ok I CANT READ!!!

the -mqtt ( On Windows the command to generate a reading is:
"C:\\Program Files (x86)\SpfSpot.3\SBFSpot.exe" -v -finq -nocsv -mqtt) got me. Its working fine

1 Like

Thank you very much!

I got it working, mqtt user is required, not optional which I first thought due mqtt already working while never entered username and password but it was an integration so seems work differently for those.

Now looking to intregrate into new energy dashboard in Home assistant 2021.8, it doesn’t show in entities list but I’m trying to use platform integration to create new kwh property.

It would be nice to get original kwh entitie to get showing into energy dashboard choice list.

Thank you very much for this @poggialb, also managed to get it work.

@jaan I am ideally looking to integrated this with the new Energy Dashboard, so if you are anyone makes progress on this, please can you update us here.

Cheers for that I’ve now got my SMA invertor talking via MQTT as well as PVOutput

I’m also trying to get it connected to the new energy dashboard and I believe it’s because the power generation values are missing two attributes state_class: measurement (See below) and last_reset: which I haven’t figured out the format with the MQTT Sensor [Edit might have figured out]

  - platform: mqtt
    state_topic: "sbfspot/123456"
    name: "Inverter Today Yield"
    value_template: "{{ value_json.EToday }}"
    unit_of_measurement: 'kWh'
    icon: mdi:solar-power
    device_class: power
    state_class: measurement
    last_reset_topic: 'sbfspot/123456'
    last_reset_value_template: '1970-01-01T00:00:00+00:00'

Been trying to do the same thing - had spfspot running for around a year on a raspberry pi taking in my data from an older sma 3600 inverter into home assistant. Have made some nice existing dashboards on generation, but would like to put into the new Energy Dashboard.

It seems that MQTT generated sensors cannot have the last_reset set which means it can’t create statistics which the new Energy dashboard needs. I’ve seen some comment about making a utility meter in configuration.yaml which can get around this with the daily attribute on it but not managed to get it working yet.

I’ve also amended the other outputs to now be device_class: power or energy and taken off the ‘’ ‘’ around appropriate unit of measurement - this should make it easier to see them in the newer HA environments

Hmm looking further into it specifically from this topic MQTT Sensor : how to define last_reset_value_template - #20 by iSteeb
I’ve updated my config and home assistant likes it but I can’t confirm until tomorrow when I have daylight. [EDIT: it works :slight_smile: ]

The other thing I think is if sbfspot itself would publish the last reset time via MQTT but I’d have to look into that aspect further.

Can you use this also with Home Assistant OS on a Raspberry PI? Thus without RaspberryOS and only have HomeAssistantIO OS installed?

Think you’d need a separate raspberry pi running Raspbian to run Spfspot - that is what I use. I run HA as a docker image on my NAS as the most stable and easiest for me. Don’t think you can run spfspot on HomeAssistant OS.

As for getting data into the new solar output part of HA I found that by creating a utility meter using the inverter_today_yield data that I didn’t need to mess with last reset time etc - which was crashing for me.

Making sure that inverter_today_yield was set as device_class power and unit as kwh allowed the utility meter to sum up the daily total and then be shown in the new solar output portion of HA.

utility_meter:
daily_solar_export:
source: sensor.inverter_today_yield
cycle: daily
monthly_solar_export:
source: sensor.inverter_today_yield
cycle: monthly

1 Like

Strange about the crashing. I ended up using the total Yield in the energy graph as the daily yield seemed to reset the graph with a negative value for the second day I guess because it starts at 0 each day and the last reset date should match that.

So excluding all the other mqtt data sbfspot sends to HomeAssistant this is the main sensor I’m using. Obviously change the 123456 to what ever your invertor Serial Number is

sensor solar:
  - platform: mqtt
    state_topic: "sbfspot/123456"
    name: "Inverter Total Yield"
    value_template: "{{ value_json.ETotal }}"
    last_reset_topic: "sbfspot/123456"
    last_reset_value_template: '1970-01-01T00:00:00+00:00'
    unit_of_measurement: kWh
    device_class: energy
    state_class: measurement
    icon: mdi:solar-power

You won’t see it as an option in the energy solar configuration until sbfspot has sent a mqtt message post adding the last_reset info either.

Also the solar predictions are pretty close to real world

4 Likes

@poggialb Just wanted to say a massive thanks for this, I moved in to place with SMA inverter 18months ago and since been trying to work out how to integrate since webconnect doesn’t work. Hour after stumbling across this post have it working :smile: and perfect timing with addition of energy functionality.

works fine, just one question, I have 2 inverters, get data from both in mqtt but on same topic, is there a way to have different topics or select them in Home assitant?

With two invertors don’t each of them have different serial numbers leading to different MQTT datasets. I’m not sure how sbfspot handles multiple invertors.