Skip to content

Commit fe3b46e

Browse files
committed
blueprint: Updated calculation for OE and CI rates to favour low rates
1 parent d727f82 commit fe3b46e

File tree

1 file changed

+23
-18
lines changed

1 file changed

+23
-18
lines changed

_docs/blueprints/target_timeframes_octopus_energy_carbon_intensity.yaml

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,6 @@ blueprint:
1414
- sensor
1515
integration: target_timeframes
1616
multiple: false
17-
octopus_energy_previous_day_rates:
18-
name: Previous day rates
19-
description: The previous day rates event sensor supplied by Octopus Energy. More information can be found at https://bottlecapdave.github.io/HomeAssistant-OctopusEnergy/entities/electricity/#previous-day-rates.
20-
selector:
21-
entity:
22-
filter:
23-
- domain:
24-
- event
25-
integration: octopus_energy
26-
multiple: false
2717
octopus_energy_current_day_rates:
2818
name: Current day rates
2919
description: The current day rates event sensor supplied by Octopus Energy. More information can be found at https://bottlecapdave.github.io/HomeAssistant-OctopusEnergy/entities/electricity/#current-day-rates.
@@ -61,6 +51,13 @@ blueprint:
6151
selector:
6252
number:
6353
mode: box
54+
octopus_energy_weighting:
55+
name: Octopus Energy rate weighting
56+
description: The weighting to apply to the Octopus Energy rates when calculating the final value for the period.
57+
default: 0.7
58+
selector:
59+
number:
60+
mode: box
6461
carbon_intensity_current_day_rates:
6562
name: Current day rates
6663
description: The current day rates event sensor supplied by Carbon Intensity. More information can be found at https://bottlecapdave.github.io/HomeAssistant-CarbonIntensity/entities/#current-day-rates.
@@ -81,20 +78,26 @@ blueprint:
8178
- event
8279
integration: carbon_intensity
8380
multiple: false
81+
carbon_intensity_weighting:
82+
name: Carbon Intensity forecast weighting
83+
description: The weighting to apply to the Carbon Intensity forecast when calculating the final value for the period.
84+
default: 0.3
85+
selector:
86+
number:
87+
mode: box
8488
variables:
8589
target_timeframe_data_source_sensor: !input target_timeframe_data_source_sensor
86-
octopus_energy_previous_day_rates: !input octopus_energy_previous_day_rates
8790
octopus_energy_current_day_rates: !input octopus_energy_current_day_rates
8891
octopus_energy_next_day_rates: !input octopus_energy_next_day_rates
8992
octopus_energy_free_electricity: !input octopus_energy_free_electricity
9093
octopus_energy_free_electricity_weighting: !input octopus_energy_free_electricity_weighting
9194
carbon_intensity_current_day_rates: !input carbon_intensity_current_day_rates
9295
carbon_intensity_next_day_rates: !input carbon_intensity_next_day_rates
96+
octopus_energy_weighting: !input octopus_energy_weighting
97+
carbon_intensity_weighting: !input carbon_intensity_weighting
9398
mode: queued
9499
max: 4
95100
triggers:
96-
- platform: state
97-
entity_id: !input octopus_energy_previous_day_rates
98101
- platform: state
99102
entity_id: !input octopus_energy_current_day_rates
100103
- platform: state
@@ -110,9 +113,6 @@ action:
110113
- action: target_timeframes.update_target_timeframe_data_source
111114
data: >
112115
{%- set all_oe_rates = [] -%}
113-
{%- if state_attr(octopus_energy_previous_day_rates, 'rates') != None -%}
114-
{%- set all_oe_rates = all_oe_rates + state_attr(octopus_energy_previous_day_rates, 'rates') -%}
115-
{%- endif -%}
116116
{%- if state_attr(octopus_energy_current_day_rates, 'rates') != None -%}
117117
{%- set all_oe_rates = all_oe_rates + state_attr(octopus_energy_current_day_rates, 'rates') -%}
118118
{%- endif -%}
@@ -132,11 +132,16 @@ action:
132132
{%- set all_ci_rates = all_ci_rates + state_attr(carbon_intensity_next_day_rates, 'rates') -%}
133133
{%- endif -%}
134134
135+
{%- set min_rate = all_oe_rates | map(attribute='value_inc_vat') | min -%}
136+
{%- set max_rate = all_oe_rates | map(attribute='value_inc_vat') | max -%}
137+
{%- set min_carbon = all_ci_rates | map(attribute='intensity_forecast') | min -%}
138+
{%- set max_carbon = all_ci_rates | map(attribute='intensity_forecast') | max -%}
139+
135140
{%- set data = namespace(new_rates=[]) -%}
136141
{%- for rate in all_oe_rates -%}
137142
{%- set start = rate["start"] | as_timestamp | timestamp_utc -%}
138143
{%- set end = rate["end"] | as_timestamp | timestamp_utc -%}
139-
{%- set value = rate["value_inc_vat"] | float -%}
144+
{%- set value = 1 - ((rate["value_inc_vat"] | float - min_rate) / (max_rate - min_rate) * octopus_energy_weighting) -%}
140145
141146
{%- set free_namespace = namespace(is_free=False) -%}
142147
{%- for free_session in free_electricity_rates -%}
@@ -158,7 +163,7 @@ action:
158163
159164
{%- set metadata = { "rate": rate["value_inc_vat"], "is_capped": rate["is_capped"] } -%}
160165
{%- if carbon_intensity_namespace.rate -%}
161-
{%- set value = value * (carbon_intensity_namespace.rate["intensity_forecast"] | float) -%}
166+
{%- set value = value + (1 - ((carbon_intensity_namespace.rate["intensity_forecast"] | float - min_carbon) / (max_rate - min_carbon) * carbon_intensity_weighting)) -%}
162167
{%- set metadata = dict(metadata.items(), carbon_intensity=carbon_intensity_namespace.rate["intensity_forecast"] | float) -%}
163168
{%- endif -%}
164169

0 commit comments

Comments
 (0)