Giter Club home page Giter Club logo

Comments (5)

PatrikTrestik avatar PatrikTrestik commented on June 9, 2024 1

Ja mám v plánu pár vylepšení, ale nemám na to čas ☹️
Snad v příštím týdnu.
Na některé věci jde udělat šablonu. Na něco bude potřeba změna kódu.

from homeassistant_cz_energy_spot_prices.

PatrikTrestik avatar PatrikTrestik commented on June 9, 2024

Ano, chápete to správně. Není ale těžké vyrobit senzor který najde blok X nejlevnějších hodin.

Řeším pro sebe výpočet se zapojením distribučních cen a HDO času. To bude trochu složitější. Pokud z toho něco bude pošlu sem výsledek.

from homeassistant_cz_energy_spot_prices.

lukasde avatar lukasde commented on June 9, 2024

Me to furt nejak nedochazi:( Muzu poprosit o vetsi nakopnuti, jak najit napr. 5 nejlevnejsich hodin v intervalu 0:00 - 12:00?
Diky moc

from homeassistant_cz_energy_spot_prices.

shaman79 avatar shaman79 commented on June 9, 2024

Tohle jsem řešil nedávno, zde je verze pro 2 nejlevnější hodiny v intervalu.

Mělo by to jít snadno upravit pro libovolný počet hodin úpravou této podmínky {% if min.min_hours|length < 2 %}

- sensor:
    - name: "two cheapest hours in interval"
      unique_id: two_cheapest_hours_in_interval
      state: > 
        {# Define your intervals here as tuples (hour starting the interval, hour ending the interval (excluded)) #}
        {% set intervals = [
          (0, 8),
          (8, 18),
          (18, 24),
        ] %}

        {# We need to use namespace so we can write into it in the inner cycle #}
        {% set min = namespace(min_hours=[], dt=None, cheapest_hours=[]) %}
        {% set cheapest_hours = [] %}
        {% set min_hours = [] %}

        {% for interval in intervals %}
        {# Initialize a list to store the two cheapest hours for the current interval #}
          {% set min.min_hours = [] %}

          {# Go through all the hours in the interval (end excluded) and find the two hours with the lowest prices #}
          {% for i in range(interval[0], interval[1]) %}
            {# Get datetime of the current hour in the current interval #}
            {% set hour_dt = now().replace(hour=i, minute=0, second=0, microsecond=0) %}

            {# Get value for that hour #}
            {% set value = states.sensor.current_spot_electricity_hour_order.attributes.get(hour_dt.isoformat()) %}

            {# Skip if not found #}
            {% if value is not defined %}
              {% break %}
            {% endif %}

            {# value is tuple (order, price), we'll use the price #}
            {% set price = value[1] %}
    
            {# Add the hour to the list of two cheapest hours if it has a lower price #}
            {% if min.min_hours|length < 2 %}
              {% set min.min_hours = min.min_hours + [(hour_dt.hour, price)] %}
            {% else %}
              {% set min.min_hours = min.min_hours|sort(attribute=1) %}
              {% if price < min.min_hours[1][1] %}
                {% set min.min_hours = min.min_hours[:1] + [(hour_dt.hour, price)] %}
              {% endif %}
            {% endif %}
    
          {% endfor %}

          {# Store two cheapest hours in the overall list #}
          {% set min.cheapest_hours = min.cheapest_hours + min.min_hours %}
        {% endfor %}

        {{ now().hour in min.cheapest_hours | map(attribute=0) }}

from homeassistant_cz_energy_spot_prices.

johny-mnemonic avatar johny-mnemonic commented on June 9, 2024

@rnovacek je tu už několik vytvořených issue na téma hledání jedné nebo více hodin v nějakém intervalu. Na kratší intervaly, které nejdou přes půlnoc se dá většinou použít ta vzorová šablona pro jednu hodinu, případně pro víc hodin v komentáři nahoře.
Bohužel to má nevýhodu v tom, že to nejde používat moc dynamicky (např, v automatizaci, kde si spočítám kolik hodin mi bude trvat nabití auta, nebo nahřátí bojleru a hledám nejlevnější tak velký interval) a také to nejde používat přes půlnoc, kdy definice intervalu nefunguje.

Nešlo by vygenerovat něco jako current_spot_electricity_hour_order pro daný interval (typicky noc)?

from homeassistant_cz_energy_spot_prices.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.