Skip to content

Instantly share code, notes, and snippets.

@NikGro
Created January 11, 2024 21:34
Show Gist options
  • Select an option

  • Save NikGro/c9b783d13b4b8157901e6fbd3ea18389 to your computer and use it in GitHub Desktop.

Select an option

Save NikGro/c9b783d13b4b8157901e6fbd3ea18389 to your computer and use it in GitHub Desktop.
Open DTU Zero Export Home Assistant Blueprint
blueprint:
name: Open DTU - Zero Export
description: "\n ## Open-DTU Zero Export\n\n\n ### !WARNING!\n\n I barely have any idea of what im actually doing here. Please monitor your system's behavior closely when using this automation! Solar-Systems or any other energy/power-related systems can be dangerous and even life-threatening. I hold no responsibility for any incidents that may be caused by this autmation. Please inspect the code carefully before use. I have tested this code only in a simulated environment with simulated input-delay and cannot guarantee for it to work as expected in a live environment.\n\n\n ### Description \n\n This automation enables you to achieve zero export with your Open DTU inverter. \n\n It uses a simplified version of hysterisis. This means, that it will try to keep your inverter's export in between two values which can be customized below. The automation tries to achieve this by attempting to set the inverter's output-limit in the middle of these values and reacting once they are reached. \n\n The automation can be tweaked to be less aggressive by setting the min- and max values further apart or to be more aggressive by setting them closer together. \n\n The automation can aslo be set to always keep the limiter below a certain wattage by adjusting the 'Open-DTU Max Output' accordingly."
domain: automation
input:
sensor_grid_export:
name: Grid-Export Sensor Entity
description: Select a sensor displaying your total current grid-export wattage. (for example a Shelly 3EM). The selected entity MUST display a positive value for the automation to work properly.
selector:
entity:
sensor_dtu_output:
name: Open-DTU Output Entity
description: Select the output-entity provided by Open-DTU displaying the current output wattage.
selector:
entity:
number_dtu_limit:
name: Open-DTU Limit Entity (Non Persistent, Absolute)
description: Select the limit-entity provided by Open-DTU. This entity is expected to be a "Input-Number" type. It's max value should reflect the inverter's max output.
selector:
entity:
input_dtu_max:
name: Open-DTU Max Output (Enter manually)
description: Enter your inverter's max output wattage (For example, 1600 for Hoymiles HMS-1600 inverters). This should be identical with the DTU-Limiter's max value.
selector:
number:
min: 0
max: 999999
step: 1
unit_of_measurement: W
mode: box
input_user_min:
name: Zero-Range-Minimum
description: Enter the lower cap of the power-export-range which the automation will attempt to keep. In this case "lower" means the smallest export-value (for example 50w export). The minimum is 0.
selector:
number:
min: 0
max: 999999
step: 1
unit_of_measurement: W
mode: box
input_user_max:
name: Zero-Range-Maximum
description: Enter the upper cap of the power-export-range which the automation will attempt to keep. It is suggested to keep a 100 W range between the min & max values. However, the blueprint does not enforce this.
selector:
number:
min: 0
max: 999999
step: 1
unit_of_measurement: W
mode: box
variables:
sensor_grid_export: !input sensor_grid_export
sensor_dtu_output: !input sensor_dtu_output
number_dtu_limit: !input number_dtu_limit
input_dtu_max: !input input_dtu_max
input_user_min: !input input_user_min
input_user_max: !input input_user_max
trigger:
- platform: state
entity_id: !input sensor_grid_export
condition:
- condition: or
conditions:
- condition: template
value_template: "{{(states(sensor_grid_export)|float()|abs()) > ((input_user_max)|float()|abs())}}"
- condition: template
value_template: "{{(states(number_dtu_limit)|float()|abs()) < ((input_dtu_max)|float()|abs())}}"
action:
- if:
- condition: template
value_template: "{{(states(sensor_grid_export)|float()|abs()) > ((input_user_max)|float()|abs())}}"
then:
- service: input_number.set_value
data_template:
entity_id: !input number_dtu_limit
value: >-
{{ ((states(sensor_dtu_output)|float()) -
((states(sensor_grid_export)|float()|abs()) -
((((input_user_max)|float()|abs()) + ((input_user_min)|float()|abs())) /2|abs())))|int()}}
- if:
- condition: and
conditions:
- condition: template
value_template: "{{(states(number_dtu_limit)|float()|abs()) < ((input_dtu_max)|float()|abs())}}"
- condition: template
value_template: "{{(states(sensor_grid_export)|float()|abs()) == ((input_user_min)|float()|abs())}}"
then:
- service: input_number.set_value
data_template:
entity_id: !input number_dtu_limit
value: "{{((input_dtu_max)|float()|abs())}}"
mode: restart
max_exceeded: silent
@Gubelat
Copy link

Gubelat commented Aug 18, 2025

Thank you very much for your work. Bluprint works fine for me.
Even with multiple inverters.
Here the way i did this.

Create a input number helper ie: input_number.dachpv_limiter

Create a new Automation:

alias: Nulleinspeisung_Master
description: ""
triggers:
  - trigger: state
    entity_id:
      - input_number.dachpv_limiter
conditions: []
actions:
  - action: number.set_value
    target:
      entity_id:
        - number.hofseite_limit_nonpersistent_absolute    #first inverter
        - number.mitte_limit_nonpersistent_absolute         #second inverter
    data:
      value: "{{ states('input_number.dachpv_limiter') | float(0) / 2 }}"   # change divisor (here is set to 2) according to how many inverter you have in your string
mode: single

Now you need to configure the blueprint.

alias: Nulleinpeisung Logik
description: ""
use_blueprint:
  path: NikGro/opendtu_zero_export.yaml
  input:
    sensor_grid_export: sensor.leistungaufnahme
    sensor_dtu_output: sensor.sonoff_energy_power
    number_dtu_limit: input_number.dachpv_limiter  #use your input number helper here! Not the DTU ones!
    input_dtu_max: 1500   #add total power output of all inverters and set it here!
    input_user_min: 50 
    input_user_max: 150

Maybe this hack is useful for somebody.....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment