Automate Fronius Soft Limit

Hi,

I found this thread really useful, to understand the mechanics - thanks a lot!

I needed a solution for the new german law ‘Solarspitzengesetz’, that requires a limited feed into the grid by max. 60% of the installed kWp. It calculates the current site consumption and adds this to the inverter max power limit.
The second automation is to turn back to 100% once the inverter goes below 10W. Just if anybody would be interested as well.
Happy to hear any feedback for improvements as well.

My configuration.yaml:

template:
  - sensor:
      - name: "fronius_symo_pwr_limit"
        # Solarspitzengesetz: maximum grid feed is 60% of kWp installed
        # i.e. 5220 * 60% = 3120 W
        # inverter max power is 5000 W
        # value to control inverter power is in percent scaled by 100, i.e. 10000 = 100%
        state: >
          {% set max_power = 5000 %}
          {% set scaling = 10000 %}
          {% set installed_Wp = 5220 %}
          {% set max_grid_feed = (installed_Wp * 0.60) %}
          {{ (( [ ((states("sensor.shellypro3_total_active_power") | float(0) )
                 + (states("sensor.fronius_symo_5_0_leistung_ac")  | float(0) )
                 + max_grid_feed), max_power] | min)
              / max_power * scaling) | int
          }}

and my autiomation.yaml:

- id: '1743520805814'
  alias: Froinuis Symo limit output power
  description: ''
  triggers:
  - trigger: state
    entity_id:
    - sensor.shellypro3_total_active_power
  conditions:
  - condition: numeric_state
    entity_id: sensor.fronius_symo_5_0_leistung_ac
    above: 3100
  - condition: numeric_state
    entity_id: sensor.fronius_symo_pwr_limit
    below: 10000
  actions:
  - action: modbus.write_register
    data:
      hub: mb_symo
      address: 40242
      value:
      - '{{ states("sensor.fronius_symo_pwr_limit") }}'
      - 0
      - 0
      - 0
      - 1
  mode: single
- id: '1743613179878'
  alias: Fronius Reset max Power
  description: ''
  triggers:
  - trigger: numeric_state
    entity_id:
    - sensor.fronius_symo_5_0_leistung_ac
    below: 3000
  conditions: []
  actions:
  - action: modbus.write_register
    data:
      hub: mb_symo
      address: 40242
      value:
      - 10000
      - 0
      - 0
      - 0
      - 1
  mode: single

EDIT: improved the conditions in the first automation and increased the trigger value in the second compared to my original post.