kellerza / pysma

Async library for SMA Solar's WebConnect interface
MIT License
59 stars 51 forks source link

Dynamic sensors #109

Closed rklomp closed 1 year ago

rklomp commented 1 year ago

This will get rid of device classes and use the getAllOnlValues.json and getAllParamValues.json to figure out which sensors are present on the device.

FindusK commented 1 year ago

I did a small test on my inverter, all sensors seem to be available. I have problems to decode some of the values, most importanly the array based sensors pv_current_b and pv_voltage_b of the inverter.

Here the full output of the script:

battery_capacity_total              0 %
     battery_charge_total            0.0 kWh
        battery_current_a            0.0 A
  battery_discharge_total            0.0 kWh
battery_power_charge_total              0 W
battery_power_discharge_total              0 W
        battery_soc_total              0 %
battery_status_operating_mode            Off
           battery_temp_a            0.0 °C
        battery_voltage_a            0.0 V
               current_l1            6.0 A
               current_l2            6.0 A
               current_l3            6.0 A
            current_total           18.0 A
              daily_yield           9065 Wh
                frequency          49.99 Hz
      grid_apparent_power           4290 VA
   grid_apparent_power_l1           1431 VA
   grid_apparent_power_l2           1431 VA
   grid_apparent_power_l3           1431 VA
               grid_power           4290 W
        grid_power_factor            0.0
      grid_reactive_power              0 var
   grid_reactive_power_l1             -2 var
   grid_reactive_power_l2             -2 var
   grid_reactive_power_l3             -2 var
        grid_relay_status         Closed
       inverter_condition             Ok
     inverter_power_limit          10000 W
     inverter_system_init            Yes
 operating_status_general      Activated
                 power_l1           1433 W
                 power_l2           1428 W
                 power_l3           1434 W
             pv_current_a          4.371 A
             pv_current_b
             pv_gen_meter        2654.88 kWh
               pv_power_a           1583 W
               pv_power_b              0 W
             pv_voltage_a          362.1 V
             pv_voltage_b
                   status             Ok
              total_yield        2655.21 kWh
               voltage_l1          236.7 V
               voltage_l2          235.3 V
               voltage_l3          236.6 V
  metering_power_supplied           3680 W
  metering_power_absorbed              0 W
       metering_frequency          49.98 Hz
     metering_total_yield       1523.549 kWh
  metering_total_absorbed        238.848 kWh
      metering_current_l1          5.457 A
      metering_current_l2          4.562 A
      metering_current_l3          5.967 A
      metering_voltage_l1         234.98 V
      metering_voltage_l2         234.57 V
      metering_voltage_l3         235.23 V
metering_active_power_feed_l1           1269 W
metering_active_power_feed_l2           1014 W
metering_active_power_feed_l3           1397 W
metering_active_power_draw_l1              0 W
metering_active_power_draw_l2              0 W
metering_active_power_draw_l3              0 W
metering_current_consumption
metering_total_consumption
rklomp commented 1 year ago

I did a small test on my inverter, all sensors seem to be available. I have problems to decode some of the values, most importanly the array based sensors pv_current_b and pv_voltage_b of the inverter.

Looking good! About the array based sensors. Do you have two strings of solar panels? Otherwise they wont give any values.

FindusK commented 1 year ago

I have both strings connected on my inverter, the value of pv_power_b should be around 2100W. This is the corresponding section in the json from another day:

            "6380_40251E00": {
                "1": [
                    {
                        "val": 3718
                    },
                    {
                        "val": 5975
                    }
                ]
            },
            "6380_40451F00": {
                "1": [
                    {
                        "val": 34110
                    },
                    {
                        "val": 61650
                    }
                ]
            },
            "6380_40452100": {
                "1": [
                    {
                        "val": 10900
                    },
                    {
                        "val": 9691
                    }
                ]
            },
codecov[bot] commented 1 year ago

Codecov Report

Merging #109 (e472cc2) into master (50b26a9) will not change coverage. The diff coverage is 100.00%.

@@            Coverage Diff             @@
##            master      #109    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files            6         5     -1     
  Lines          428       241   -187     
==========================================
- Hits           428       241   -187     
Impacted Files Coverage Δ
pysma/definitions.py 100.00% <ø> (ø)
pysma/const.py 100.00% <100.00%> (ø)
pysma/sensor.py 100.00% <100.00%> (ø)
pysma/__init__.py

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

rklomp commented 1 year ago

I have both strings connected on my inverter, the value of pv_power_b should be around 2100W. This is the corresponding section in the json from another day:

I found the issue and committed a fix. Also updated the tests to cover this.

I am creating a file with test data for testing the code. Would you be able to share the response of your inverter for POST requests to /dyn/getAllOnlValues.json and /dyn/getAllParamValues.json so I can include them?

rklomp commented 1 year ago

@kellerza,

Do you know of any users with a devices that requires the alternative jmespath queries?

JMESPATH_VAL = "val"
JMESPATH_VAL_TAG = JMESPATH_VAL + "[0].tag"
JMESPATH_VAL_STR = "[?str==sum([`1`,`{}`])].val | [0]"

Trying to build a file with test data and having this data would be really useful

rklomp commented 1 year ago

@FindusK , Could you share the response of your inverter for POST requests to /dyn/getAllOnlValues.json and /dyn/getAllParamValues.json so I can include them? I expect this gets the tests coverage to 100%

phdelodder commented 1 year ago

@rklomp here is mine: pysma-debug.log

FindusK commented 1 year ago

@rklomp sure. getAllOnlValues.json.txt getAllParamValues.json.txt

rklomp commented 1 year ago

Thanks @phdelodder and @FindusK! I have added both your data to the testfile and got a 100% coverage now