Skip to content

Commit 3276a7f

Browse files
committed
blueprint: Updated blueprints to be more resilient to missing data
1 parent ae27756 commit 3276a7f

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

_docs/blueprints/target_timeframes_carbon_intensity.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,13 @@ condition: []
4949
action:
5050
- action: target_timeframes.update_target_timeframe_data_source
5151
data: >
52-
{% set all_rates = state_attr(carbon_intensity_current_day_rates, 'rates') + state_attr(carbon_intensity_next_day_rates, 'rates') %}
52+
{% set all_rates = [] %}
53+
{% if state_attr(carbon_intensity_current_day_rates, 'rates') != None %}
54+
{% set all_rates = all_rates + state_attr(carbon_intensity_current_day_rates, 'rates') %}
55+
{% endif %}
56+
{% if state_attr(carbon_intensity_next_day_rates, 'rates') != None %}
57+
{% set all_rates = all_rates + state_attr(carbon_intensity_next_day_rates, 'rates') %}
58+
{% endif %}
5359
{% set data = namespace(new_rates=[]) %}
5460
{% for rate in all_rates %}
5561
{% set start = rate["from"] | as_timestamp | timestamp_utc %}

_docs/blueprints/target_timeframes_octopus_energy.yaml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,16 @@ condition: []
6060
action:
6161
- action: target_timeframes.update_target_timeframe_data_source
6262
data: >
63-
{% set all_rates = state_attr(octopus_energy_previous_day_rates, 'rates') + state_attr(octopus_energy_current_day_rates, 'rates') + state_attr(octopus_energy_next_day_rates, 'rates') %}
63+
{% set all_rates = [] %}
64+
{% if state_attr(octopus_energy_previous_day_rates, 'rates') != None %}
65+
{% set all_rates = all_rates + state_attr(octopus_energy_previous_day_rates, 'rates') %}
66+
{% endif %}
67+
{% if state_attr(octopus_energy_current_day_rates, 'rates') != None %}
68+
{% set all_rates = all_rates + state_attr(octopus_energy_current_day_rates, 'rates') %}
69+
{% endif %}
70+
{% if state_attr(octopus_energy_next_day_rates, 'rates') != None %}
71+
{% set all_rates = all_rates + state_attr(octopus_energy_next_day_rates, 'rates') %}
72+
{% endif %}
6473
{% set data = namespace(new_rates=[]) %}
6574
{% for rate in all_rates %}
6675
{% set start = rate["start"] | as_timestamp | timestamp_utc %}

0 commit comments

Comments
 (0)