Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- - platform: template
- sensors:
- elpris_tomorrow_available:
- friendly_name: "Elpris tomorrow available"
- value_template: >-
- {% set streng = state_attr('sensor.nordpool_kwh_dk2_dkk_3_095_025', 'tomorrow') %}
- {{ iif (((streng[0] is none) or (streng|length ==0)) ,false,true,false) }}
- - platform: template
- sensors:
- opladningstidspunkt:
- friendly_name: 'Opladningstidspunkt'
- value_template: >-
- {% set list = states.sensor.nordpool_kwh_dk2_dkk_3_095_025.attributes.today %}
- {% set list2 = states.sensor.nordpool_kwh_dk2_dkk_3_095_025.attributes.tomorrow %}
- {% if elpris_tomorrow_available %}
- {% set list = list + list2 %}
- {% endif %}
- {% set len = list|length %}
- {% set list = list[now().hour:len] %}
- {% set numberoflow = states.input_number.nordpool_numberoflow.state | int %}
- {% set threshold = states.input_number.cleversats.state | float %}
- {% set ns = namespace(count = 0) %}
- {% set ns_sh = namespace(starthour = -1) %}
- {% set ns_found = namespace(found = false) %}
- {% for pris in list %}
- {% if (pris<=threshold) %}
- {% if (ns_sh.starthour<0): %}
- {% set ns_sh.starthour = loop.index -1 %}
- {% endif %}
- {% set ns.count = ns.count + 1 %}
- {% if (ns.count==numberoflow): %}
- {% set ns_found.found = true %}
- {% endif %}
- {% else %}
- {% if (ns.count < numberoflow) and not ns_found.found %}
- {% set ns_sh.starthour = -1 %}
- {% endif %}
- {% set ns.count = 0 %}
- {% endif %}
- {% endfor %}
- {% if (ns_found.found): %}
- {% set result = now().replace(hour=now().hour,minute=0,second=0)+timedelta(hours = ns_sh.starthour) %}
- {{ result.strftime("%Y-%m-%d %H:%M") }}
- {% else %}
- -1
- {% endif %}
Advertisement
Add Comment
Please, Sign In to add comment