Advertisement
JonasPed

Untitled

May 13th, 2022
1,557
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 1.66 KB | None | 0 0
  1. template:
  2.   - sensor:
  3.     - name: El billigste 3 timer
  4.       unit_of_measurement: DKK/kWh
  5.       device_class: timestamp
  6.       state: >
  7.        {%- set x = namespace(x = now().hour) %}
  8.         {%- set x.low_price = 99999 %}
  9.         {%- set x.prices = state_attr('sensor.nordpool_kwh_dk1_dkk_3_10_025', 'raw_today') + state_attr('sensor.nordpool_kwh_dk1_dkk_3_10_025', 'raw_tomorrow') %}
  10.         {%- for n in range(now().hour, (state_attr('sensor.nordpool_kwh_dk1_dkk_3_10_025', 'today') | length) + (state_attr('sensor.nordpool_kwh_dk1_dkk_3_10_025', 'tomorrow') | length)-2) %}
  11.           {%- set price = (x.prices[n].value + x.prices[n+1].value + x.prices[n+2].value) / 3 %}
  12.           {%- if price < x.low_price %}
  13.             {%- set x.low_price = price %}
  14.             {%- set x.x = n %}
  15.           {%- endif %}
  16.         {%- endfor %}
  17.         {{ x.prices[x.x].start.isoformat() }}
  18.       attributes:
  19.         price: >
  20.          {%- set x = namespace(x = now().hour) %}
  21.           {%- set x.low_price = 99999 %}
  22.           {%- set x.prices = state_attr('sensor.nordpool_kwh_dk1_dkk_3_10_025', 'raw_today') + state_attr('sensor.nordpool_kwh_dk1_dkk_3_10_025', 'raw_tomorrow') %}
  23.           {%- for n in range(now().hour, (state_attr('sensor.nordpool_kwh_dk1_dkk_3_10_025', 'today') | length) + (state_attr('sensor.nordpool_kwh_dk1_dkk_3_10_025', 'tomorrow') | length)-2) %}
  24.             {%- set price = (x.prices[n].value + x.prices[n+1].value + x.prices[n+2].value) / 3 %}
  25.             {%- if price < x.low_price %}
  26.               {%- set x.low_price = price %}
  27.               {%- set x.x = n %}
  28.             {%- endif %}
  29.           {%- endfor %}
  30.           {{ x.low_price | round(3) }}
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement