Anyone know howto read SMA Sunny Beam data into HA?

Thx, I changed your code on my running HA system, rebooted afterwards, and it works just fine.
so every time there is an update, I’ll have to remember to add the change myself.

Hi,

I was struggling to make the smbtool working with my sunnybeam, it was always returning 0160.
It was the case with the python code, but as well for original C version that I compiled. Same in the rPi and on my mac.
I was able to connect to the sunnybeam via a windows virtual machine and the old SDC software.
So, as I was being able to read the data from SDC , I decided to go further and sniff the USB messages !

I saw that the message to get the device id was different than the tool.
SDC is sending

7EFF03404100000000900003D2F45808D4F58B7B7E

But the SunnyBeamTool (SBT) is sending:
7EFF0340410000000090000280854F2DB2E67E

Quite different. SBT is hardcoding the first byte with 7EFF03404100000000900002 while SDC is sending 7EFF03404100000000900003
The message submitted by SDC is 21 bytes while SBT is 19 bytes. I don’t really know why there is this difference and I didn’t really investigate it yet BUT I hardcoded the byte array in search_device_id() to the one sent by SDC and … Voila !
It is now working with the compiled C version, the device id is now returned by the sunnybeam and all other methods are working correctly so I can now retrieve my data !

I’m not very fluent with python, but any idea how I could have a custom version of your library, to change that part of the code so I can make it work for my sunnybeam ?
Thanks !

Hey there,

@dannerph
Thanks for the Integration.
I never thought that somebody would really implement this old hardware for homeassistant. My search was almost desperate and i couldn’t believe that somebody actually did it. Nevertheless, i did all the steps but i can’t make it work.

My Setup:
Proxmox installed on a Homeserver
I have a virtual machine on the proxmox for Home Assistant.

I passthrough the usb device with gui setting and by changing /etc/pve/qemuserver/xxx.conf

When i check for usb devices on the virtual machine itself, the device is found.
image

When i check the entities, it only says unknown though. I don’t think i have to set the udev rules cause i pass it through to the virtual machine ?

Is there any troubleshooting i can do ?

I’d really appreciate any help

Greetings Michael

Hi @Robin61,
sorry for answering late (you need to either tag me with @dannerph or open a github issue in the repository).

Which version of sunnybeam do you have? The bluetooth version? Whould be interesting to get to know, how the different models are working. Could you provide me more information of your USB sniffing (here or via private message) so that I can have look on it?

I recently accepted a pull-request fixing escaping of certain characters in CRC calculation, which was not a problem for my device thus I have not found this bug.

Hi @Hafenmeister
you could enable debug logging for the integration and the library by adding the following to your config yaml file:

logger:
  default: warning
  logs:
    sunnybeamtool.sunnybeamtool: debug
    custom_components.sunnybeam: debug

If you run home assistant in a docker container within the virtual machine, the udev rule is most likely required, as docker containers are usually unprivileged.

Thanks for the fast reply @dannerph,

My log looks like this and goes on like this forever:

2023-03-05 14:53:16.905 WARNING (MainThread) [custom_components.sunnybeam] New data could not be fetched, try again next time.
2023-03-05 14:53:16.906 DEBUG (MainThread) [custom_components.sunnybeam] Notifying all listeners
2023-03-05 14:53:16.906 DEBUG (MainThread) [custom_components.sunnybeam.sensor] received: 0
2023-03-05 14:53:16.906 DEBUG (MainThread) [custom_components.sunnybeam.sensor] received: 0
2023-03-05 14:53:16.906 DEBUG (MainThread) [custom_components.sunnybeam.sensor] received: 0
2023-03-05 14:53:26.907 DEBUG (MainThread) [sunnybeamtool.sunnybeamtool] Sent: 7eff0340410000000080000a000000002d2e7e
2023-03-05 14:53:27.481 DEBUG (MainThread) [sunnybeamtool.sunnybeamtool] raw_read: 0160
2023-03-05 14:53:27.553 DEBUG (MainThread) [sunnybeamtool.sunnybeamtool] raw_read: 0160
2023-03-05 14:53:27.626 DEBUG (MainThread) [sunnybeamtool.sunnybeamtool] raw_read: 0160
2023-03-05 14:53:27.698 DEBUG (MainThread) [sunnybeamtool.sunnybeamtool] raw_read: 0160
2023-03-05 14:53:27.770 DEBUG (MainThread) [sunnybeamtool.sunnybeamtool] raw_read: 0160
2023-03-05 14:53:27.770 DEBUG (MainThread) [sunnybeamtool.sunnybeamtool] raw_read processed: 
2023-03-05 14:53:27.770 DEBUG (MainThread) [sunnybeamtool.sunnybeamtool] Sent: 7eff0340410000ff0010000b0f090007ac7e
2023-03-05 14:53:28.346 DEBUG (MainThread) [sunnybeamtool.sunnybeamtool] raw_read: 0160
2023-03-05 14:53:28.419 DEBUG (MainThread) [sunnybeamtool.sunnybeamtool] raw_read: 0160
2023-03-05 14:53:28.491 DEBUG (MainThread) [sunnybeamtool.sunnybeamtool] raw_read: 0160
2023-03-05 14:53:28.563 DEBUG (MainThread) [sunnybeamtool.sunnybeamtool] raw_read: 0160
2023-03-05 14:53:28.635 DEBUG (MainThread) [sunnybeamtool.sunnybeamtool] raw_read: 0160
2023-03-05 14:53:28.707 DEBUG (MainThread) [sunnybeamtool.sunnybeamtool] raw_read: 0160
2023-03-05 14:53:28.780 DEBUG (MainThread) [sunnybeamtool.sunnybeamtool] raw_read: 0160
2023-03-05 14:53:28.852 DEBUG (MainThread) [sunnybeamtool.sunnybeamtool] raw_read: 0160
2023-03-05 14:53:28.924 DEBUG (MainThread) [sunnybeamtool.sunnybeamtool] raw_read: 0160
2023-03-05 14:53:28.996 DEBUG (MainThread) [sunnybeamtool.sunnybeamtool] raw_read: 0160
2023-03-05 14:53:29.068 DEBUG (MainThread) [sunnybeamtool.sunnybeamtool] raw_read: 0160
2023-03-05 14:53:29.140 DEBUG (MainThread) [sunnybeamtool.sunnybeamtool] raw_read: 0160
2023-03-05 14:53:29.213 DEBUG (MainThread) [sunnybeamtool.sunnybeamtool] raw_read: 0160
2023-03-05 14:53:29.285 DEBUG (MainThread) [sunnybeamtool.sunnybeamtool] raw_read: 0160
2023-03-05 14:53:29.357 DEBUG (MainThread) [sunnybeamtool.sunnybeamtool] raw_read: 0160
2023-03-05 14:53:29.429 DEBUG (MainThread) [sunnybeamtool.sunnybeamtool] raw_read: 0160
2023-03-05 14:53:29.502 DEBUG (MainThread) [sunnybeamtool.sunnybeamtool] raw_read: 0160
2023-03-05 14:53:29.574 DEBUG (MainThread) [sunnybeamtool.sunnybeamtool] raw_read: 0160
2023-03-05 14:53:29.647 DEBUG (MainThread) [sunnybeamtool.sunnybeamtool] raw_read: 0160
2023-03-05 14:53:29.720 DEBUG (MainThread) [sunnybeamtool.sunnybeamtool] raw_read: 0160
2023-03-05 14:53:29.792 DEBUG (MainThread) [sunnybeamtool.sunnybeamtool] raw_read: 0160
2023-03-05 14:53:29.864 DEBUG (MainThread) [sunnybeamtool.sunnybeamtool] raw_read: 0160
2023-03-05 14:53:29.937 DEBUG (MainThread) [sunnybeamtool.sunnybeamtool] raw_read: 0160
2023-03-05 14:53:30.009 DEBUG (MainThread) [sunnybeamtool.sunnybeamtool] raw_read: 0160
2023-03-05 14:53:30.081 DEBUG (MainThread) [sunnybeamtool.sunnybeamtool] raw_read: 0160
2023-03-05 14:53:30.154 DEBUG (MainThread) [sunnybeamtool.sunnybeamtool] raw_read: 0160
2023-03-05 14:53:30.226 DEBUG (MainThread) [sunnybeamtool.sunnybeamtool] raw_read: 0160
2023-03-05 14:53:30.298 DEBUG (MainThread) [sunnybeamtool.sunnybeamtool] raw_read: 0160
2023-03-05 14:53:30.371 DEBUG (MainThread) [sunnybeamtool.sunnybeamtool] raw_read: 0160
2023-03-05 14:53:30.443 DEBUG (MainThread) [sunnybeamtool.sunnybeamtool] raw_read: 0160
2023-03-05 14:53:30.516 DEBUG (MainThread) [sunnybeamtool.sunnybeamtool] raw_read: 0160
2023-03-05 14:53:30.589 DEBUG (MainThread) [sunnybeamtool.sunnybeamtool] raw_read: 0160
2023-03-05 14:53:30.661 DEBUG (MainThread) [sunnybeamtool.sunnybeamtool] raw_read: 0160
2023-03-05 14:53:30.734 DEBUG (MainThread) [sunnybeamtool.sunnybeamtool] raw_read: 0160
2023-03-05 14:53:30.806 DEBUG (MainThread) [sunnybeamtool.sunnybeamtool] raw_read: 0160
2023-03-05 14:53:30.878 DEBUG (MainThread) [sunnybeamtool.sunnybeamtool] raw_read: 0160
2023-03-05 14:53:30.952 DEBUG (MainThread) [sunnybeamtool.sunnybeamtool] raw_read: 0160
2023-03-05 14:53:31.025 DEBUG (MainThread) [sunnybeamtool.sunnybeamtool] raw_read: 0160
2023-03-05 14:53:31.098 DEBUG (MainThread) [sunnybeamtool.sunnybeamtool] raw_read: 0160
2023-03-05 14:53:31.170 DEBUG (MainThread) [sunnybeamtool.sunnybeamtool] raw_read: 0160
2023-03-05 14:53:31.243 DEBUG (MainThread) [sunnybeamtool.sunnybeamtool] raw_read: 0160
2023-03-05 14:53:31.315 DEBUG (MainThread) [sunnybeamtool.sunnybeamtool] raw_read: 0160
2023-03-05 14:53:31.387 DEBUG (MainThread) [sunnybeamtool.sunnybeamtool] raw_read: 0160
2023-03-05 14:53:31.460 DEBUG (MainThread) [sunnybeamtool.sunnybeamtool] raw_read: 0160
2023-03-05 14:53:31.532 DEBUG (MainThread) [sunnybeamtool.sunnybeamtool] raw_read: 0160
2023-03-05 14:53:31.604 DEBUG (MainThread) [sunnybeamtool.sunnybeamtool] raw_read: 0160
2023-03-05 14:53:31.677 DEBUG (MainThread) [sunnybeamtool.sunnybeamtool] raw_read: 0160
2023-03-05 14:53:31.750 DEBUG (MainThread) [sunnybeamtool.sunnybeamtool] raw_read: 0160
2023-03-05 14:53:31.822 DEBUG (MainThread) [sunnybeamtool.sunnybeamtool] raw_read: 0160
2023-03-05 14:53:31.895 DEBUG (MainThread) [sunnybeamtool.sunnybeamtool] raw_read: 0160
2023-03-05 14:53:31.895 DEBUG (MainThread) [sunnybeamtool.sunnybeamtool] raw_read processed: 
2023-03-05 14:53:31.895 WARNING (MainThread) [custom_components.sunnybeam] New data could not be fetched, try again next time.
2023-03-05 14:53:31.896 DEBUG (MainThread) [custom_components.sunnybeam] Notifying all listeners
2023-03-05 14:53:31.896 DEBUG (MainThread) [custom_components.sunnybeam.sensor] received: 0
2023-03-05 14:53:31.896 DEBUG (MainThread) [custom_components.sunnybeam.sensor] received: 0
2023-03-05 14:53:31.896 DEBUG (MainThread) [custom_components.sunnybeam.sensor] received: 0
2023-03-05 14:53:41.896 DEBUG (MainThread) [sunnybeamtool.sunnybeamtool] Sent: 7eff0340410000000080000a000000002d2e7e
2023-03-05 14:53:42.471 DEBUG (MainThread) [sunnybeamtool.sunnybeamtool] raw_read: 0160

Hi @Hafenmeister,
have you tried to run the underlying python (GitHub - dannerph/SunnyBeamToolPython: Python port of SunnyBeamTool) or C (GitHub - SBFspot/SunnyBeamTool: Get solar data out of your SunnyBeam) library from your computer, in order to check in a first place, if your device is compatible?
If yes, which libusb version do you have in your setup? I remember that I was not able to get it working on my Synology NAS because of an outdated version of libusb. From within the docker container of Home Assistant core, it is working.
If above steps are find, I would start investigating, why your proxmox setting is not forwarding data to libusb.

Hi Thanks a lot fpr providing such a solution. Unfortunately I cannot get this working. I have the HA running in a docker on a synology NAS with a Conbee II Zigbee stick. I followed the instructions in the readme file copy the files to custom_components, restart HA, plugged in the Sunnybeam restart HA and edit the config yaml file. After editing the yaml file the check was not good - Integration Sunnybeam not found. I also added the 99-SMA rule to lib/udev/rules.d. After replugging the sunny beam no success and also the conbee was not working anymore. The Sunnybeam is shown at the NAS Info/USB devices with full name so seam to be working. After removing the rule and reboot of the NAS the HA and conbee worked fine. Do anybody have an idea how get this working? Thanks in advance.

Hi @mbbs1024 @kefjevl
I have a installation from 2009 with SMA inverter Sunny boy 3000TL

I never used the Bluetooth as I was not aware that I could use without a Sunny beam. In the beginning I was taking note manual about the production…after some time not any more.
Recently I came across a program from SMA, Sunny explorer, and tried to make connection with Bluetooth via laptop. And it worked…!!! It was able to download all the data from the past.
This triggered the idea to get this data in HA via Bluetooth…

Did you have some info on that?

Hello All,
I found this thread a few days ago. I also have a Sunny Beam and want to connect my SMA inverter SB3300 (year 2008 version) to HA. I have not tried implementing the Sunny Beam yet because the place where my RPi4 with HA is placed is a very bad place for the Sunny Beam regarding reception of the inverter signal. Maybe there are smarter people than me that can convert the Sunny Beam to a network device (ESP32, Tasmota regarding MQTT facilities?) which has wifi access to the home network? If this is possible, the Sunny Beam can be placed at every place where wifi and the SM3300 inverter signal are in sight of the Sunny Beam and as a bonus it could be powered via the 5V PSU of the coupled device (fed in the USB port, batteries removed) while a sunny place is not mandatory anymore. I’m not a software guy but can hold a soldering station… . I hope someone can help me and others with a solution like this?

Hello, sorry for my very late reply as well :smiley:

I have a Sunnybeam radio version, not the bluetooth one. I don’t have the data packets anymore unfortunately.
It has been working for the last 18 months, even if it is not 100% stable.
For example, if there is small electricity instability (like if I turn on an electric heater on the same outlet as my machine running HA), it will stop being able to fetch new data from usb unless I reboot the computer.
Quite weird.

I just built a small rest service that provides me the data, so I can externalise data extraction from my HA machine.

@Hafenmeister it looks like the same issue as I had. Maybe try to change the hardcoded bytes from 7EFF03404100000000900002 to 7EFF03404100000000900003

@mbbs1024 @dannerph

guys is this still working and does this work on HAOS

Hi @GylRon1
as far as I know, ESP32 does not have a USB host controller, so it will not work to connect the Sunny Beam via USB to a ESP32.

@Tinker_s still working for me quite stable (some small transmission issues because of a quite far distance to the inverters)

Yep, on rare occasions (about once a year) it stops working, and then I reboot HA to get it working again.
There is probably a more elegant way to only restart the integration, but I did not take the time to search for it, as a reboot of HA is realy quick.

Hi all,
My problem is solved. Recently a battery is placed and my old SunnyBoy is measured with a inductive sensor that can be read by the battery converter which in turn can be read in HA.

Hi @dannerph

I have 2 solarpanel systems, but only one is available in HA thanks to your integration.
They have the same orientation, so I want to multiply the output with a factor 2.5065
so that the output represents the power generated by the 2 systems.

In the past, you showed me to adapt a few lines in sensor.pi like this

        data = self._sunnybeam.get_data()
        _LOGGER.debug(f"received: {data}")
        if data != 0:
            if "power" in self._attr_name:
                self._attr_native_value = round(int(data[0]) / 1000.0, 3)
            elif "today" in self._attr_name:
                self._attr_native_value = round(float(2.5065*data[1]), 2)
            else:
                self._attr_native_value = int(2.5065*data[2])

I searched these lines in the new version, but apparently you read the data in a different way now.

Can I do the multiplication like this key=KEY_POWER*2.5065 or do I need to do that elsewhere ?
I am not familiar with Python.

SENSORS = [
    SensorEntityDescription(
        key=KEY_POWER,
        translation_key=KEY_POWER,
        device_class=SensorDeviceClass.POWER,
        native_unit_of_measurement=UnitOfPower.KILO_WATT,
        state_class=SensorStateClass.MEASUREMENT,
    ),
    SensorEntityDescription(
        key=KEY_ENERGY_TODAY,
        translation_key=KEY_ENERGY_TODAY,
        native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
        device_class=SensorDeviceClass.ENERGY,
        state_class=SensorStateClass.TOTAL_INCREASING,
    ),
    SensorEntityDescription(
        key=KEY_ENERGY_TOTAL,
        translation_key=KEY_ENERGY_TOTAL,
        native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
        device_class=SensorDeviceClass.ENERGY,
        state_class=SensorStateClass.TOTAL_INCREASING,
    ),

Hi @mbbs1024,
I would recommend not to change the integration but create a template sensor within Home Assistant that takes the value to multiply it.

You can create template sensors directly in the UI under Settings > Devices & Services > Helpers.

Would be something like this for the template (similar for energy sensors)

{{ states("sensor.sunnybeam_power") | float(0.0) * 2.5065  }}

You can also add the same sensor class so that it is recognised by the energy dashboard.

Thanks, I created the 3 templates, tomorrow, when the sun is up again, I’ll see if they are recognised in the energy dashboard.

yes thank you , i forgot to reply but i also got this working like a charm now . mucht better than the thing i wrote in python