Change charge power depending on solar input

Hi

I just like to share my latest automation. I change the charge current to the car depending on incoming solar so I don't run the house battery down to zero and/or need to use the grid.

First I made a sensor for average solar power:

- platform: statistics
  name: Solar PV 5 Min Average
  entity_id: sensor.solarnet_power_photovoltaics
  unique_id: solarpv5minavg
  state_characteristic: mean
  max_age:
    minutes: 5

And an input bolean so I can controll if I like this automation to be active, it's an button in the gui.

input_boolean:
  dynamic_charge:
    name: Change charge speed depending on solar
    icon: mdi:ev-station

And here is the automation, it will execute when car is charging every 5 minutes:

alias: Dynamic charging
description: >-
Updates charging current based on solar, every 5 minutes when the car is charging and
dynamic charging is enabled.
triggers:
  - entity_id: sensor.solarnet_power_photovoltaics
    trigger: state
conditions:
  - condition: state
    entity_id: input_boolean.dynamic_charge
    state: "on"
  - condition: state
    entity_id: sensor.wallbox_pulsarplus_sn_271169_status_beskrivning
    state: Charging
    enabled: true
  - condition: template
    value_template: >-
      {{ states('sensor.solar_pv_5_min_average') not in ['unavailable',
      'unknown'] }}
  - condition: template
    value_template: >-
      {{ this.attributes.last_triggered is none or (now() -
      this.attributes.last_triggered).total_seconds() >= 300 }}
actions:
  - action: number.set_value
    target:
      entity_id: number.wallbox_pulsarplus_sn_271169_maximal_laddningsstrom
    data:
      value: >
        {% set solar = states('sensor.solar_pv_5_min_average') | float(0) %} {%
        if solar >= 9970 %} 13 {% elif solar >= 9280 %} 12 {% elif solar >= 8590
        %} 11 {% elif solar >= 7900 %} 10 {% elif solar >= 7210 %} 9 {% elif
        solar >= 6520 %} 8 {% elif solar >= 5830 %} 7 {% else %} 6 {% endif %}
mode: single

The charge current is calculated so I get about 1000 Watt to the house, I'm fine tuning it right now:

I also have an automation that stop the charging to car if the house battery goes below 80% and resumes when it's over 90%.

Cheers /Anders