Skip to content

Jinja template to extract highest forecast price #8

Answered by micarex
micarex asked this question in Q&A
Discussion options

You must be logged in to vote

Figured it out. Posting in case useful to others

{%- set ns = namespace(highval={}) %}
{%- for intervals in states.sensor.amber_35_general_forecast.attributes["forecasts"] %}
{%- if loop.index0==0 %}
{%- set ns.highval=intervals["per_kwh"] | float %}
{%- endif %}
{%- if intervals['per_kwh'] | float > ns.highval | float %}
{%- set ns.highval=intervals["per_kwh"] | float %}
{%- endif %}
{%- endfor %}
{{ ns.highval }}

Sample data*
forecasts:

  • duration: 30
    nem_date: '2021-08-14T22:30:00+10:00'
    per_kwh: 22
    spot_per_kwh: 8
    start_time: '2021-08-14T12:00:01+00:00'
    end_time: '2021-08-14T12:30:00+00:00'
    renewables: 21
    spike_status: none
    range_min: 4.68735
    range_max: 31.12405
  • duration: 30
    nem_date: …

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by micarex
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant