Guest User

Untitled

a guest
Jan 17th, 2023
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.03 KB | Source Code | 0 0
  1. today_ranks: >
  2. {% set handled = namespace(list=[]) %}
  3. {% set break = namespace(found=0) %}
  4. {% set rank = namespace(slot=0) %}
  5. {% set time = namespace(slot=0) %}
  6. {% set output = namespace(value=[]) %}
  7. {% for price in state_attr("sensor.shf_electricity_price_now", "today_prices") %}
  8. {% set time.slot = loop.index0 %}
  9. {% for price2 in state_attr("sensor.shf_electricity_price_now", "today_prices")|sort %}
  10. {% if price==price2 and break.found==0 %}
  11. {% set rank.slot = loop.index0 %}
  12. {% for x in handled.list %}
  13. {% if rank.slot==handled.list[loop.index0] %}
  14. {% set break.found=2 %}
  15. {% endif %}
  16. {% endfor %}
  17. {% if break.found==0 %}
  18. {% set output.value = output.value + [loop.index] %}
  19. {% set handled.list = handled.list + [rank.slot] %}
  20. {% set break.found=1 %}
  21. {% elif break.found==2 %}
  22. {% set break.found=0 %}
  23. {% endif %}
  24. {% endif %}
  25. {% endfor %}
  26. {% set break.found=0 %}
  27. {% endfor %}
  28. {{output.value}}
  29. tomorrow_ranks: >
  30. {% set handled = namespace(list=[]) %}
  31. {% set break = namespace(found=0) %}
  32. {% set rank = namespace(slot=0) %}
  33. {% set time = namespace(slot=0) %}
  34. {% set output = namespace(value=[]) %}
  35. {% for price in state_attr("sensor.shf_electricity_price_now", "tomorrow_prices") %}
  36. {% set time.slot = loop.index0 %}
  37. {% for price2 in state_attr("sensor.shf_electricity_price_now", "tomorrow_prices")|sort %}
  38. {% if price==price2 and break.found==0 %}
  39. {% set rank.slot = loop.index0 %}
  40. {% for x in handled.list %}
  41. {% if rank.slot==handled.list[loop.index0] %}
  42. {% set break.found=2 %}
  43. {% endif %}
  44. {% endfor %}
  45. {% if break.found==0 %}
  46. {% set output.value = output.value + [loop.index] %}
  47. {% set handled.list = handled.list + [rank.slot] %}
  48. {% set break.found=1 %}
  49. {% elif break.found==2 %}
  50. {% set break.found=0 %}
  51. {% endif %}
  52. {% endif %}
  53. {% endfor %}
  54. {% set break.found=0 %}
  55. {% endfor %}
  56. {{output.value}}
Advertisement
Add Comment
Please, Sign In to add comment