Page 1 of 5

SMA Sunny Boy 1.5

Posted: Thursday 18 July 2019 19:52
by merlot
Hello,
After trying to search some plugin to get the instant power and generated energy of my SMA Sunny Boy inverter 1.5 I've found nothing for domoticz or the solutions were for an inverter with MODBUS or similar.
Then came through a script in the openhab forum that, with the keys I captured for my device, worked fine. So, I've developed my own plugin, a very simple one but it works.
I don't have a github account, so far, then let me put in here just in case you want to use it, or even better, improve it.
Spoiler: show
# SMA Sunny Boy 1.5 Python Plugin for Domoticz
#
# Author: merlot
#

"""
<plugin key="SunnyBoy15" name="SMA Sunny Boy 1.5 Solar Inverter" author="merlot" version="1.0.0">
<description>
<h2>SMA Sunny Boy 1.5 Solar Inverter Plugin</h2><br/>
<h3>Features</h3>
<ul style="list-style-type:square">
<li>Register instant power and dayly generated energy</li>
</ul>
</description>
<params>
<param field="Address" label="IP Address" width="200px" required="true"/>
<param field="Password" label="User group password" width="200px" required="true" password="true"/>
<param field="Mode6" label="Debug" width="75px">
<options>
<option label="True" value="Debug"/>
<option label="False" value="Normal" default="true"/>
</options>
</param>
</params>
</plugin>
"""

import sys
sys.path.append('/usr/local/lib/python3.5/dist-packages/')

try:
import Domoticz
except ImportError:
import fakeDomoticz as Domoticz

import json
import requests

class BasePlugin:
enabled = False
lastPolled = 0
lastResponse = 0

def __init__(self):
return

def onStart(self):
Domoticz.Log("onStart called")
if Parameters["Mode6"] == "Debug":
Domoticz.Debugging(1)
else:
Domoticz.Debugging(0)
if (len(Devices) == 0):
Domoticz.Device("pv watt", 1, "Custom", Options = { "Custom" : "1;W"}).Create()
Domoticz.Device("wh today", 2, "Custom", Options = { "Custom" : "1;Wh"}).Create()
Domoticz.Device("kwh total", 3, "Custom", Options = { "Custom" : "1;kWh"}).Create()
DumpConfigToLog()
Domoticz.Log("Plugin is started.")
# If Heartbeat>30 you'll get the error thread seems to have ended unexpectedly
# https://www.domoticz.com/wiki/Developin ... #Callbacks
Domoticz.Heartbeat(20)

def onStop(self):
Domoticz.Log("onStop called")

def onConnect(self, Connection, Status, Description):
Domoticz.Log("onConnect called")

def onMessage(self, Connection, Data, Status, Extra):
Domoticz.Log("onMessage called")

def onCommand(self, Unit, Command, Level, Hue):
Domoticz.Log("onCommand called for Unit " + str(Unit) + ": Parameter '" + str(Command) + "', Level: " + str(Level))

def onNotification(self, Name, Subject, Text, Status, Priority, Sound, ImageFile):
Domoticz.Log("Notification: " + Name + "," + Subject + "," + Text + "," + Status + "," + str(Priority) + "," + Sound + "," + ImageFile)

def onDisconnect(self, Connection):
Domoticz.Log("onDisconnect called")

def onHeartbeat(self):
Domoticz.Log("onHeartbeat called "+ str(self.lastPolled))
## Read SMA Inverter ##
url_base="http://" + Parameters["Address"] + "/dyn/"
url=url_base + "login.json"
payload = ('{"pass" : "' + Parameters["Password"] + '", "right" : "usr"}')
headers = {'Content-Type': 'application/json', 'Accept-Charset': 'UTF-8'}

self.lastPolled = self.lastPolled + 1
if (self.lastPolled > 3): self.lastPolled = 1
if (self.lastPolled == 1):
try:
r = requests.post(url, data=payload, headers=headers)
except:
Domoticz.Log("Error accessing SMA inverter on "+Parameters["Address"])
else:
j = json.loads(r.text)
try:
sid = j['result']['sid']
except:
Domoticz.Log("No response from SMA inverter on "+Parameters["Address"])
else:
url = url_base + "getValues.json?sid=" + sid
payload = ('{"destDev":[],"keys":["6400_00260100","6400_00262200","6100_40263F00"]}')
headers = {'Content-Type': 'application/json', 'Accept-Charset': 'UTF-8'}

try:
r = requests.post(url, data=payload, headers=headers)
except:
Domoticz.Log("No data from SMA inverter on "+Parameters["Address"])
else:
j = json.loads(r.text)

sma_pv_watt = j['result']['012F-730B00E6']['6100_40263F00']['1'][0]['val']
if sma_pv_watt is None:
sma_pv_watt = 0
sma_kwh_today = j['result']['012F-730B00E6']['6400_00262200']['1'][0]['val']
sma_kwh_total = j['result']['012F-730B00E6']['6400_00260100']['1'][0]['val']/1000

# Domoticz.Log(r.text)
# Domoticz.Log(str(sma_pv_watt))
# Domoticz.Log(str(sma_kwh_today))

Devices[1].Update(nValue=sma_pv_watt, sValue=str(sma_pv_watt))
Devices[2].Update(nValue=sma_kwh_today, sValue=str(sma_kwh_today))
sValue="%.2f" % sma_kwh_total
Devices[3].Update(nValue=0, sValue=sValue.replace('.',','))


global _plugin
_plugin = BasePlugin()

def onStart():
global _plugin
_plugin.onStart()

def onStop():
global _plugin
_plugin.onStop()

def onConnect(Connection, Status, Description):
global _plugin
_plugin.onConnect(Connection, Status, Description)

def onMessage(Connection, Data, Status, Extra):
global _plugin
_plugin.onMessage(Connection, Data, Status, Extra)

def onCommand(Unit, Command, Level, Hue):
global _plugin
_plugin.onCommand(Unit, Command, Level, Hue)

def onNotification(Name, Subject, Text, Status, Priority, Sound, ImageFile):
global _plugin
_plugin.onNotification(Name, Subject, Text, Status, Priority, Sound, ImageFile)

def onDisconnect(Connection):
global _plugin
_plugin.onDisconnect(Connection)

def onHeartbeat():
global _plugin
_plugin.onHeartbeat()

# Generic helper functions
def DumpConfigToLog():
for x in Parameters:
if Parameters[x] != "":
Domoticz.Debug( "'" + x + "':'" + str(Parameters[x]) + "'")
Domoticz.Debug("Device count: " + str(len(Devices)))
for x in Devices:
Domoticz.Debug("Device: " + str(x) + " - " + str(Devices[x]))
Domoticz.Debug("Device ID: '" + str(Devices[x].ID) + "'")
Domoticz.Debug("Device Name: '" + Devices[x].Name + "'")
Domoticz.Debug("Device nValue: " + str(Devices[x].nValue))
Domoticz.Debug("Device sValue: '" + Devices[x].sValue + "'")
Domoticz.Debug("Device LastLevel: " + str(Devices[x].LastLevel))
return
Just
- create a directory under the plugin one, like SMA_Sunny_Boy
- copy&paste the code in a plugin.py file
- restart domoticz
- Add the device, introducing the IP and User group password

That's all

Image

I have also updated to 4.10717 and I'm having some crashes, so I don't know if it's due to the plugin, that seems so simple to cause it, or it's the version since I've seen some other experiencing a similar issue.

Comments and improvements are welcome

Thank you

Re: SMA Sunny Boy 1.5

Posted: Friday 19 July 2019 14:41
by sincze
Excellent.
Tnx for Sharing :lol:

Re: SMA Sunny Boy 1.5

Posted: Friday 19 July 2019 23:29
by merlot
I have set up a github, just to look like an experienced programmer :lol: :lol: :lol:

https://github.com/merlot-dev/Domoticz-SMA-SunnyBoy

I hope it works

Re: SMA Sunny Boy 1.5

Posted: Sunday 21 July 2019 10:04
by Pat303
Hi merlot,

Thanks for sharing your SMA plugin for Domoticz.

I just tested it as I have a SMA Sunny Boy 3.0 but I have these errors:

2019-07-21 09:11:23.623 Error: (SMA Sunny Boy 3.0) 'onHeartbeat' failed 'TypeError':'Can't convert 'NoneType' object to str implicitly'.
2019-07-21 09:11:23.623 Error: (SMA Sunny Boy 3.0) ----> Line 163 in '/home/pi/domoticz/plugins/Domoticz-SMA-SunnyBoy/plugin.py', function onHeartbeat
2019-07-21 09:11:23.623 Error: (SMA Sunny Boy 3.0) ----> Line 103 in '/home/pi/domoticz/plugins/Domoticz-SMA-SunnyBoy/plugin.py', function onHeartbeat


Any idea of the issue?

Re: SMA Sunny Boy 1.5

Posted: Sunday 21 July 2019 17:17
by merlot
I'm sorry but I don't know 3.0 version of Sunny Boy and probably it won't work. Or the ID's are different

Anyway, put some Domoticz.Log(r.text) after the requests to see what you get from it and modify the script to adapt it to that device

Re: SMA Sunny Boy 1.5

Posted: Sunday 21 July 2019 17:34
by merlot
I have create a v2 version to change from a Custom sensor to a type kWh, but I don't understand how it works.

From the inverter I get:
- instant power (W)
- Dayly generated Energy (kWh)
- Total generated Energy (kWh)

The device type kWh can be updated with two values, power and energy, and I expected it to be the daily on, but what I see in the Utility screen is

Image

That is, the instant power I get and, I guess, the daily calculated Energy, but not the Dayly Energy I'm getting from the device. I can see this value got from the device in the device administration

Image

I've seen some kWh devices where 3 values are shown: power, daily energy and total, like this

Image

How can I get this?

In the other hand, which are the types of device that suit more the data I get.

Thank you very much

Re: SMA Sunny Boy 1.5

Posted: Tuesday 18 February 2020 14:25
by akortekaas
Thanks for the plugin, it works very well :)

The only thing i had to change was the 012F-730BXXXX number, the last 4 digits were different for me.

For those who don't know how to get this number:

-Download and install wireshark (free packet sniffer software)
-in wireshark click the connection which your pc uses to connect to lan.
-Apply a filter to the address bar so you will only see traffic from your sunny boy to your pc: "ip.src ==xxx.xxx.xxx.xxx" (replace xxx.xxx.xxx.xxx with the ip of the sunny boy inverter.
Make sure you are logged in on the sunny boy inverter web portal on a browser as user and you see actual data from your inverter (the packet sniffer will read from this)
-Then click the blue shark icon in wireshark to start sniffing packets, turn it off after a few seconds.
-now you should have a list of nonsense with a few lines that look like this: "276 HTTP/1.0 200 OK (application/json)" these are the packets that contain the user id. (012f number)
-Click on one of the application/json entries and in the window below you will see a bunch of stuff (sometimes you will need to click the ">" arrow a few times to expand the code)
-somewere in there or multiple times is your 012F code, as far as i know there only should be one, so if you find one, you should be done.

Now you need to change the 012f number in the plugin to your unique number ( it's in Domoticz-SMA-SunnyBoy/plugin.py after you installed the plugin, there are 3 instances of this number that need to be changed)
I don't know enough about linux and stuff to give more clear instructions about this part.

Re: SMA Sunny Boy 1.5

Posted: Tuesday 18 February 2020 19:12
by jeroenkl
akortekaas wrote: Tuesday 18 February 2020 14:25 Thanks for the plugin, it works very well :)

The only thing i had to change was the 012F-730BXXXX number, the last 4 digits were different for me.

For those who don't know how to get this number:

-Download and install wireshark (free packet sniffer software)
-in wireshark click the connection which your pc uses to connect to lan.
-Apply a filter to the address bar so you will only see traffic from your sunny boy to your pc: "ip.src ==xxx.xxx.xxx.xxx" (replace xxx.xxx.xxx.xxx with the ip of the sunny boy inverter.
Make sure you are logged in on the sunny boy inverter web portal on a browser as user and you see actual data from your inverter (the packet sniffer will read from this)
-Then click the blue shark icon in wireshark to start sniffing packets, turn it off after a few seconds.
-now you should have a list of nonsense with a few lines that look like this: "276 HTTP/1.0 200 OK (application/json)" these are the packets that contain the user id. (012f number)
-Click on one of the application/json entries and in the window below you will see a bunch of stuff (sometimes you will need to click the ">" arrow a few times to expand the code)
-somewere in there or multiple times is your 012F code, as far as i know there only should be one, so if you find one, you should be done.

Now you need to change the 012f number in the plugin to your unique number ( it's in Domoticz-SMA-SunnyBoy/plugin.py after you installed the plugin, there are 3 instances of this number that need to be changed)
I don't know enough about linux and stuff to give more clear instructions about this part.
thxs, I've caputered my SMA2.5 ID. But still got this as error:

2020-02-18 19:10:31.769 Error: (SMA zolder) 'onHeartbeat' failed 'KeyError'.
2020-02-18 19:10:31.769 Error: (SMA zolder) ----> Line 170 in '/home/pi/domoticz/plugins/Domoticz-SMA-SunnyBoy/plugin.py', function onHeartbeat
2020-02-18 19:10:31.769 Error: (SMA zolder) ----> Line 122 in '/home/pi/domoticz/plugins/Domoticz-SMA-SunnyBoy/plugin.py', function onHeartbeat

need advice, who can assist please?

BR, Jeroen

Re: SMA Sunny Boy 1.5

Posted: Tuesday 18 February 2020 19:30
by akortekaas
The only thing i could think if is a typo in the 012f key, did you copy caps/ no caps ?, i think that is important.

I don't know enough about this stuff to think of something else.

Since you have a different version of Sunny Boy another option might be that the 6400 numbers are different.
You can check this out by going to your sma webpage, look for a value that is in this script, total kwh generated is easiest to spot.
And then use wireshark again in the same way and look through different json packets until you find a 6xxx-xxxxxx number with the same kwh value behind it.
If your SMA does not use the same 6xxx id's for the values as in this script, you can find them all yourself by matching values from the sunny boy webpage to id + value in the packets and then change the 3 6xxx id's that are used by this script in plugin.py.

Re: SMA Sunny Boy 1.5

Posted: Wednesday 19 February 2020 13:04
by jeroenkl
akortekaas wrote: Tuesday 18 February 2020 19:30 The only thing i could think if is a typo in the 012f key, did you copy caps/ no caps ?, i think that is important.

I don't know enough about this stuff to think of something else.

Since you have a different version of Sunny Boy another option might be that the 6400 numbers are different.
You can check this out by going to your sma webpage, look for a value that is in this script, total kwh generated is easiest to spot.
And then use wireshark again in the same way and look through different json packets until you find a 6xxx-xxxxxx number with the same kwh value behind it.
If your SMA does not use the same 6xxx id's for the values as in this script, you can find them all yourself by matching values from the sunny boy webpage to id + value in the packets and then change the 3 6xxx id's that are used by this script in plugin.py.
Hi, thanks for your reply.

The id key is correct and double checked.
The 6400 numbers are the same for my device, so that's not the problem..
Still investigating

BR,
Jeroen

Re: SMA Sunny Boy 1.5

Posted: Wednesday 19 February 2020 14:42
by akortekaas
I'm sure you have already tried this but if you google the phrase "'onHeartbeat' failed KeyError" there are a lot of other people with the same error with other hardware in domoticz and one of their solutions may work for you ?

Re: SMA Sunny Boy 1.5

Posted: Wednesday 19 February 2020 19:09
by jeroenkl
akortekaas wrote: Wednesday 19 February 2020 14:42 I'm sure you have already tried this but if you google the phrase "'onHeartbeat' failed KeyError" there are a lot of other people with the same error with other hardware in domoticz and one of their solutions may work for you ?
I could be caused by too old SMA firmware.
I'm running 2.3.2.R and last version is 3.10.05.R

whuch version are you running on your SMA akortekaas?

Re: SMA Sunny Boy 1.5

Posted: Wednesday 19 February 2020 19:23
by akortekaas
2.5.2r.

Re: SMA Sunny Boy 1.5

Posted: Thursday 19 March 2020 22:54
by rklomp
I had my SMA inverter installed last week and experienced the same issues with the original plugin, so I decided to do a complete rewrite.

My version can be found here:
https://github.com/rklomp/Domoticz-SMA-SunnyBoy

Feel free to try it out and post any issues you have.
I am currently running it with a SB 3.6 on firmware version 3.10.16.R

Re: SMA Sunny Boy 1.5

Posted: Monday 06 April 2020 2:05
by Carthman
Hello,

I plan to get a PV installation with SMA inverter.
I will need the actual and instantaneous value of PV production for regulation.

I see "PV Watt" value when you add the device, is it the instantaneous PV production ?
So with this, no need for a current clamp at the inverter output to measure the PV production ?

Re: SMA Sunny Boy 1.5

Posted: Monday 06 April 2020 2:16
by akortekaas
I think that is what you mean but i don't know much about this stuff.

The value's i am getting are total kwh (no idea if this is over total lifetime of the inverter or since last reboot etc), today's kwh and current watt (which i guess is what you are looking for, it goes higher when the sun shines).

Re: SMA Sunny Boy 1.5

Posted: Monday 06 April 2020 15:53
by Carthman
Yes, I will need the current watts value !
So this value, for you, goes higher to a maximum during the day when it's sunny, and 0 during the night ?
So this value is exactly the current PV production injected on your electric grid ?

Re: SMA Sunny Boy 1.5

Posted: Monday 06 April 2020 16:13
by akortekaas
yes.

Re: SMA Sunny Boy 1.5

Posted: Monday 06 April 2020 21:05
by jeroenkl
rklomp wrote: Thursday 19 March 2020 22:54 I had my SMA inverter installed last week and experienced the same issues with the original plugin, so I decided to do a complete rewrite.

My version can be found here:
https://github.com/rklomp/Domoticz-SMA-SunnyBoy

Feel free to try it out and post any issues you have.
I am currently running it with a SB 3.6 on firmware version 3.10.16.R
thanks!

Re: SMA Sunny Boy 1.5

Posted: Friday 10 April 2020 7:06
by svdhaar
rklomp wrote: Thursday 19 March 2020 22:54 I had my SMA inverter installed last week and experienced the same issues with the original plugin, so I decided to do a complete rewrite.

My version can be found here:
https://github.com/rklomp/Domoticz-SMA-SunnyBoy

Feel free to try it out and post any issues you have.
I am currently running it with a SB 3.6 on firmware version 3.10.16.R
Hi Rene, first need to say that i'm not a developer :-). I've installed Git, python, Domoticz on my Synology nas.

I have installed your script and the SMA hardware is showing. But when i add this new device, there is an error in the domoticz log:

2020-04-10 06:57:19.354 Error: (SMASunnyBoy) failed to load 'plugin.py', Python Path used was '/usr/local/domoticz/var/plugins/Domoticz-SMA-SunnyBoy/:/volume1/@appstore/py3k/usr/local/lib/python35.zip:/volume1/@appstore/py3k/usr/local/lib/python3.5/:/volume1/@appstore/py3k/usr/local/lib/python3.5/plat-linux:/volume1/@appstore/py3k/usr/local/lib/python3.5/lib-dynload:/volume1/@appstore/py3k/usr/local/lib/python3.5/site-packages'.
2020-04-10 06:57:19.355 Error: (SMA Omvormer) Module Import failed, exception: 'ImportError'
2020-04-10 06:57:19.355 Error: (SMA Omvormer) Module Import failed: ' Name: requests'
2020-04-10 06:57:19.355 Error: (SMA Omvormer) Error Line details not available.

any idea what i'm doing wrong?