Create Solar Array Automation

I’m in the progress of building an Automation, that can Limit my inverter Output. Based on a difference between grid import/export.

I’ve set up counters, helpers ect. But the big problem now is getting it to work.

The counters counts kWh. The Sliders indicate the Array’s output in percentage. And the current wattage production.

The goal, is to make sure, that in the end of an hour, the Import / export is equal (or as close as possible).

My idea, is to check the difference every 30 seconds, and adjust the output accordingly. The starting point will always be 100%, and the wattage production is current production at 100 efficiency.

So I need a calculation, based on the difference, and current wattage production, to set the array output to match the difference. So if the current difference is eg. 5 kwh, and the array produces 50 Kwh, then it needs to be set @ 10 percent. This calculation will be done every 30 seconds.

Any good ideas how to accomplish this, for now the values are static, since the inverters has not yet been fitted.

So something like this?

template:
  - trigger:
      - platform: time_pattern
        seconds: "/30"
    sensor:
      - name: "Percentage Power Required"
        unit_of_measurement: "%"
        state: >
          {% set diff = states('sensor.energy_imported')|float(0) - states('sensor.energy_exported')|float(0) %}
          {% if diff > 0 %}
            {{ 100 * diff / 50 }}
          {% else %}
            0
          {% endif %}
        availability: "{{ states('sensor.energy_imported')|is_number and states('sensor.energy_exported')|is_number }}"

You could replace the set 50kW / day with a prediction from a solar forecast integration.

Your solution might work. But I think I’ll need more data (exceptions)

When this will be in effect. I’m looking at an hourly import on approx 20 kWh, and a production capacity on approx 800 kWh. So when a difference on 5 Kwh is active. It could take me as little as 1 minute to even the scale. So for instance. If the output is scaled to 1 %, the next comparison, should take into account if the difference was larger or smaller than the previous. And then increase with 1%. Then the next comparison, should do the same, an increase / decrease by 1% again. and then keep going every 30 seconds.

So the solution might be, to start at 1% and then increase until the difference gets smaller, and the decrease until it rises again. Can that be done ?

:open_mouth:

Are you running an electric aluminium smelter?

20kW in one hour is a constant 83A @ 240V.

In one hour‽

You have an 800kW solar array‽

Is there something wrong with your numbers?

Unfortunately, the numbers are correct. The array is 1250 kWp but only 800 kWh Inverter capacity. I consume 2.000.000 kWh @ Year.

So if the energy prices are negative, it might cost me up to 100 euros an hour…

Also. the 20 kWh is my idle consumption. When at full load, I consume up to 900 kWh an hour. The maximum usage is 2x1000A @ 400V

Been Working forward. Got the slider to update based on values. Trying to make a helper, that shows the current difference with import/export.

However, it gives me a result Is not a dictionary when running it. Do you know why ?

service: input_number.set_value
data: >-
  states('counter.kwh_40007_hourly')|float -
  states('counter.kwh_40007_hourly_export')|float
target:
  entity_id: input_number.40007_hourly_difference
data: >
  {{ states('counter.kwh_40007_hourly')|float(0) -
  states('counter.kwh_40007_hourly_export')|float(0) }}

Triggered by the time pattern at July 3, 2023 at 9:12:40 AM

Input number: Set 40007 - Hourly Difference

Stopped because an error was encountered at July 3, 2023 at 9:12:40 AM (runtime: 0.01 seconds)

Error rendering data template: Result is not a Dictionary

Is it the endpoint that fails, not the calculation ?

service: input_number.set_value
data: >
  {{ states('counter.kwh_40007_hourly')|float(0) -
  states('counter.kwh_40007_hourly_export')|float(0) }}
target:
  entity_id: input_number.40007_hourly_difference

That usually means your indentation is incorrect somewhere. Post the entire automation.

alias: 40007 - Calc. Hourly Difference
description: ""
trigger:
  - platform: time_pattern
    seconds: /5
condition: []
action:
  - service: input_number.set_value
    data: >
      {{ states('counter.kwh_40007_hourly')|float(0) -
      states('counter.kwh_40007_hourly_export')|float(0) }}
    target:
      entity_id: input_number.40007_hourly_difference
mode: single

The data needs a value key:

action:
  - service: input_number.set_value
    data: 
      value:
        {{ states('counter.kwh_40007_hourly')|float(0) -
           states('counter.kwh_40007_hourly_export')|float(0) }}
    target:
      entity_id: input_number.40007_hourly_difference

Changed something :

Stopped because an error was encountered at July 3, 2023 at 10:39:30 AM (runtime: 0.01 seconds)

expected float for dictionary value @ data[‘value’]

I forgot the multi line indicator > after value:

action:
  - service: input_number.set_value
    data: 
      value: >
        {{ states('counter.kwh_40007_hourly')|float(0) -
           states('counter.kwh_40007_hourly_export')|float(0) }}
    target:
      entity_id: input_number.40007_hourly_difference

Perfect. It Now works. Now I have the values I think I need. Current Consumption, current production. (current consumption is import and export combined, so can be positive and negative) and the difference between import and export.

So my idea is.
Look at the Current Import/export (40007_Power_total_all). See if theres a difference in import/export values. If theres too much export. then change the Output from 100% to 1%, and then slowly increase until theres a match between import / export. and then keep the difference to a minimum.

I hope this is described sufficient. The goal is. When the Power prices are Negative. I’ll need to make sure, that I don’t export power (summed pr. hour). this is my best take on how to achieve this, any suggestions is greatly appreciated.