prediction automation for home assistant #1953
Replies: 5 comments 1 reply
-
I copied your code into developer tools/templates and started adding debugging to it to work out what its doing. Didn't get to the end as my battery is empty, but here's where I got to:
|
Beta Was this translation helpful? Give feedback.
-
Thanks for your help. Someone else has offered help on the HA forums and their template collects the data but still doesn't quite work; in the data for today an empty_event should occur at 22:30 ({'time': '22:30', 'value': 0.76},), but it's showing as no battery predictions available. `- variables:
|
Beta Was this translation helpful? Give feedback.
-
might have it here, can't be certain; it still returns no battery predictions available, but with my current data, that's true. i'll update when ive checked it: {% set today_midnight = today_at() + timedelta(days=1) %}
{% set pred_data = state_attr('predbat.soc_kw_best', 'results') %}
{% set pred_list = [] %}
{% if pred_data %}
{% for ts_str, value in pred_data.items() %}
{% set dt = strptime(ts_str, '%Y-%m-%dT%H:%M:%S%z') %}
{% if dt < today_midnight %}
{% set pred_list = pred_list + [{
'time': dt.time().strftime('%H:%M'),
'value': value | float(0)
}] %}
{% endif %}
{% endfor %}
{% endif %}
{% set predictions = pred_list | sort(attribute='time') %}
{# Now use the variable predictions (a list) in your filters #}
{% set charge_events = predictions | selectattr('value', '>=', full_charge) | list %}
{% set empty_events = predictions | selectattr('value', '<=', empty_level) | list %}
{# Finally, output your message based on the lists #}
{% if predictions %}
Today's battery forecast:
{% if charge_events %}
→ Full charge at {{ charge_events[0].time }}
{% endif %}
{% if empty_events %}
→ Empty at {{ empty_events[0].time }}
{% endif %}
{% if not charge_events and not empty_events %}
→ Range: {{ predictions|map(attribute='value')|min|round(1) }}kWh to
{{ predictions|map(attribute='value')|max|round(1) }}kWh
{% endif %}
{% else %}
No battery predictions available
{% endif %} |
Beta Was this translation helpful? Give feedback.
-
it's taken me a while but i think this works: alias: (1100) Home Battery Max/Min TTS Analysis
description: Announce battery full/empty times and range daily at 11:00
triggers:
- at: "11:00:00"
trigger: time
actions:
- data:
message: >
{% set full_kwh = 19.05 %} {% set empty_kwh = 0.76 %} {% set
capacity_range = full_kwh - empty_kwh %}
{% set results = state_attr('predbat.soc_kw_best', 'results') %} {% set
current_date = now().date() %}
{# Initialize trackers using concatenation-only #} {% set track =
namespace(
max_kwh=-999,
max_times=[],
min_kwh=999,
min_times=[],
full_times=[],
empty_times=[]
) %}
{# Percentage conversion macro #} {%- macro to_percent(kwh) -%}
{{ (((kwh - empty_kwh) / capacity_range * 100) | round(0)) }}
{%- endmacro -%}
{# Process predictions #} {% for timestamp_str, soc in results.items()
if timestamp_str != 'today' %}
{% set ts = (timestamp_str | replace('+0000', '+00:00') | as_datetime) %}
{% if ts.date() == current_date %}
{# Track max value #}
{% if soc > track.max_kwh %}
{% set track.max_kwh = soc %}
{% set track.max_times = [ts] %}
{% elif soc == track.max_kwh %}
{% set track.max_times = track.max_times + [ts] %}
{% endif %}
{# Track min value #}
{% if soc < track.min_kwh %}
{% set track.min_kwh = soc %}
{% set track.min_times = [ts] %}
{% elif soc == track.min_kwh %}
{% set track.min_times = track.min_times + [ts] %}
{% endif %}
{# Check thresholds with concatenation #}
{% if soc == full_kwh %}
{% set track.full_times = track.full_times + [ts.strftime('%H:%M')] %}
{% elif soc == empty_kwh %}
{% set track.empty_times = track.empty_times + [ts.strftime('%H:%M')] %}
{% endif %}
{% endif %}
{% endfor %}
{# Build message without using append #} {% set max_percent =
to_percent(track.max_kwh) %} {% set min_percent =
to_percent(track.min_kwh) %} {% set max_time =
track.max_times[0].strftime('%H:%M') if track.max_times else '' %} {%
set min_time = track.min_times[0].strftime('%H:%M') if track.min_times
else '' %}
{% set threshold_events = [] %} {% if track.full_times | length > 0 %}
{% set threshold_events = threshold_events + ['Fully charged at ' + track.full_times | join(', ')] %}
{% endif %} {% if track.empty_times | length > 0 %}
{% set threshold_events = threshold_events + ['Empty reserve hit at ' + track.empty_times | join(', ')] %}
{% endif %}
Battery status: {% if threshold_events | length > 0 %}{{
threshold_events | join(' and ') }}. {% endif %} Today's range: {{
max_percent }}%{% if track.max_kwh == full_kwh %} (FULL){% endif %} at
{{ max_time }} to {{ min_percent }}%{% if track.min_kwh == empty_kwh %}
(EMPTY){% endif %} at {{ min_time }}.
cache: false
media_player_entity_id: media_player.nest_mini_speakers
target:
entity_id: tts.piper
action: tts.speak my example output from this morning was "Battery status: Fully charged at 14:15, 16:00 and Empty reserve hit at It would be nice if this can be a place for other peoples home assistant automations re predbat can go? |
Beta Was this translation helpful? Give feedback.
-
the one i have for cars so far is this (have removed my octopus account number): alias: (~1015 or when EV plugged in) Cheap Rate Slots TTS Announcement
description: Triggers when planned_dispatches changes from empty to populated
triggers:
- event_type: state_changed
event_data:
entity_id: binary_sensor.octopus_energy_a_*accountnumber*_intelligent_dispatching
trigger: event
conditions:
- condition: template
value_template: >-
{% set old = trigger.event.data.old_state.attributes.planned_dispatches |
default([]) %} {% set new =
trigger.event.data.new_state.attributes.planned_dispatches | default([])
%} {{ (old | length == 0) and (new | length > 0) }}
actions:
- data:
cache: false
media_player_entity_id: media_player.nest_mini_speakers
message: >-
{% set dispatches =
state_attr('binary_sensor.octopus_energy_a_*accountnumber*_intelligent_dispatching',
'planned_dispatches') %}
Cheap rate slots received: {% for slot in dispatches -%}
{% set start = as_timestamp(slot.start) | timestamp_custom("%-I:%M%p") | lower %}
{% set end = as_timestamp(slot.end) | timestamp_custom("%-I:%M%p") | lower %}
{{ start }} to {{ end }}{% if not loop.last %}{% if loop.revindex == 2 %} and {% else %}, {% endif %}{% endif %}
{%- endfor %}.
{% if is_state('binary_sensor.kona_ev_battery_plug', 'on') %}
{% set car = 'grey' %}
{% set soc = states('sensor.kona_ev_battery_level') | float %}
{% set predbat_entity = 'predbat.car_soc' %}
{% elif is_state('binary_sensor.kona_ev_battery_plug_2', 'on') %}
{% set car = 'red' %}
{% set soc = states('sensor.kona_ev_battery_level_2') | float %}
{% set predbat_entity = 'predbat.car_soc_1' %}
{% endif %}
{% if car %}
The {{ car }} kona is currently at {{ soc | round(1) }}% battery.
{% if soc < 100 %}
{% set charge_time = none %}
{% set final_soc = soc %}
{% set predbat_results = state_attr(predbat_entity, 'results') | default({}) %}
{% for ts_str, percentage in predbat_results.items() | sort %}
{% set dt = (ts_str | regex_replace('\+0000', 'Z')) | as_datetime %}
{% if dt and percentage | float >= 100 %}
{% for slot in dispatches %}
{% set slot_start = as_timestamp(slot.start) %}
{% set slot_end = as_timestamp(slot.end) %}
{% if slot_start <= dt.timestamp() <= slot_end %}
{% set charge_time = dt.strftime('%-I:%M%p') | lower %}
{% break %}
{% endif %}
{% endfor %}
{% endif %}
{% if charge_time %}{% break %}{% endif %}
{% endfor %}
{% if not charge_time %}
{% for ts_str, percentage in predbat_results.items() | sort %}
{% set dt = (ts_str | regex_replace('\+0000', 'Z')) | as_datetime %}
{% if dt %}
{% for slot in dispatches %}
{% set slot_start = as_timestamp(slot.start) %}
{% set slot_end = as_timestamp(slot.end) %}
{% if slot_start <= dt.timestamp() <= slot_end %}
{% set final_soc = percentage | float %}
{% endif %}
{% endfor %}
{% endif %}
{% endfor %}
{% endif %}
{% if charge_time %}
It will reach 100% by {{ charge_time }}.
{% elif final_soc > soc %}
Will charge up to {{ final_soc | round(1) }}%.
{% else %}
Charging projection unavailable.
{% endif %}
{% endif %}
{% endif %}
target:
entity_id: tts.piper
action: tts.speak It's announcing the cheap rate slots, the currently connected car and the current SoC of that car correctly, but as far as comparing the time slots goes etc, it's a nightmare. I think not least because the timestamps are formatted slightly differently, octopus being for example '2025-02-21T13:56:00+00:00' and predbat being for example 2025-02-21T14:20:00+0000. a lot of that could be removed/simplified with only 1 EV, but doesnt change the issue with comparing time slots/analysis. |
Beta Was this translation helpful? Give feedback.
-
Hello, I'm trying to make a HA automation that takes predbat.soc_kw_best attributes, checks whether the SoC will hit max and or min (in my case 19.05 and 0.76), get the times (if any) up to midnight and announce them via tts, but I'm struggling with the code. My attributes as an example:
`"results:
2025-02-01T18:50:00+0000: 9.91
2025-02-01T18:55:00+0000: 9.706
2025-02-01T19:00:00+0000: 9.498
2025-02-01T19:05:00+0000: 9.345
2025-02-01T19:10:00+0000: 9.086
2025-02-01T19:15:00+0000: 8.947
2025-02-01T19:20:00+0000: 8.715
2025-02-01T19:25:00+0000: 8.576
2025-02-01T19:30:00+0000: 8.321
2025-02-01T19:35:00+0000: 8.094
2025-02-01T19:40:00+0000: 7.782
2025-02-01T19:45:00+0000: 7.469
2025-02-01T19:50:00+0000: 7.157
2025-02-01T19:55:00+0000: 6.844
2025-02-01T20:00:00+0000: 6.532
2025-02-01T20:05:00+0000: 6.219
2025-02-01T20:10:00+0000: 5.907
2025-02-01T20:15:00+0000: 5.594
2025-02-01T20:20:00+0000: 5.282
2025-02-01T20:25:00+0000: 4.969
2025-02-01T20:30:00+0000: 4.657
2025-02-01T20:35:00+0000: 4.344
2025-02-01T20:40:00+0000: 4.032
2025-02-01T20:45:00+0000: 3.719
2025-02-01T20:50:00+0000: 3.407
2025-02-01T20:55:00+0000: 3.094
2025-02-01T21:00:00+0000: 2.782
2025-02-01T21:05:00+0000: 2.469
2025-02-01T21:10:00+0000: 2.157
2025-02-01T21:15:00+0000: 1.844
2025-02-01T21:20:00+0000: 1.532
2025-02-01T21:25:00+0000: 1.219
2025-02-01T21:30:00+0000: 0.907
2025-02-01T21:35:00+0000: 1.195
2025-02-01T21:40:00+0000: 1.483
2025-02-01T21:45:00+0000: 1.771
2025-02-01T21:50:00+0000: 2.059
2025-02-01T21:55:00+0000: 2.347
2025-02-01T22:00:00+0000: 2.635
2025-02-01T22:05:00+0000: 2.322
2025-02-01T22:10:00+0000: 2.01
2025-02-01T22:15:00+0000: 1.697
2025-02-01T22:20:00+0000: 1.385
2025-02-01T22:25:00+0000: 1.072
2025-02-01T22:30:00+0000: 0.76
2025-02-01T22:35:00+0000: 1.048
2025-02-01T22:40:00+0000: 1.336
2025-02-01T22:45:00+0000: 1.624
2025-02-01T22:50:00+0000: 1.912
2025-02-01T22:55:00+0000: 2.2
2025-02-01T23:00:00+0000: 2.488
2025-02-01T23:05:00+0000: 2.776
2025-02-01T23:10:00+0000: 3.064
2025-02-01T23:15:00+0000: 3.352
2025-02-01T23:20:00+0000: 3.64
2025-02-01T23:25:00+0000: 3.928
2025-02-01T23:30:00+0000: 4.216
2025-02-01T23:35:00+0000: 4.504
2025-02-01T23:40:00+0000: 4.792
2025-02-01T23:45:00+0000: 5.08
2025-02-01T23:50:00+0000: 5.368
2025-02-01T23:55:00+0000: 5.656
2025-02-02T00:00:00+0000: 5.944
2025-02-02T00:05:00+0000: 6.232
2025-02-02T00:10:00+0000: 6.52
2025-02-02T00:15:00+0000: 6.808
2025-02-02T00:20:00+0000: 7.096
2025-02-02T00:25:00+0000: 7.384
2025-02-02T00:30:00+0000: 7.672
2025-02-02T00:35:00+0000: 7.96
2025-02-02T00:40:00+0000: 8.248
2025-02-02T00:45:00+0000: 8.536
2025-02-02T00:50:00+0000: 8.824
2025-02-02T00:55:00+0000: 9.112
2025-02-02T01:00:00+0000: 9.4
2025-02-02T01:05:00+0000: 9.688
2025-02-02T01:10:00+0000: 9.976
2025-02-02T01:15:00+0000: 10.264
2025-02-02T01:20:00+0000: 10.552
2025-02-02T01:25:00+0000: 10.84
2025-02-02T01:30:00+0000: 11.128
2025-02-02T01:35:00+0000: 11.416
2025-02-02T01:40:00+0000: 11.704
2025-02-02T01:45:00+0000: 11.992
2025-02-02T01:50:00+0000: 12.28
2025-02-02T01:55:00+0000: 12.568
2025-02-02T02:00:00+0000: 12.856
2025-02-02T02:05:00+0000: 13.144
2025-02-02T02:10:00+0000: 13.432
2025-02-02T02:15:00+0000: 13.72
2025-02-02T02:20:00+0000: 14.008
2025-02-02T02:25:00+0000: 14.296
2025-02-02T02:30:00+0000: 14.584
2025-02-02T02:35:00+0000: 14.872
2025-02-02T02:40:00+0000: 15.16
2025-02-02T02:45:00+0000: 15.448
2025-02-02T02:50:00+0000: 15.736
2025-02-02T02:55:00+0000: 16.024
2025-02-02T03:00:00+0000: 16.312
2025-02-02T03:05:00+0000: 16.6
2025-02-02T03:10:00+0000: 16.888
2025-02-02T03:15:00+0000: 17.141
2025-02-02T03:20:00+0000: 17.383
2025-02-02T03:25:00+0000: 17.582
2025-02-02T03:30:00+0000: 17.755
2025-02-02T03:35:00+0000: 17.905
2025-02-02T03:40:00+0000: 18.04
2025-02-02T03:45:00+0000: 18.164
2025-02-02T03:50:00+0000: 18.288
2025-02-02T03:55:00+0000: 18.391
2025-02-02T04:00:00+0000: 18.466
2025-02-02T04:05:00+0000: 18.541
2025-02-02T04:10:00+0000: 18.616
2025-02-02T04:15:00+0000: 18.662
2025-02-02T04:20:00+0000: 18.708
2025-02-02T04:25:00+0000: 18.754
2025-02-02T04:30:00+0000: 18.8
2025-02-02T04:35:00+0000: 18.835
2025-02-02T04:40:00+0000: 18.869
2025-02-02T04:45:00+0000: 18.904
2025-02-02T04:50:00+0000: 18.939
2025-02-02T04:55:00+0000: 18.973
2025-02-02T05:00:00+0000: 19.008
2025-02-02T05:05:00+0000: 19.042
2025-02-02T05:10:00+0000: 19.05
2025-02-02T05:30:00+0000: 19.05
2025-02-02T05:35:00+0000: 19.014
2025-02-02T05:40:00+0000: 18.946
2025-02-02T05:45:00+0000: 18.901
2025-02-02T05:50:00+0000: 18.824
2025-02-02T05:55:00+0000: 18.775
2025-02-02T06:00:00+0000: 18.701
2025-02-02T06:05:00+0000: 18.657
2025-02-02T06:10:00+0000: 18.578
2025-02-02T06:15:00+0000: 18.529
2025-02-02T06:20:00+0000: 18.456
2025-02-02T06:25:00+0000: 18.413
2025-02-02T06:30:00+0000: 18.332
2025-02-02T06:35:00+0000: 18.267
2025-02-02T06:40:00+0000: 18.069
2025-02-02T06:45:00+0000: 17.971
2025-02-02T06:50:00+0000: 17.825
2025-02-02T06:55:00+0000: 17.714
2025-02-02T07:00:00+0000: 17.642
2025-02-02T07:05:00+0000: 17.598
2025-02-02T07:10:00+0000: 17.508
2025-02-02T07:15:00+0000: 17.456
2025-02-02T07:20:00+0000: 17.375
2025-02-02T07:25:00+0000: 17.327
2025-02-02T07:30:00+0000: 17.246
2025-02-02T07:35:00+0000: 17.197
2025-02-02T07:40:00+0000: 17.118
2025-02-02T07:45:00+0000: 17.074
2025-02-02T07:50:00+0000: 17.002
2025-02-02T07:55:00+0000: 16.958
2025-02-02T08:00:00+0000: 16.885
2025-02-02T08:05:00+0000: 16.832
2025-02-02T08:10:00+0000: 16.744
2025-02-02T08:15:00+0000: 16.683
2025-02-02T08:20:00+0000: 16.37
2025-02-02T08:25:00+0000: 16.112
2025-02-02T08:30:00+0000: 15.973
2025-02-02T08:35:00+0000: 15.901
2025-02-02T08:40:00+0000: 15.78
2025-02-02T08:45:00+0000: 15.703
2025-02-02T08:50:00+0000: 15.557
2025-02-02T08:55:00+0000: 15.475
2025-02-02T09:00:00+0000: 15.332
2025-02-02T09:05:00+0000: 15.249
2025-02-02T09:10:00+0000: 15.036
2025-02-02T09:15:00+0000: 14.781
2025-02-02T09:20:00+0000: 14.592
2025-02-02T09:25:00+0000: 14.429
2025-02-02T09:30:00+0000: 14.206
2025-02-02T09:35:00+0000: 14.123
2025-02-02T09:40:00+0000: 13.996
2025-02-02T09:45:00+0000: 13.902
2025-02-02T09:50:00+0000: 13.775
2025-02-02T09:55:00+0000: 13.584
2025-02-02T10:00:00+0000: 13.272
2025-02-02T10:05:00+0000: 12.959
2025-02-02T10:10:00+0000: 12.655
2025-02-02T10:15:00+0000: 12.475
2025-02-02T10:20:00+0000: 12.193
2025-02-02T10:25:00+0000: 11.92
2025-02-02T10:30:00+0000: 11.616
2025-02-02T10:35:00+0000: 11.478
2025-02-02T10:40:00+0000: 11.212
2025-02-02T10:45:00+0000: 11.018
2025-02-02T10:50:00+0000: 10.752
2025-02-02T10:55:00+0000: 10.588
2025-02-02T11:00:00+0000: 10.465
2025-02-02T11:05:00+0000: 10.302
2025-02-02T11:10:00+0000: 10.111
2025-02-02T11:15:00+0000: 9.919
2025-02-02T11:20:00+0000: 9.683
2025-02-02T11:25:00+0000: 9.501
2025-02-02T11:30:00+0000: 9.264
2025-02-02T11:35:00+0000: 9.006
2025-02-02T11:40:00+0000: 8.787
2025-02-02T11:45:00+0000: 8.474
2025-02-02T11:50:00+0000: 8.255
2025-02-02T11:55:00+0000: 8.167
2025-02-02T12:00:00+0000: 7.947
2025-02-02T12:05:00+0000: 7.776
2025-02-02T12:10:00+0000: 7.778
2025-02-02T12:15:00+0000: 7.698
2025-02-02T12:20:00+0000: 7.676
2025-02-02T12:25:00+0000: 7.58
2025-02-02T12:30:00+0000: 7.607
2025-02-02T12:35:00+0000: 7.646
2025-02-02T12:40:00+0000: 7.523
2025-02-02T12:45:00+0000: 7.478
2025-02-02T12:50:00+0000: 7.415
2025-02-02T12:55:00+0000: 7.37
2025-02-02T13:00:00+0000: 7.342
2025-02-02T13:05:00+0000: 7.356
2025-02-02T13:10:00+0000: 7.276
2025-02-02T13:15:00+0000: 7.262
2025-02-02T13:20:00+0000: 7.152
2025-02-02T13:25:00+0000: 6.974
2025-02-02T13:30:00+0000: 6.897
2025-02-02T13:35:00+0000: 6.805
2025-02-02T13:40:00+0000: 6.717
2025-02-02T13:45:00+0000: 6.61
2025-02-02T13:50:00+0000: 6.629
2025-02-02T13:55:00+0000: 6.355
2025-02-02T14:00:00+0000: 6.286
2025-02-02T14:05:00+0000: 6.282
2025-02-02T14:10:00+0000: 6.09
2025-02-02T14:15:00+0000: 5.955
2025-02-02T14:20:00+0000: 5.908
2025-02-02T14:25:00+0000: 5.744
2025-02-02T14:30:00+0000: 5.641
2025-02-02T14:35:00+0000: 5.514
2025-02-02T14:40:00+0000: 5.255
2025-02-02T14:45:00+0000: 5.11
2025-02-02T14:50:00+0000: 4.974
2025-02-02T14:55:00+0000: 4.86
2025-02-02T15:00:00+0000: 4.685
2025-02-02T15:05:00+0000: 4.572
2025-02-02T15:10:00+0000: 4.352
2025-02-02T15:15:00+0000: 4.224
2025-02-02T15:20:00+0000: 4.025
2025-02-02T15:25:00+0000: 3.896
2025-02-02T15:30:00+0000: 3.691
2025-02-02T15:35:00+0000: 3.516
2025-02-02T15:40:00+0000: 3.259
2025-02-02T15:45:00+0000: 3.123
2025-02-02T15:50:00+0000: 2.855
2025-02-02T15:55:00+0000: 2.69
2025-02-02T16:00:00+0000: 2.419
2025-02-02T16:05:00+0000: 2.249
2025-02-02T16:10:00+0000: 1.98
2025-02-02T16:15:00+0000: 1.839
2025-02-02T16:20:00+0000: 1.577
2025-02-02T16:25:00+0000: 1.429
2025-02-02T16:30:00+0000: 1.195
2025-02-02T16:35:00+0000: 1.052
2025-02-02T16:40:00+0000: 0.812
2025-02-02T16:45:00+0000: 0.76
2025-02-02T23:30:00+0000: 0.76
2025-02-02T23:35:00+0000: 1.048
2025-02-02T23:40:00+0000: 1.336
2025-02-02T23:45:00+0000: 1.624
2025-02-02T23:50:00+0000: 1.912
2025-02-02T23:55:00+0000: 2.2
2025-02-03T00:00:00+0000: 2.488
2025-02-03T00:05:00+0000: 2.776
2025-02-03T00:10:00+0000: 3.064
2025-02-03T00:15:00+0000: 3.352
2025-02-03T00:20:00+0000: 3.64
2025-02-03T00:25:00+0000: 3.928
2025-02-03T00:30:00+0000: 4.216
2025-02-03T00:35:00+0000: 4.504
2025-02-03T00:40:00+0000: 4.792
2025-02-03T00:45:00+0000: 5.08
2025-02-03T00:50:00+0000: 5.368
2025-02-03T00:55:00+0000: 5.656
2025-02-03T01:00:00+0000: 5.944
2025-02-03T01:05:00+0000: 6.232
2025-02-03T01:10:00+0000: 6.52
2025-02-03T01:15:00+0000: 6.808
2025-02-03T01:20:00+0000: 7.096
2025-02-03T01:25:00+0000: 7.384
2025-02-03T01:30:00+0000: 7.672
2025-02-03T01:35:00+0000: 7.96
2025-02-03T01:40:00+0000: 8.248
2025-02-03T01:45:00+0000: 8.536
2025-02-03T01:50:00+0000: 8.824
2025-02-03T01:55:00+0000: 9.112
2025-02-03T02:00:00+0000: 9.4
2025-02-03T02:05:00+0000: 9.688
2025-02-03T02:10:00+0000: 9.976
2025-02-03T02:15:00+0000: 10.264
2025-02-03T02:20:00+0000: 10.552
2025-02-03T02:25:00+0000: 10.84
2025-02-03T02:30:00+0000: 11.128
2025-02-03T02:35:00+0000: 11.416
2025-02-03T02:40:00+0000: 11.704
2025-02-03T02:45:00+0000: 11.992
2025-02-03T02:50:00+0000: 12.28
2025-02-03T02:55:00+0000: 12.568
2025-02-03T03:00:00+0000: 12.856
2025-02-03T03:05:00+0000: 13.144
2025-02-03T03:10:00+0000: 13.432
2025-02-03T03:15:00+0000: 13.72
2025-02-03T03:20:00+0000: 14.008
2025-02-03T03:25:00+0000: 14.296
2025-02-03T03:30:00+0000: 14.584
2025-02-03T03:35:00+0000: 14.872
2025-02-03T03:40:00+0000: 15.16
2025-02-03T03:45:00+0000: 15.448
2025-02-03T03:50:00+0000: 15.736
2025-02-03T03:55:00+0000: 16.024
2025-02-03T04:00:00+0000: 16.312
2025-02-03T04:05:00+0000: 16.6
2025-02-03T04:10:00+0000: 16.888
2025-02-03T04:15:00+0000: 17.141
2025-02-03T04:20:00+0000: 17.383
2025-02-03T04:25:00+0000: 17.582
2025-02-03T04:30:00+0000: 17.755
2025-02-03T04:35:00+0000: 17.905
2025-02-03T04:40:00+0000: 18.04
2025-02-03T04:45:00+0000: 18.164
2025-02-03T04:50:00+0000: 18.288
2025-02-03T04:55:00+0000: 18.391
2025-02-03T05:00:00+0000: 18.466
2025-02-03T05:05:00+0000: 18.541
2025-02-03T05:10:00+0000: 18.616
2025-02-03T05:15:00+0000: 18.662
2025-02-03T05:20:00+0000: 18.708
2025-02-03T05:25:00+0000: 18.754
2025-02-03T05:30:00+0000: 18.8
2025-02-03T05:35:00+0000: 18.675
2025-02-03T05:40:00+0000: 18.571
2025-02-03T05:45:00+0000: 18.495
2025-02-03T05:50:00+0000: 18.388
2025-02-03T05:55:00+0000: 18.32
2025-02-03T06:00:00+0000: 18.199
2025-02-03T06:05:00+0000: 18.126
2025-02-03T06:10:00+0000: 18.023
2025-02-03T06:15:00+0000: 17.952
2025-02-03T06:20:00+0000: 17.84
2025-02-03T06:25:00+0000: 17.777
2025-02-03T06:30:00+0000: 17.686
2025-02-03T06:35:00+0000: 17.622
2025-02-03T06:40:00+0000: 17.501
2025-02-03T06:45:00+0000: 17.428
2025-02-03T06:50:00+0000: 17.324
2025-02-03T06:55:00+0000: 17.254
2025-02-03T07:00:00+0000: 17.132
2025-02-03T07:05:00+0000: 17.06
2025-02-03T07:10:00+0000: 16.938
2025-02-03T07:15:00+0000: 16.701
2025-02-03T07:20:00+0000: 16.495
2025-02-03T07:25:00+0000: 16.303
2025-02-03T07:30:00+0000: 16.012
2025-02-03T07:35:00+0000: 15.838
2025-02-03T07:40:00+0000: 15.557
2025-02-03T07:45:00+0000: 15.411
2025-02-03T07:50:00+0000: 15.107
2025-02-03T07:55:00+0000: 14.794
2025-02-03T08:00:00+0000: 14.607
2025-02-03T08:05:00+0000: 14.386
2025-02-03T08:10:00+0000: 14.087
2025-02-03T08:15:00+0000: 13.996
2025-02-03T08:20:00+0000: 13.683
2025-02-03T08:25:00+0000: 13.488
2025-02-03T08:30:00+0000: 13.176
2025-02-03T08:35:00+0000: 13.107
2025-02-03T08:40:00+0000: 12.856
2025-02-03T08:45:00+0000: 12.673
2025-02-03T08:50:00+0000: 12.408
2025-02-03T08:55:00+0000: 12.096
2025-02-03T09:00:00+0000: 11.98
2025-02-03T09:05:00+0000: 11.953
2025-02-03T09:10:00+0000: 11.784
2025-02-03T09:15:00+0000: 11.729
2025-02-03T09:20:00+0000: 11.518
2025-02-03T09:25:00+0000: 11.367
2025-02-03T09:30:00+0000: 11.17
2025-02-03T09:35:00+0000: 11.049
2025-02-03T09:40:00+0000: 11.03
2025-02-03T09:45:00+0000: 10.717
2025-02-03T09:50:00+0000: 10.552
2025-02-03T09:55:00+0000: 10.24
2025-02-03T10:00:00+0000: 10.082
2025-02-03T10:05:00+0000: 9.88
2025-02-03T10:10:00+0000: 9.817
2025-02-03T10:15:00+0000: 9.758
2025-02-03T10:20:00+0000: 9.731
2025-02-03T10:25:00+0000: 9.602
2025-02-03T10:30:00+0000: 9.503
2025-02-03T10:35:00+0000: 9.432
2025-02-03T10:40:00+0000: 9.462
2025-02-03T10:45:00+0000: 9.419
2025-02-03T10:50:00+0000: 9.365
2025-02-03T10:55:00+0000: 9.27
2025-02-03T11:00:00+0000: 9.216
2025-02-03T11:05:00+0000: 9.059
2025-02-03T11:10:00+0000: 9.171
2025-02-03T11:15:00+0000: 9.069
2025-02-03T11:20:00+0000: 9.061
2025-02-03T11:25:00+0000: 9.067
2025-02-03T11:30:00+0000: 8.928
2025-02-03T11:35:00+0000: 8.859
2025-02-03T11:40:00+0000: 8.878
2025-02-03T11:45:00+0000: 8.891
2025-02-03T11:50:00+0000: 8.769
2025-02-03T11:55:00+0000: 8.712
2025-02-03T12:00:00+0000: 8.591
2025-02-03T12:05:00+0000: 8.291
2025-02-03T12:10:00+0000: 8.243
2025-02-03T12:15:00+0000: 8.174
2025-02-03T12:20:00+0000: 8.21
2025-02-03T12:25:00+0000: 8.17
2025-02-03T12:30:00+0000: 8.206
2025-02-03T12:35:00+0000: 8.166
2025-02-03T12:40:00+0000: 8.201
2025-02-03T12:45:00+0000: 8.145
2025-02-03T12:50:00+0000: 8.104
2025-02-03T12:55:00+0000: 8.016
2025-02-03T13:00:00+0000: 7.984
2025-02-03T13:05:00+0000: 7.969
2025-02-03T13:10:00+0000: 7.982
2025-02-03T13:15:00+0000: 7.862
2025-02-03T13:20:00+0000: 7.984
2025-02-03T13:25:00+0000: 7.873
2025-02-03T13:30:00+0000: 7.975
2025-02-03T13:35:00+0000: 7.854
2025-02-03T13:40:00+0000: 7.921
2025-02-03T13:45:00+0000: 7.951
2025-02-03T13:50:00+0000: 7.868
2025-02-03T13:55:00+0000: 7.899
2025-02-03T14:00:00+0000: 7.893
2025-02-03T14:05:00+0000: 7.755
2025-02-03T14:10:00+0000: 7.841
2025-02-03T14:15:00+0000: 7.604
2025-02-03T14:20:00+0000: 7.566
2025-02-03T14:25:00+0000: 7.254
2025-02-03T14:30:00+0000: 7.354
2025-02-03T14:35:00+0000: 7.254
2025-02-03T14:40:00+0000: 7.23
2025-02-03T14:45:00+0000: 7.119
2025-02-03T14:50:00+0000: 7.094
2025-02-03T14:55:00+0000: 7.022
2025-02-03T15:00:00+0000: 6.964
2025-02-03T15:05:00+0000: 6.778
2025-02-03T15:10:00+0000: 6.665
2025-02-03T15:15:00+0000: 6.59
2025-02-03T15:20:00+0000: 6.414
2025-02-03T15:25:00+0000: 6.354
2025-02-03T15:30:00+0000: 6.27
2025-02-03T15:35:00+0000: 6.149
2025-02-03T15:40:00+0000: 5.837
2025-02-03T15:45:00+0000: 5.68
2025-02-03T15:50:00+0000: 5.49
2025-02-03T15:55:00+0000: 5.391
2025-02-03T16:00:00+0000: 5.194
2025-02-03T16:05:00+0000: 5.084
2025-02-03T16:10:00+0000: 4.867
2025-02-03T16:15:00+0000: 4.758
2025-02-03T16:20:00+0000: 4.532
2025-02-03T16:25:00+0000: 4.393
2025-02-03T16:30:00+0000: 4.162
2025-02-03T16:35:00+0000: 4.018
2025-02-03T16:40:00+0000: 3.705
2025-02-03T16:45:00+0000: 3.449
2025-02-03T16:50:00+0000: 3.137
2025-02-03T16:55:00+0000: 2.824
2025-02-03T17:00:00+0000: 2.545
2025-02-03T17:05:00+0000: 2.399
2025-02-03T17:10:00+0000: 2.157
2025-02-03T17:15:00+0000: 2.012
2025-02-03T17:20:00+0000: 1.769
2025-02-03T17:25:00+0000: 1.624
2025-02-03T17:30:00+0000: 1.369
2025-02-03T17:35:00+0000: 1.197
2025-02-03T17:40:00+0000: 0.955
2025-02-03T17:45:00+0000: 0.809
2025-02-03T17:50:00+0000: 0.76
2025-02-03T18:45:00+0000: 0.76
today: 5.944
friendly_name: Battery SoC kWh best
state_class: measurement
unit_of_measurement: kWh
first_charge_kwh: 0.9068
soc_now: 9.91
value_per_kwh_now: 7.76
value_per_kwh_end: 7.76
value_now: 76.87
value_end: 5.9
icon: mdi:battery"`
so they occur there
2025-02-01T22:30:00+0000: 0.76 2025-02-02T05:10:00+0000: 19.05 2025-02-02T05:30:00+0000: 19.05 2025-02-02T16:45:00+0000: 0.76 2025-02-02T23:30:00+0000: 0.76 2025-02-03T17:50:00+0000: 0.76 2025-02-03T18:45:00+0000: 0.76
not necessarily before midnight, but you hopefully get the idea. The tts announcement based on the above would be something like "batteries empty at 22:30"
The closest I've got is this, but it either won't announce anything, or will say no battery predictions available:
`alias: Predbat TTS Analysis
description: Daily battery forecast at 09:45
mode: single
triggers:
trigger: time
actions:
full_charge: 19.05
empty_level: 0.76
predictions: >-
{% set today_midnight = now().replace(hour=0, minute=0, second=0,
microsecond=0) + timedelta(days=1) %} {% set pred_data =
state_attr('predbat.soc_kw_best', 'results') %} {% set pred_list = [] %}
{% for ts_str, value in pred_data.items() %}
{% set dt = strptime(ts_str, '%Y-%m-%dT%H:%M:%S%z') %}
{% if dt < today_midnight %}
{% set pred_list = pred_list + [{
'time': dt.time().strftime('%H:%M'),
'value': value | float
}] %}
{% endif %}
{% endfor %} {{ pred_list | sort(attribute='time') }}
charge_events: "{{ predictions|selectattr('value', '>=', full_charge)|list }}"
empty_events: "{{ predictions|selectattr('value', '<=', empty_level)|list }}"
message: |-
{% if predictions %}
Today's battery forecast:
{% if charge_events %}→ Full charge at {{ charge_events[0].time }}{% endif %}
{% if empty_events %}→ Empty at {{ empty_events[0].time }}{% endif %}
{% if not charge_events and not empty_events %}
→ Range: {{ predictions|map(attribute='value')|min|round(1) }}kWh to
{{ predictions|map(attribute='value')|max|round(1) }}kWh
{% endif %}
{% else %}
No battery predictions available
{% endif %}
entity_id: tts.piper
data:
message: "{{ message }}"
media_player_entity_id: media_player.bedroom_mat
cache: false
action: tts.speak`
Thanks
Beta Was this translation helpful? Give feedback.
All reactions