Custom Integration: Sonnenbatterie

Hi all,

this is my first integration for Homeassistant
and the first time, i code python at all.

This integration not only shows the same values as the well-known /api/v1/status rest templates,
it also shows voltage, amps, watts for all the phases as well as the current net-frequency and more.

i published the required lib to pypi, so it should just run after installing

to install, you use the integrations page wich asks you for the IP of your Sonnenbatterie and the password for the user (username can be User or Installer), you should have got them from your technician

The Passwort seems to be not personalized currently.
You can always try User/sonnenUser3552 :slight_smile:

image
image


4 Likes

THX for the integration, which “User” and “PW” I will use - the “system user” from the sonnenbatterie (model 9.2 eco from 2014 I use) OR the User/Password from the App and RemoteDashboard? THX!

I have the ECO 8 and for me, it is the Username/Password from the Documents of the batterie.

I have this Dropdown on my batterie interface:
image

I have to use “User” and the Password is “SonnenUserXXXXXX”

Edit:
The interface is shown if i access the batterie directly via http://[IP]/dash
Better image:

Edit2:
The password comes from this piece of paper:

You have the “new” version … see my “dashboard”

- it “comes” with my IP-adress of the Sonnenbatterie.

Uhh… i did not know, that there are so different versions of the webinterface.
Then… i cant help you with that, as i dont own this type.
maybe you can check it there is an alternative webinterface on a different port of the batterie
but you would still need the credentials from the installer, i think.

Sorry for that.

I have a ECO8. Thank you for the integration!

Tell me how good or not good this works for you, please :slight_smile:
I can only test it with my eco 8.3 currently.

I have the eco 8.0 DE 9010 ND. After i find the correct password for the user account to get local to the battery and type them in your integration every sonnen sensors are available. Very easy and no problems!

1 Like

This seems to be nearly the same as mine. i have
eco 8.03 9010 ND
image

Cool! :+1::+1:Gonna try it out very soon! But what’s the difference and benefits from using a REST sensor? What more do I get?
With the REST sensor I do not even have to use user/pass but only logon via internal ip address.

If you look at my Screenshot in First Post,
You see all sensors generated by this addons.

For example
Net frequency,
Wattage, Voltage, Amps for all 3 Phases,
…

i change to the integration because the interval is shorter. And i like the Total Capacity Real sensor to see the capacity in the future with Grafana.

Tried it out on my Hybrid
|Capacity|7.5 kWh (3 modules)|
|Hardware Version|8|
|Inverter Max. Power|3300 W|
|Model|hyb 8.13 9010 ND|

Didn’t work though - it kept being in a state NOTRUN even though I restarted Home Assistant multiple times. It was able to fetch the Serial Number though, so somethings went right. (Installed manually not through HACS)
I’m fine for now with the REST interface - works like a charm. But I’d like to help you if you like. (It might as well be something I’ve done wrong)

Thanks anyway! Appreciate what you do for the community :+1::fist_right::fist_left::facepunch::clap::muscle::muscle:

Hi ZkiiFreak,

thank you for your testing :slight_smile:

Could you check the homeassistant log file and send me all the parts about the sonnenbatterie component. There should be some errors if its not working.

Did you setup via the add integration in ha configuration page?

Set it up via the add integration page, yes :wink:
The log (removed “personal” stuff):

2020-04-08 14:28:44 INFO (MainThread) [homeassistant.setup] Setting up sonnenbatterie,
2020-04-08 14:28:44 INFO (MainThread) [homeassistant.setup] Setup of domain sonnenbatterie took 0.0 seconds.,
2020-04-08 14:28:44 INFO (MainThread) [custom_components.sonnenbatterie] setup_entry: {"username": "User", "password": "*************", "ip_address": "172.16.2.**"},
2020-04-08 14:28:44 INFO (MainThread) [homeassistant.components.sensor] Setting up sensor.sonnenbatterie,
2020-04-08 14:28:44 INFO (MainThread) [custom_components.sonnenbatterie] SETUP_ENTRY,
2020-04-08 14:28:44 INFO (MainThread) [custom_components.sonnenbatterie] sonnenbatterie - INTERVAL: None,
2020-04-08 14:28:44 INFO (MainThread) [custom_components.sonnenbatterie] Create Sensor sensor.sonnenbatterie_*****,
2020-04-08 14:28:45 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new sensor.sonnenbatterie entity: sensor.sonnenbatterie_*****
2020-04-08 14:28:45 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up sonnenbatterie platform for sensor,
    val=inverter['status']['fac'],
KeyError: 'fac',
    monitor = SonnenBatterieMonitor(sonnenInst, sensor, async_add_entities,updateIntervalSeconds),
  File "/config/custom_components/sonnenbatterie/sensor.py", line 41, in async_setup_entry,
    return fut.result(),
  File "/usr/local/lib/python3.7/asyncio/tasks.py", line 442, in wait_for,
    await asyncio.wait_for(asyncio.shield(task), SLOW_SETUP_MAX_WAIT),
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 179, in _async_setup_platform,
Traceback (most recent call last):,
    self.setupEntities(),
  File "/config/custom_components/sonnenbatterie/sensor.py", line 120, in __init__,
  File "/config/custom_components/sonnenbatterie/sensor.py", line 134, in setupEntities,
    self.AddOrUpdateEntities(),
  File "/config/custom_components/sonnenbatterie/sensor.py", line 209, in AddOrUpdateEntities,

UPDATE:
Just update to latest git revision. It now writes the json output to error log once and then disabled this sensor. If you send me the json, i can check, what is wrong :slight_smile:

Old:
Very nice!
Could you change the line 209 to 213 accordingly:
image


        """this and that from the states"""
        try:
            val=inverter['status']['fac']
            sensorname=allSensorsPrefix+"state_netfrequency"
            unitname="Hz"
            friendlyname="Net Frequency"
            self._AddOrUpdateEntity(sensorname,friendlyname,val,unitname)
        except:
            e = traceback.format_exc()
            LOGGER.error(e)
            LOGGER.error(inverter)

        """whatever comes next"""

or just replace the sensor.py with this one: nextcloud.weltmeyer.net

then check the log again, it should post something like:

2020-04-08 15:10:15 ERROR (Thread-12) [custom_components.sonnenbatterie] {‘status’: {‘IOStates’: {‘’: False, ‘AC_Relais1Closed’: False, ‘AC_Relais2Closed’: False, ‘DC1_RelaisClosed’: False, ‘DC2_RelaisClosed’: False, ‘OpenCollectorOutput1’: False, ‘OpenCollectorOutput2’: False, ‘OpenCollectorOutput3’: False}, ‘fac’: ‘50.02’, ‘iac1’: ‘0.34’, ‘iac2’: ‘0.34’, ‘iac3’: ‘0.33’, ‘ibat’: ‘-0.01’, ‘ipv’: ‘0.00’, ‘ipv2’: ‘0.00’, ‘mode’: ‘connected’, ‘pac1’: ‘-0.46’, ‘pac2’: ‘-0.19’, ‘pac3’: ‘0.17’, ‘pac_microgrid’: ‘0.00’, ‘pac_total’: ‘-5.29’, ‘pbat’: ‘-0.33’, ‘phi’: ‘0.00’, ‘ppv’: ‘0.00’, ‘ppv2’: ‘0.00’, ‘sac1’: ‘80.16’, ‘sac2’: ‘80.23’, ‘sac3’: ‘78.72’, ‘sac_total’: ‘239.11’, ‘status’: {‘’: False, ‘Active Failure’: False, ‘Active P(f) Active’: False, ‘Active Pu Active’: False, ‘BDC Communication Timeout’: False, ‘Checking FI’: False, ‘Checking Grid DC Offset Current’: False, ‘Checking Grid Timing’: False, ‘Checking Isolation Resistance’: False, ‘Checking PU Hardware’: False, ‘Checking Relais’: False, ‘Checking Shutdown’: False, ‘DcInput Config Incomplete’: False, ‘Derating External’: False, ‘Derating Freq too high for connect’: False, ‘Derating Freq too low for connect’: False, ‘Derating Frequency’: False, ‘Derating Hardware Limit’: False, ‘Derating Startup’: False, ‘Derating Thermal’: False, ‘Derating User Limit’: False, ‘FanError Active’: False, ‘Island Mode Active’: False, ‘Island Mode Overload’: False, ‘Island Mode ShortCircuit’: False, ‘Over Temperature’: False, ‘PU Communication Timeout’: False, ‘Reactive Output Control Active’: False, ‘Ready’: True, ‘Self Test Active’: False, ‘Startup OK’: True}, ‘status2’: {‘’: False, ‘FFR_Active_status’: False}, ‘tempbdc’: ‘32.79’, ‘temphmi’: ‘34.00’, ‘temppu’: ‘38.09’, ‘uac1’: ‘240.96’, ‘uac2’: ‘235.21’, ‘uac3’: ‘234.46’, ‘ubat’: ‘50.77’, ‘udc’: ‘645.80’, ‘upv’: ‘0.00’, ‘upv2’: ‘0.00’}, ‘settings’: {‘CommunicationWatchdog’: 60, ‘CountryCode’: 4900, ‘Firmware Version’: {‘BDC Version’: ‘3.26.0’, ‘ENS1 Version’: ‘3.2.0’, ‘ENS2 Version’: ‘3.2.0’, ‘HMI Version’: ‘2.28.0’, ‘PU Version’: ‘11.2.0’, ‘RIO Version’: ‘0.0.0’}, ‘PVsU_Enable’: 0, ‘P_max’: 5500, ‘PassivePvsFConfiguration_t’: {‘Frequency’: 0, ‘Gradient’: 0}, ‘PowerDeratingPermill’: 1000, ‘PvsFConfiguration_t’: {‘ActivationDelay_ms’: 0, ‘ExitDelay_s’: 0, ‘ExitRamp_s’: 0, ‘FrequencyLowerEnd_mHz’: 0, ‘FrequencyLowerEntry_mHz’: 0, ‘FrequencyLowerExit_mHz’: 0, ‘FrequencyUpperEnd_mHz’: 0, ‘FrequencyUpperEntry_mHz’: 0, ‘FrequencyUpperExit_mHz’: 0}, ‘PvsF_Enable’: 0, ‘PvsUConfiguration_t’: {‘ControlResponseTime_s’: 0, ‘Type’: 0, ‘Voltage_LowerEnd_ppt’: 0, ‘Voltage_LowerEntry_ppt’: 0, ‘Voltage_UpperEnd_ppt’: 0, ‘Voltage_UpperEntry_ppt’: 0}, ‘ReactivePowerConfiguration_t’: {‘CalculationBasis’: 0, ‘P_Point1’: 0, ‘P_Point2’: 1000, ‘P_Point3’: 1000, ‘P_Point4’: 1000, ‘P_Point5’: 1000, ‘P_Point6’: 1000, ‘P_Point7’: 1000, ‘P_Point8’: 1000, ‘PowerFactor’: 1000, ‘Reactive_Output_CurvePointsUsed’: 2, ‘dynamic’: 0, ‘phi_Point1’: 1000, ‘phi_Point2’: 1000, ‘phi_Point3’: 1000, ‘phi_Point4’: 1000, ‘phi_Point5’: 1000, ‘phi_Point6’: 1000, ‘phi_Point7’: 1000, ‘phi_Point8’: 1000}, ‘ShutdownPin’: 0, ‘StecaFFRConfiguration_t’: {‘FFR_Enable’: 0, ‘FFR_Test_Enable’: 0, ‘Frequency_FFR_lower_mHz’: 0, ‘Frequency_FFR_test_mHz’: 0, ‘Frequency_FFR_upper_mHz’: 0}, ‘UNIXTimestamp’: 639616530}}
2020-04-08 15:10:17 ERROR (Thread-12) [custom_components.sonnenbatterie] Traceback (most recent call last):
File “/config/custom_components/sonnenbatterie/sensor.py”, line 210, in AddOrUpdateEntities
val=inverter[‘status’][‘factest’]
KeyError: ‘fac’

Hi
The latest Git version downloaded and works! Thanks! :slight_smile: :+1: PM sent as well containing logs

1 Like

Hi! I’m rather new to HA, but would love to get this to work for me.
I´m not rather sure how to add the repositorie or if I can add it in the config file?

You can add the repository via the HACS settings