Hi Woempiej, I’m new to this forum and don’t have much experience with Home Assistant, but I hope you can still help me. I’ve loaded your automation into my HA setup and am currently testing it. As I understand it, this automation is supposed to limit the export to 250W of feed-in power. That isn't happening in my case. I believe I’ve used the correct IDs. Do you have any idea what I might be doing wrong, or what information I could share with you so you can assess the situation? I hope you can help me out so that I stop feeding power back into the grid by January 1, 2027. Regards, Arjan.
Hi Arjan,
Can you share your automation .yaml?
Navigate to your automation, click on the 3 vertical dots in the upper right corner and click on "Bewerken in YAML".
Copy the code of your automation on this forum with the formatting code option!
You have to be sure
Which hardware are you using? (type of P1 dongle, Goodwe intverter model)
alias: GoodWe Export Limiter test
description: 🔴 Variables alleen zichtbaar in YAML
triggers:
- entity_id:
- sensor.p1_meter_active_power
trigger: state
conditions:
- condition: numeric_state
entity_id: sensor.pv_power_2
above: 10
actions:
- condition: template
value_template: "{{ active }}"
- target:
entity_id: "{{ limit_entity }}"
data:
value: "{{ clamped_limit }}"
action: number.set_value
variables:
p1_entity: sensor.p1_meter_active_power
pv_entity: sensor.pv_power_2
limit_entity: number.grid_export_limit_2
target_export: 100
min_w: 0
max_w: 3000
max_step: 250
deadband: 80
p1: "{{ states(p1_entity) | float(0) }}"
pv: "{{ states(pv_entity) | float(0) }}"
export_now: "{{ -p1 if p1 < 0 else 0 }}"
error: "{{ target_export - export_now }}"
active: "{{ error | abs > deadband }}"
kp: 0.5
step_raw: "{{ error * kp }}"
step_limited: |
{% if step_raw > max_step %}
{{ max_step }}
{% elif step_raw < -max_step %}
{{ -max_step }}
{% else %}
{{ step_raw }}
{% endif %}
limit_now: "{{ states(limit_entity) | float(0) }}"
proposed_limit: "{{ limit_now + step_limited }}"
clamped_limit: |
{% if proposed_limit < min_w %}
{{ min_w }}
{% elif proposed_limit > max_w %}
{{ max_w }}
{% else %}
{{ proposed_limit | round(0) }}
{% endif %}
mode: restart
[grid]






[/grid]
Hi, I hope this is what you mean.
Hi,
Here is my new automation. Any tips, tricks and/or improvements are welcome.
This automation continuously adjusts the GoodWe inverter’s grid export limit to keep the power exported to the grid close to a target value (default: -250 W because my P1 meter registers export as a minus value and import as plus value).
Every 10 seconds, it:
Only write (export limit value) to Goodwe inverter if PV power is higher then 50 Watt
Reads the current power flow from the P1 meter.
Compares it to the desired export target.
Increases or decreases the inverter’s export limit accordingly.
Makes larger adjustments when importing power from the grid and smaller adjustments when exporting too much.
Limits each adjustment step and keeps the export limit between 300 W and 5000 W.
Only updates the inverter if the required change is significant, reducing unnecessary commands.
alias: GoodWe PV Export Controller
description: 🔴 Variables only visible in YAML
triggers:
- trigger: time_pattern
seconds: /10
conditions:
- condition: numeric_state
entity_id: sensor.pv_power
above: 50
- condition: template
value_template: |
{{ (p1 - target_export) | abs > 50 }}
- condition: template
value_template: |
{{ (new_limit - current_limit) | abs > 25 }}
actions:
- action: number.set_value
target:
entity_id: number.grid_export_limit
data:
value: |
{% if new_limit < 300 %}
300
{% elif new_limit > 5000 %}
5000
{% else %}
{{ new_limit }}
{% endif %}
variables:
target_export: -250
p1: "{{ states('sensor.p1_meter_3c39e72f4cec_active_power') | float(0) }}"
current_limit: "{{ states('number.grid_export_limit') | float(300) }}"
delta: |
{% set error = p1 - target_export %}
{# Increase output faster during import #} {% if error > 0 %}
{% set d = error * 0.5 %}
{% else %}
{# Reduce output gradually during export #}
{% set d = error * 0.2 %}
{% endif %}
{# Limit the maximum adjustment step #} {% if d > 500 %}
500
{% elif d < -150 %}
-150
{% else %}
{{ d }}
{% endif %}
new_limit: |
{{ (current_limit + (delta | float)) | round(0) }}
mode: restart
Hi Woempiej, I’ve given the two variables the correct names, and I think it’s working now. The export limit is nicely variable. Thanks for your help and the quick response. Just a quick question: is that new automation an extension of this one, or is it a completely new one? Gr.Arjan
Hi,
Good to read you fixed it ![]()
The two automations have the same overall goal → controlling the GoodWe inverter’s grid export limit to maintain a target export of for example 250 W
It’s a new automation that is upscaling the Goodwe export limit entity quiker when I’m importing power, and downscaling slower (to targer_export) when exporting power.
I am still testing and tweaking…
GoodWe PV Export Controller
alias: GoodWe PV Export Controller
description: 🔴 Variables only visible in YAML
triggers:
- trigger: time_pattern
seconds: /10
conditions:
- condition: numeric_state
entity_id: sensor.pv_power
above: 300
- condition: template
value_template: |
{{ (p1 - target_export) | abs > 50 }}
- condition: template
value_template: |
{{ (new_limit - current_limit) | abs > 25 }}
actions:
- action: number.set_value
target:
entity_id: number.grid_export_limit
data:
value: |
{% if new_limit < 300 %}
300
{% elif new_limit > 5000 %}
5000
{% else %}
{{ new_limit }}
{% endif %}
variables:
target_export: -350
p1: "{{ states('sensor.p1_meter_3c39e72f4cec_active_power') | float(0) }}"
current_limit: "{{ states('number.grid_export_limit') | float(300) }}"
delta: |
{% set error = p1 - target_export %}
{# Increase output faster during import #} {% if error > 0 %}
{% set d = error * 0.5 %}
{% else %}
{# Reduce output gradually during export #}
{% set d = error * 0.2 %}
{% endif %}
{# Limit the maximum adjustment step #} {% if d > 500 %}
500
{% elif d < -150 %}
-150
{% else %}
{{ d }}
{% endif %}
new_limit: |
{{ (current_limit + (delta | float)) | round(0) }}
mode: restart









