cokeman0 / OpenEpaperElectricPriceTag

OpenEpaper Electric price tag with 12h graf
7 stars 1 forks source link

Overly complicated price calculations #2

Closed svenakela closed 8 months ago

svenakela commented 11 months ago

The calculations for max and min prices can be so much smaller in your Yaml files.

No need to recreate arrays and sort them, there are max and min functions in Python. I'll give you examples that you can copy/paste into the Home Assistant Template Editor to give you an idea.

{% set today = state_attr('sensor.nordpool_kwh_se3_sek_3_10_025', 'today') %}
{% set max_today = max(today) %}
{% set min_today = min(today) %}

MAX Today: {{ max_today }}
MIN Today: {{ min_today }}

If you want to concatenate the today and tomorrow values, merging lists in Python is just a '+' operation.

{% set today = state_attr('sensor.nordpool_kwh_se3_sek_3_10_025', 'today') %}
{% set tomorrow = state_attr('sensor.nordpool_kwh_se3_sek_3_10_025', 'tomorrow') %}
{% set max_ = max(today + tomorrow) %}
{% set min_ = min(today + tomorrow) %}

MAX coming days: {{ max_ }}
MIN coming days: {{ min_ }}
cokeman0 commented 11 months ago

Hi, yes, as I said, i'm not a programmer :-D but I also sometimes need to add fake info, to get the data needed.

e.g. on tomorrow, I'll add price og 9999.9999, so I can filter out when, there is no data yet, and also in the windows for graf high and graf low, where I reuse old prises, to get the data needed, but you a right, it's overly complicated, but it makes it so I understand it :-D

johansolve commented 8 months ago

I've added a pull request with refactoring of this and other improvements

cokeman0 commented 8 months ago

Thanks, for all the updates. :-)

I will update the EDS version with your fixes tomorrow... :-)