Example on how to access data of a Sunny Boy SMA solar inverter

The first 12 lines should be the same to be able to connect to the inverter.
The ID used in line 17 and 18 are part of the JSON response.
The value in “keys” should be the same, I assume.
What you could to is add a line before line 17/18 with “print r.text” to see what is the returned value.

Otherwise send me a private message, I can update the script for you to test. If it works for you, I can post the rest here

Hello,

I am not familiar with python, but do I have to install anything else?
I am running Ubuntu Server:

[11:51:37] steuerung@steuerung:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 18.04.2 LTS
Release: 18.04
Codename: bionic

[11:49:55] steuerung@steuerung:~$ python --version
Python 2.7.15rc1

The scripts gives me this error:

[11:43:18] steuerung@steuerung:~$ ./sma.py
-bash: ./sma.py: /usr/bin/python^M: bad interpreter: No such file or directory

Hi Jan,

Thanks a lot for this tutorial.

I have had the same error as Toon, but I finally managed to make the script work by changing the cmd_query_total_today and cmd_query_spot_ac_power. As you can see below, I have to include the src_serial to the message, as the original script hdo did.
For some reason, they differ from yours, while I also have a SB-4000TL. I have used Wireshark to analyze the packets sent from my PC to the inverter when using the “Sunny Explorer” S/W from SMA.
I noticed that the src_serial is NOT the serial number of my inverter. I do not know to what it corresponds, but I had to extract it from a packet analyzed with Wireshark.
For info, while “Sunny Explorer” is running and connected to the inverter, just log all packets transmitted by the PC and look for ffffffffffff00007800 which is then followed by the src_serial in hex (intel format, little endian)

cmd_query_total_today =    '534d4100000402a00000000100260010606509a0ffffffffffff00007800%s000000000000f180000200540001260022ff260000000000' % (struct.pack('<I', src_serial).encode('hex'))
cmd_query_spot_ac_power =  '534d4100000402a00000000100260010606509e0ffffffffffff00007800%s00000000000081f0000200510001260022ff260000000000' % (struct.pack('<I', src_serial).encode('hex'))
1 Like

Hi guys, just a heads up, SMA has MODBUS integrated in their inverter.
activate this in the device and just connect with the modbus binding from openhab.

i can read actual data. (total production in kWh, current production in W, status of the inverter …)

I can´t get the script to run…

  File "sma.py", line 32, in <module>
    cmd_login =                '534d4100000402a000000001003a001060650ea0ffffffffffff00017800%s00010000000004800c04fdff07000000840300004c20cb5100000000%s00000000' % (struct.pack('<I', src_serial).encode('hex'), get_encoded_pw(user_pw))
AttributeError: 'bytes' object has no attribute 'encode'

Anyone still running this script or using another solution?

Sorry no… Havn´t tried yet.

For me it still works fine. However I struggle supporting the script w/o having the hardware to debug. As kahlder pointed out there seem to be some differences between the inverters which you have to analyze with Wireshark. Or you give the modbus binding a shot.

Yeah I ll try to get something to run with the modbus binding now.

I have a Sunny Tripower 8000TL-20 inverter…

Hi Superwutz,

I’m very interested in the modbus solution.
Can you give us an example of your configurations of the things and items ?

I’m also trying to get a connection to my SMA inverter running with the help ob Modbus, but still having no look :frowning:

I was not yet able to get it to run…

Modbus example:

All done in Paper UI
create MODBUS TCP Slave Thing. = modbus bridge
IP ADRESS
Port: 502
ID:3
time between transactions 60

next Thing: SMA current Power
Modbus Binding - > Regular Poll
bridge = the one we created.
Poll interval : 500 ms
Lengt: 2
Maximum tries 3
Start: 30775
Type: Input register

next thing: Modbus binding , modbus Data

bridge = modbus poll we just created.
read adress: 30775
read value type: 32bit signed integer (int32)
read transform: default
write transform : default

This things has 11 channels, the channel : Value as number is the one i use to read out the current power production in W from my sma invertor.

1 Like

Hi Tom,

I tried to follow your example, but where do I fill in the read value type ?
In Paper UI, I only these see four options:

I also see no input fields for read transform and write transform.

Kind regards,
Pieter

Hi Tom,

Forget my previous post. In the meantime I figured it out a bit more.
Only thing is that my Modbus data stays offline. Modbus TCP Slave and Regular Poll are online.

Pieter

I suspect you use modbus2 binding?
I use modbus2 for another device (I do have an SMA solar inverter as well, but it´s not connected through modbus yet). I went for manual modbus config files, as it´s alot easier to handle. You can find my setup in this thread.

Basicly it should be the same connecting anything else using modbus2 binding, as long as you´ve got the modbus data for your inverter.
(When I get the time, I´ll try to figure how to add my SMA TPL6000 inverter through modbus as well, but I´m in no hurry, as I´ve got the SMA Energy Meter connected insted, which gives me the same detail the inverter can give me).

Hi Kim,

Thanks for your reply. I will look into the information you provided.
I use the Modbus Binding, version 2.4.0

For now I created 3 things in my configuration.

Modbus TCP slave SMA, IP-address, Id=2 (bridge)
Regular Poll wich uses the Modbus slave bridge, start address 30775, type-input register, length=2
Modbus data where the bridge selection = Regular poll and Read Address = 30775

Kind regards,
Pieter

I receive data from the Modbus now. Only thing is that it’s probably not in correct format.
Address 30775 (32bit signed integer) receives every ten seconds a permanent number: 2147483648.

Do I need some kind of conversion in the field ‘Read transform’ ?

i know it’s old discussion, but if you have BT, there is no problem to get data from SMA then
take a look here:

and here:

i like your icons, can you share where you got them ? :slight_smile:
thanks

1 Like

Hmm my SMA SunnyBoy Storage 2.5 got BT… But it´s connected via speedwire (LAN)…
My problem is, I simply cant understand this SBFspot thing, and how to get from there to openhab.
Atm I´m using the SMA Energy Meter (connected via LAN) and the openhab binding. But it really lack information and options, which is in the Energy Meter. I have tried rise an request, but I dont think there is anymore support or development for the binding anymore.