Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start figuring out savings sessions #576

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion .HA_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2024.7.4
2024.8.3
1 change: 1 addition & 0 deletions configuration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ climate: !include climate.yaml
# Merged Includes
automation: !include_dir_list automation
scene: !include_dir_list scenes
template: !include_dir_list templates

# Merged items requiring a dictionary
input_select: !include_dir_named input_select
Expand Down
5 changes: 5 additions & 0 deletions packages/givenergy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ sensor:

# "{{ states('sensor.viewpoint_device_0_arotherm_plus_heat_generated_domestic_hot_water') | int / states('sensor.viewpoint_device_0_arotherm_plus_consumed_electrical_energy_domestic_hot_water') | int | float(default='NaN') }}"

free_electricity:
value_template: "{{ states.calendar.family_calendar.attributes.message }}"
friendly_name: Free Electricity
unique_id: calendar.free_electricity

- platform: integration
source: sensor.grid_all
method: left
Expand Down
21 changes: 21 additions & 0 deletions packages/octopus_savings.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
automation:
- alias: Enable battery charging
id: enable_battery_charging
trigger:
- platform: time
at: "00:00:00"
action:
- service: givenergy_local.enable_timed_charge
data:
device_id: 636335f26ef06930329cf34272a13502
start_time: "13:00:00"
end_time: "14:00:00"

- alias: Disable battery charging
id: disable_battery_charging
trigger:
- platform: time
at: "14:05:00"
action:
- service: homeassistant.turn_off
entity_id: switch.battery_ac_charging
104 changes: 104 additions & 0 deletions templates/octopus_savings.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
- alias: Octopus savings
trigger:
- platform: homeassistant
event: start
- platform: time_pattern
hours: "/6"
- platform: calendar
event: end
entity_id: calendar.family_calendar
- platform: event
event_type: event_template_reloaded
action:
- service: calendar.get_events
data:
end_date_time: "{{now() + timedelta(days=21)}}"
target:
entity_id: calendar.family_calendar
response_variable: agenda
- variables:
dump: "{{ agenda['calendar.family_calendar'].events }}"
all_events: "{{dump |sort(attribute='start') | list }}"
next_5_events: "{{dump |sort(attribute='start') | list }}"
countnumb: "{{dump | length }}"
lastevent: "{{dump[-1] }}"
sensor:
- name: "[Octopus] Free Electricity"
unique_id: upcoming_free_electricity
icon: "mdi:lightning"
picture: /local/sportlogos/f1.png
state: >
{%- if countnumb == 0 %}
Nothing Scheduled
{%- else %}
{%- from 'easy_time.jinja' import easy_relative_time %}
{%- set tmpdate = as_timestamp(next_5_events[0]['start']) %}
{%- set timeto = (as_timestamp(next_5_events[0]['start'])-as_timestamp(now())) / 86400 %}
{{next_5_events[0]['summary']|replace('[F1] ','')}} @ {{next_5_events[0]['location']}} - {{ easy_relative_time(tmpdate, 'day, hour, minute') }} ({{ iif(timeto < 6, tmpdate|timestamp_custom ('%a %H:%M'), tmpdate|timestamp_custom ('%d/%m %H:%M'), "None Recorded")}})
{%- endif %}
attributes:
category: sport
remaining_events: "{{countnumb}}"
last_event: "{{lastevent.end}}"
next_5_events: >
{%- if countnumb == 0 %}
No Events
{%- else %}
{{next_5_events}}
{%- endif %}
nextevent_timeto: >
{%- if countnumb == 0 %}
-999
{%- else %}
{%- set timeto = (as_timestamp(next_5_events[0]['start'])-as_timestamp(now())) / 86400 %}
{{ timeto | round (0) }}
{%- endif %}
nextevent_desc: >
{%- if countnumb == 0 %}
No Event Scheduled
{%- else %}
{{next_5_events[0]['summary']|replace('[F1] ','')}}
{%- endif %}
nextevent_locn: >
{%- if countnumb == 0 %}
No Event Scheduled
{%- else %}
{{next_5_events[0]['location']}}
{%- endif %}
nextevent_time: >
{%- if countnumb == 0 %}
No Event Scheduled
{%- else %}
{%- from 'easy_time.jinja' import easy_relative_time %}
{%- set tmpdate = as_timestamp(next_5_events[0]['start']) %}
{%- set timeto = (as_timestamp(next_5_events[0]['start'])-as_timestamp(now())) / 86400 %}
{{ easy_relative_time(tmpdate, 'day, hour, minute') }} ({{ iif(timeto < 6, tmpdate|timestamp_custom ('%a %H:%M'), tmpdate|timestamp_custom ('%d/%m %H:%M'), "None Recorded")}})
{%- endif %}
afterevent_timeto: >
{%- if countnumb == 0 or countnumb == 1 %}
-999
{%- else %}
{%- set timeto = (as_timestamp(next_5_events[1]['start'])-as_timestamp(now())) / 86400 %}
{{ timeto | round (0) }}
{%- endif %}
afterevent_desc: >
{%- if countnumb == 0 or countnumb == 1 %}
No Event Scheduled
{%- else %}
{{next_5_events[1]['summary']|replace('[F1] ','')}}
{%- endif %}
afterevent_locn: >
{%- if countnumb == 0 or countnumb == 1 %}
No Event Scheduled
{%- else %}
{{next_5_events[1]['location']}}
{%- endif %}
afterevent_time: >
{%- if countnumb == 0 or countnumb == 1 %}
No Event Scheduled
{%- else %}
{%- from 'easy_time.jinja' import easy_relative_time %}
{%- set tmpdate = as_timestamp(next_5_events[1]['start']) %}
{%- set timeto = (as_timestamp(next_5_events[1]['start'])-as_timestamp(now())) / 86400 %}
{{ easy_relative_time(tmpdate, 'day, hour, minute') }} ({{ iif(timeto < 6, tmpdate|timestamp_custom ('%a %H:%M'), tmpdate|timestamp_custom ('%d/%m %H:%M'), "None Recorded")}})
{%- endif %}