For a few months now, I have been the proud owner of a PV system with FoxESS H3pro and a hybrid battery. I have two EVs in my garage with a wallbox.
After much deliberation, I connected the inverter to my LAN via Modbus and also to HA via the Foxess Modbus app with lots of sensors, work modes, etc. Everything is great.
So far, I have always pursued the idea of controlling the battery via HA automations and not via an app for HA such as Solar Optimizer.
Important: Due to the Solar Peak Act, my PV system is throttled to 60% (=9 kWh) of the 15kWp. In this respect, I am very interested in charging the battery at peak times on sunny days rather than in the morning.
My thoughts:
Trigger: Check every day at 6.30 a.m. whether Solcast peak power is higher than 8000W.
–> If yes: Only charge the battery at the time of Solcast peak power. The battery should not be charged before this time.
–> If no: Charge the battery in Self Use Mode in the morning.
Here is my code, which unfortunately does not yet work as I would like it to. The battery is discharged, but NOT charged at peak times.
In addition to this shortcoming, I would like to optimize peak charging so that the battery is not charged at full power, but only with 4.5 kWh, for example, and the rest is fed into the grid.
Do you have any ideas on how to make the script work and optimize it?
Code: Select all
alias: "PV | FoxESS – Tagessteuerung: Entladen & Laden nach Solcast 8kW Regel"
description: Steuert die Batterieladung nach Solcast-Prognose mit Ladefenster bis 15:00
triggers:
- at: "06:30:00"
trigger: time
conditions: []
actions:
- variables:
peak_dt: >
{{ states('sensor.solcast_pv_forecast_zeitpunkt_spitzenleistung_heute')
| as_datetime(default=None) }}
peak_power_w: >
{{ states('sensor.solcast_pv_forecast_prognose_spitzenleistung_heute') |
float(0) }}
now_dt: "{{ now() }}"
precharge_lead_min: 60
window_end_dt: "{{ now().replace(hour=15, minute=0, second=0, microsecond=0) }}"
peak_valid: >
{{ peak_dt is not none and peak_dt.date() == now().date() and peak_dt >
now() }}
precharge_start: |
{% if peak_dt is not none %}
{{ (peak_dt - timedelta(minutes=precharge_lead_min)) }}
{% else %}
{{ None }}
{% endif %}
peak_threshold_w: 8000
- data:
title: PV | FoxESS – Debug
message: >
Solcast: Peak {{ peak_power_w | round(0) }} W um {{ peak_dt if peak_dt
is not none else 'unbekannt' }}. Valid={{ peak_valid }} | Precharge ab
{{ precharge_start if precharge_start is not none else '—' }},
Fenster-Ende: {{ window_end_dt }} | Schwelle: {{ peak_threshold_w }} W.
action: notify.mobile_app_aloha
- choose:
- conditions:
- condition: template
value_template: "{{ peak_power_w >= peak_threshold_w and peak_valid }}"
sequence:
- target:
entity_id: select.h3pro_work_mode
data:
option: Force Discharge
action: select.select_option
- target:
entity_id: number.h3pro_max_charge_current
data:
value: 0
action: number.set_value
- target:
entity_id: number.h3pro_max_discharge_current
data:
value: 50
action: number.set_value
- data:
title: PV | FoxESS – Debug
message: >
Starker Tag erkannt ({{ peak_power_w | round(0) }} W).
Entlade-Phase aktiv. Ladefenster bis {{ window_end_dt }}.
action: notify.mobile_app_aloha
- choose:
- conditions:
- condition: template
value_template: |
{{ precharge_start is not none
and now() >= precharge_start
and now() < window_end_dt }}
sequence: []
default:
- wait_template: |
{{ precharge_start is not none and now() >= precharge_start }}
timeout: "12:00:00"
continue_on_timeout: true
- choose:
- conditions:
- condition: template
value_template: "{{ now() < window_end_dt }}"
sequence:
- target:
entity_id: select.h3pro_work_mode
data:
option: Self Use
action: select.select_option
- target:
entity_id: number.h3pro_max_charge_current
data:
value: 50
action: number.set_value
- target:
entity_id: number.h3pro_max_discharge_current
data:
value: 5
action: number.set_value
- data:
title: PV | FoxESS – Ladefenster aktiv
action: notify.mobile_app_aloha
mode: single