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

Hi Toon,

The Installer pwd is different in my case, but I’m not sure if that’s the problem.
I will try this today in my configuration.

Groeten,
Pieter

Hi Toon,

Your solution didn’t work for me. I received no reply at all.
Does the SunnyBoy communicate through Webconnect, TCP or UDP ?

My inverter has only the webconnect enabled.

Kind regards,
Pieter

Hi Jan,

I’d appreciate if you could help rewriting the code to allow for longer passwords. That’s outside my reach…

Thank you,
Toon

Thank you for the tutorial, it works like a charm.
As I have a SunnyBoy2.5 I had to create a custom Python program to read the integrated webserver.
I’m not sure if all fields are the same (ID can differ per inverter).
I can post an example to test, if wanted

Hi Lennert,

I’m very interested in your script, since I have the same inverter.
Could you place your version of the script in this topic ?

Kind regards,
Pieter Bruinsma

Here you are, very basic but it works. Change IP and password accordingly :slight_smile:
The only thing I’m not sure about are the ID/references, these might be different for you.
I’ve found out by running the script in parts and using “print r.text”

#!/usr/bin/python
import json
import requests
Total=0
Today=0
url = ‘http://192.168.1.31/dyn/login.json
payload = (‘{“pass” : “YourPassHere”, “right” : “usr”}’)
headers = {‘Content-Type’: ‘application/json’, ‘Accept-Charset’: ‘UTF-8’}
r = requests.post(url, data=payload, headers=headers)
j = json.loads(r.text)
sid = j[‘result’][‘sid’]
url = ‘http://192.168.1.31/dyn/getValues.json?sid=’ + sid
payload = (‘{“destDev”:,“keys”:[“6400_00260100”,“6400_00262200”]}’)
headers = {‘Content-Type’: ‘application/json’, ‘Accept-Charset’: ‘UTF-8’}
r = requests.post(url, data=payload, headers=headers)
j = json.loads(r.text)
Total = j[‘result’][‘012F-730ACDF3’][‘6400_00260100’][‘1’][0][‘val’]
Today = j[‘result’][‘012F-730ACDF3’][‘6400_00262200’][‘1’][0][‘val’]
d = {}
d[“Total”] = Total
d[“Today”] = Today
print json.dumps(d, ensure_ascii=False)

Thanks Lennert,

I will try this script in short time. I assume that I can use the items as described earlier in this topic. Where in your script do I have to fill in my inverter-ID ?

Kind regards,
Pieter

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