Code kopieren & zu File Editor
Intelligente Energieverteilung und PV-Überschuss-Management mit automatischer Gerätesteuerung basierend auf Strompreisen, PV-Erzeugung und Batteriestatus. - PV-Überschuss Management: Automatische ...
Intelligente Energieverteilung und PV-Überschuss-Management mit automatischer Gerätesteuerung basierend auf Strompreisen, PV-Erzeugung und Batteriestatus.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
# Energy Optimization Integration
# Intelligente Energieverteilung und PV-Überschuss-Management
# Basis-Sensoren für Energiebilanz
sensor:
# Aktueller Energieüberschuss (PV - Verbrauch)
- platform: template
sensors:
energy_surplus:
friendly_name: "Energie-Überschuss"
unit_of_measurement: "W"
value_template: >
{% set pv_power = states('sensor.solar_power') | float(0) %}
{% set house_power = states('sensor.house_consumption') | float(0) %}
{{ (pv_power - house_power) | round(0) }}
icon_template: >
{% if states('sensor.energy_surplus') | float > 500 %}
mdi:solar-power
{% elif states('sensor.energy_surplus') | float > 0 %}
mdi:flash
{% else %}
mdi:transmission-tower
{% endif %}
# Dynamischer Strompreis (für Tibber/aWATTar)
- platform: template
sensors:
electricity_price_level:
friendly_name: "Strompreis-Level"
value_template: >
{% set price = states('sensor.electricity_price_current') | float(0.30) %}
{% if price < 0.20 %}sehr günstig
{% elif price < 0.25 %}günstig
{% elif price < 0.35 %}normal
{% elif price < 0.45 %}teuer
{% else %}sehr teuer
{% endif %}
icon_template: >
{% set price = states('sensor.electricity_price_current') | float(0.30) %}
{% if price < 0.20 %}mdi:currency-eur-off
{% elif price < 0.25 %}mdi:currency-eur
{% elif price < 0.35 %}mdi:currency-eur
{% elif price < 0.45 %}mdi:alert-circle
{% else %}mdi:alert
{% endif %}
# Batteriespeicher Effizienz
- platform: template
sensors:
battery_efficiency:
friendly_name: "Batterie Effizienz"
unit_of_measurement: "%"
value_template: >
{% set charge_power = states('sensor.battery_charge_power') | float(0) %}
{% set discharge_power = states('sensor.battery_discharge_power') | float(0) %}
{% if charge_power > 0 %}
{{ ((discharge_power / charge_power) * 100) | round(1) }}
{% else %}
95
{% endif %}
# Optimaler Geräte-Zeitplan basierend auf PV-Prognose
- platform: template
sensors:
optimal_washing_time:
friendly_name: "Optimale Waschzeit"
value_template: >
{% set now_hour = now().hour %}
{% set pv_forecast = state_attr('sensor.pv_forecast_today', 'hourly') %}
{% if pv_forecast %}
{% set max_pv_hour = pv_forecast.index(pv_forecast | max) + 6 %}
{% if max_pv_hour > 23 %}{{ max_pv_hour - 24 }}:00{% else %}{{ max_pv_hour }}:00{% endif %}
{% else %}
12:00
{% endif %}
# Energiekosten-Prognose für heute
- platform: template
sensors:
energy_cost_forecast:
friendly_name: "Energiekosten Prognose"
unit_of_measurement: "€"
value_template: >
{% set base_consumption = 15 %} # kWh Grundverbrauch
{% set pv_generation = states('sensor.pv_forecast_today') | float(0) %}
{% set price = states('sensor.electricity_price_current') | float(0.30) %}
{% set cost = (base_consumption - pv_generation) * price %}
{{ cost | round(2) if cost > 0 else 0 }}
# Geräte-Prioritäten für Überschuss-Management
input_select:
energy_device_priority:
name: "Geräte-Priorität bei Überschuss"
options:
- "Warmwasser > E-Auto > Waschmaschine > Spülmaschine"
- "E-Auto > Warmwasser > Waschmaschine > Spülmaschine"
- "Waschmaschine > Warmwasser > E-Auto > Spülmaschine"
initial: "Warmwasser > E-Auto > Waschmaschine > Spülmaschine"
# Optimierungs-Modi
input_select:
energy_optimization_mode:
name: "Energieoptimierung Modus"
options:
- "Aus"
- "Nur PV-Überschuss"
- "Günstige Strompreise"
- "Vollautomatisch"
initial: "Nur PV-Überschuss"
# Schwellenwerte für Optimierung
input_number:
energy_surplus_threshold:
name: "PV-Überschuss Schwelle"
min: 500
max: 3000
step: 100
initial: 1000
unit_of_measurement: "W"
icon: "mdi:solar-power"
energy_cheap_price_threshold:
name: "Günstiger Strompreis Schwelle"
min: 0.15
max: 0.30
step: 0.01
initial: 0.22
unit_of_measurement: "€/kWh"
icon: "mdi:currency-eur"
battery_min_soc:
name: "Mindest-Batterieladung"
min: 10
max: 50
step: 5
initial: 20
unit_of_measurement: "%"
icon: "mdi:battery"
# Boolean-Helper für manuelle Steuerung
input_boolean:
energy_optimization_enabled:
name: "Energieoptimierung aktiviert"
initial: true
icon: "mdi:lightning-bolt"
force_device_start:
name: "Geräte-Start erzwingen"
initial: false
icon: "mdi:play-circle"
battery_save_mode:
name: "Batterie-Sparmodus"
initial: false
icon: "mdi:battery-heart"
# Binäre Sensoren für Optimierungs-Bedingungen
binary_sensor:
- platform: template
sensors:
pv_surplus_available:
friendly_name: "PV-Überschuss verfügbar"
value_template: >
{{ states('sensor.energy_surplus') | float >
states('input_number.energy_surplus_threshold') | float }}
delay_on: "00:02:00"
delay_off: "00:05:00"
electricity_price_cheap:
friendly_name: "Günstiger Strompreis"
value_template: >
{{ states('sensor.electricity_price_current') | float <
states('input_number.energy_cheap_price_threshold') | float }}
battery_needs_charging:
friendly_name: "Batterie muss geladen werden"
value_template: >
{{ states('sensor.battery_soc') | float <
states('input_number.battery_min_soc') | float }}
delay_on: "00:10:00"
optimal_time_window:
friendly_name: "Optimales Zeitfenster"
value_template: >
{% set current_hour = now().hour %}
{% set optimal_hour = states('sensor.optimal_washing_time').split(':')[0] | int %}
{{ (current_hour >= optimal_hour and current_hour <= optimal_hour + 3) }}
energy_optimization_conditions_met:
friendly_name: "Optimierungs-Bedingungen erfüllt"
value_template: >
{% set mode = states('input_select.energy_optimization_mode') %}
{% if mode == 'Aus' %}
false
{% elif mode == 'Nur PV-Überschuss' %}
{{ is_state('binary_sensor.pv_surplus_available', 'on') }}
{% elif mode == 'Günstige Strompreise' %}
{{ is_state('binary_sensor.electricity_price_cheap', 'on') }}
{% elif mode == 'Vollautomatisch' %}
{{ is_state('binary_sensor.pv_surplus_available', 'on') or
is_state('binary_sensor.electricity_price_cheap', 'on') or
is_state('binary_sensor.optimal_time_window', 'on') }}
{% endif %}
# Scripts für Geräte-Management
script:
energy_start_water_heater:
alias: "Warmwasser starten"
sequence:
- condition: template
value_template: >
{{ states('sensor.water_heater_temperature') | float < 55 }}
- service: switch.turn_on
target:
entity_id: switch.water_heater
- service: notify.mobile_app
data:
title: "🔥 Warmwasser"
message: "Warmwasserbereitung gestartet (PV-Überschuss)"
energy_start_car_charging:
alias: "E-Auto laden starten"
sequence:
- condition: template
value_template: >
{{ states('sensor.car_battery_level') | float < 80 }}
- condition: state
entity_id: binary_sensor.car_connected
state: "on"
- service: switch.turn_on
target:
entity_id: switch.car_charger
- service: notify.mobile_app
data:
title: "⚡ E-Auto"
message: "Laden gestartet ({{ states('sensor.energy_surplus') }}W Überschuss)"
energy_start_washing_machine:
alias: "Waschmaschine starten"
sequence:
- condition: state
entity_id: binary_sensor.washing_machine_ready
state: "on"
- service: switch.turn_on
target:
entity_id: switch.washing_machine
- service: notify.mobile_app
data:
title: "👕 Waschmaschine"
message: "Waschgang gestartet zur optimalen Zeit"
energy_start_dishwasher:
alias: "Spülmaschine starten"
sequence:
- condition: state
entity_id: binary_sensor.dishwasher_ready
state: "on"
- service: switch.turn_on
target:
entity_id: switch.dishwasher
- service: notify.mobile_app
data:
title: "🍽️ Spülmaschine"
message: "Spülgang gestartet bei günstigem Strom"
energy_stop_non_essential:
alias: "Nicht-essentielle Geräte stoppen"
sequence:
- service: switch.turn_off
target:
entity_id:
- switch.pool_pump
- switch.garden_irrigation
- switch.workshop_heater
- service: climate.set_temperature
target:
entity_id: climate.heat_pump
data:
temperature: 19 # Temperatur reduzieren
- service: notify.mobile_app
data:
title: "⚡ Energiesparmodus"
message: "Nicht-essentielle Verbraucher gestoppt"
# Automatisierungen für intelligente Energieverteilung
automation:
- alias: "PV-Überschuss Management"
trigger:
- platform: state
entity_id: binary_sensor.pv_surplus_available
to: "on"
for: "00:03:00"
condition:
- condition: state
entity_id: input_boolean.energy_optimization_enabled
state: "on"
action:
- choose:
# Priorität 1: Warmwasser
- conditions:
- condition: template
value_template: >
{{ 'Warmwasser' in states('input_select.energy_device_priority') and
states('sensor.water_heater_temperature') | float < 55 }}
sequence:
- service: script.energy_start_water_heater
# Priorität 2: E-Auto (falls verfügbar)
- conditions:
- condition: state
entity_id: binary_sensor.car_connected
state: "on"
- condition: template
value_template: >
{{ states('sensor.car_battery_level') | float < 80 }}
sequence:
- service: script.energy_start_car_charging
# Priorität 3: Waschmaschine
- conditions:
- condition: state
entity_id: binary_sensor.washing_machine_ready
state: "on"
sequence:
- service: script.energy_start_washing_machine
# Fallback: Batterie laden
default:
- condition: template
value_template: >
{{ states('sensor.battery_soc') | float < 95 }}
- service: script.energy_charge_battery
- alias: "Teurer Strom - Verbrauch reduzieren"
trigger:
- platform: template
value_template: >
{{ states('sensor.electricity_price_current') | float > 0.40 }}
for: "00:05:00"
condition:
- condition: state
entity_id: input_boolean.energy_optimization_enabled
state: "on"
action:
- service: script.energy_stop_non_essential
- service: notify.mobile_app
data:
title: "💸 Teurer Strom"
message: "Aktuell {{ states('sensor.electricity_price_current') }}€/kWh - Verbrauch reduziert"
- alias: "Batterie-Notladung bei günstigen Preisen"
trigger:
- platform: state
entity_id: binary_sensor.electricity_price_cheap
to: "on"
condition:
- condition: state
entity_id: binary_sensor.battery_needs_charging
state: "on"
- condition: time
after: "23:00:00"
before: "06:00:00"
action:
- service: switch.turn_on
target:
entity_id: switch.battery_charger
- service: notify.mobile_app
data:
title: "🔋 Batterie-Notladung"
message: "Ladung bei günstigem Nachtstrom ({{ states('sensor.electricity_price_current') }}€/kWh)"
- alias: "Optimaler Waschzeitpunkt"
trigger:
- platform: state
entity_id: binary_sensor.optimal_time_window
to: "on"
condition:
- condition: state
entity_id: binary_sensor.washing_machine_ready
state: "on"
- condition: template
value_template: >
{{ 'Vollautomatisch' in states('input_select.energy_optimization_mode') }}
action:
- service: script.energy_start_washing_machine
- alias: "Energieoptimierung Tagesreport"
trigger:
platform: time
at: "20:00:00"
action:
- service: notify.mobile_app
data:
title: "📊 Energie-Tagesreport"
message: >
PV-Ertrag: {{ states('sensor.pv_energy_today') }}kWh
Verbrauch: {{ states('sensor.energy_consumption_today') }}kWh
Kosten: {{ states('sensor.energy_cost_forecast') }}€
Optimierungen: {{ states('counter.energy_optimizations_today') }}
# Counter für Optimierungen
counter:
energy_optimizations_today:
name: "Optimierungen heute"
initial: 0
step: 1
icon: "mdi:lightning-bolt-circle"
# Utility Meter für Energiestatistiken
utility_meter:
energy_savings_daily:
source: sensor.energy_cost_savings
cycle: daily
name: "Tägliche Energieeinsparung"
pv_surplus_utilization_daily:
source: sensor.pv_surplus_used
cycle: daily
name: "Tägliche PV-Überschuss-Nutzung"
# Template für Einsparungsberechnung
sensor:
- platform: template
sensors:
energy_cost_savings:
friendly_name: "Energiekosteneinsparung"
unit_of_measurement: "€"
value_template: >
{% set normal_cost = states('sensor.energy_consumption_today') | float * 0.30 %}
{% set actual_cost = states('sensor.energy_cost_today') | float %}
{{ (normal_cost - actual_cost) | round(2) if normal_cost > actual_cost else 0 }}
pv_surplus_used:
friendly_name: "Genutzter PV-Überschuss"
unit_of_measurement: "kWh"
value_template: >
{% set surplus = states('sensor.energy_surplus') | float %}
{% if surplus > 0 %}
{{ (surplus * 0.25 / 1000) | round(2) }} # 15min Intervall
{% else %}
0
{% endif %}