Skeem

Nordpool best time

Aug 20th, 2022 (edited)
1,240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 1.97 KB | None | 0 0
  1. - platform: template
  2.   sensors:
  3.     elpris_tomorrow_available:
  4.       friendly_name: "Elpris tomorrow available"
  5.       value_template: >-
  6.             {% set streng = state_attr('sensor.nordpool_kwh_dk2_dkk_3_095_025', 'tomorrow') %}
  7.             {{ iif (((streng[0] is none) or (streng|length ==0)) ,false,true,false) }}
  8. - platform: template
  9.   sensors:
  10.     opladningstidspunkt:
  11.       friendly_name: 'Opladningstidspunkt'
  12.       value_template: >-
  13.         {% set list = states.sensor.nordpool_kwh_dk2_dkk_3_095_025.attributes.today %}
  14.         {% set list2 = states.sensor.nordpool_kwh_dk2_dkk_3_095_025.attributes.tomorrow %}
  15.         {% if elpris_tomorrow_available %}
  16.           {% set list = list + list2  %}
  17.         {% endif  %}
  18.         {% set len = list|length  %}
  19.         {% set list = list[now().hour:len] %}
  20.         {% set numberoflow = states.input_number.nordpool_numberoflow.state | int %}
  21.         {% set threshold = states.input_number.cleversats.state | float %}
  22.         {% set ns = namespace(count = 0) %}
  23.         {% set ns_sh = namespace(starthour = -1) %}
  24.         {% set ns_found = namespace(found = false) %}
  25.         {% for pris in list %}
  26.           {% if (pris<=threshold) %}
  27.              {% if (ns_sh.starthour<0): %}
  28.                {% set ns_sh.starthour = loop.index -1 %}
  29.              {% endif %}
  30.              {% set ns.count = ns.count + 1 %}
  31.              {% if (ns.count==numberoflow): %}
  32.                {% set ns_found.found = true %}
  33.              {% endif %}  
  34.           {% else %}
  35.             {% if (ns.count < numberoflow) and not ns_found.found %}
  36.               {% set ns_sh.starthour = -1 %}
  37.             {% endif %}  
  38.             {% set ns.count = 0 %}
  39.           {% endif %}
  40.         {% endfor %}
  41.         {% if (ns_found.found): %}
  42.           {% set result = now().replace(hour=now().hour,minute=0,second=0)+timedelta(hours = ns_sh.starthour) %}
  43.           {{ result.strftime("%Y-%m-%d %H:%M") }}
  44.         {% else %}
  45.           -1
  46.         {% endif %}
  47.  
  48.  
Advertisement
Add Comment
Please, Sign In to add comment