SMA Tripower // Modbus // Total consumption or Grid feed-in

Hi,
I run a SMA Tripower STP10.0-3SE-40 865 inverter and have it connected via modbus.
I would like to set up a logic which toggles a switch whenever I produce e.g. 3000W more than I use.
I have already managed to get the currently produced power (Register 30775) but I do not know where to find the total consumption or the grid feed.
Would be great if you could help me out!

See my yaml details below

Thanks,

Leiste

modbus:
  - name: SMA
    type: tcp
    host: 192.168.2.33
    port: 502
    sensors:
      - name: PV_Leistung
        unit_of_measurement: W
        slave: 3
        address: 30775
        data_type: int32
      - name: PV_Tagesertrag
        unit_of_measurement: kWh
        slave: 3
        address: 30517
        scale: 0.001
        precision: 3
        data_type: uint64
      - name: PV_Gesamtertrag
        unit_of_measurement: MWh
        slave: 3
        address: 30513
        scale: 0.000001
        precision: 3
        data_type: uint64
      - name: Grid Voltage
        unit_of_measurement: V
        slave: 3
        address: 30783
        scale: 0.01
        precision: 2
        data_type: uint32
      - name: Grid frequency
        unit_of_measurement: Hz
        slave: 3
        address: 30803
        scale: 0.01
        precision: 2
        data_type: uint32
      - name: SMA_temp
        unit_of_measurement: °C
        slave: 3
        address: 30953
        scale: 0.1
        precision: 1
        data_type: int32
      - name: SMA_status
        slave: 3
        address: 30201
        data_type: uint32
      - name: SMA_grid
        slave: 3
        address: 30217
        data_type: uint32
      - name: Insulation
        slave: 3
        address: 30225
        scale: 0.001
        unit_of_measurement: kOhms
        data_type: uint32
      - name: SMA_Residual_current
        slave: 3
        address: 31247
        scale: 1
        unit_of_measurement: mA
        data_type: int32
      - name: Apparent Power
        unit_of_measurement: VA
        slave: 3
        address: 30813
        scale: 1
        precision: 0
        data_type: int32
      - name: Reactive Power
        unit_of_measurement: W
        slave: 3
        address: 30805
        scale: 1
        precision: 0
        data_type: int32

Instead of Modbus, it is probably easier if you use my integration.

The inverter does not know what you are feeding in. To do this, you need to query your Energymeter or Sunny Home Manager 2, if available.