Code Monkey home page Code Monkey logo

Comments (10)

Hellowlol avatar Hellowlol commented on June 25, 2024 1

Yeah. All you need just a sensor that has a holiday attribut. The example i provided has dict of all holydays so you can format the datetime to a str and use a .get and check if the value is not None.

from nordpool.

Hellowlol avatar Hellowlol commented on June 25, 2024

The easiest way i can think is to check if utcnow and now is the same date. The integration patches now so it always in the context of the current hour. So if the day isnt the same its tomorrow.

from nordpool.

magnusoverli avatar magnusoverli commented on June 25, 2024

Does that mean that the additional cost template is evaluated per hour and takes date into account?

If that is the case I suppose my template should work as intended?

from nordpool.

magnusoverli avatar magnusoverli commented on June 25, 2024

Ah, no, it does not work.
To summarise… We receive prices for tomorrow at 13:00 here. This means that we need a way to check if tomorrow is a workday, which I currently am unable to see how is done. The workday status defines the level of taxes on electricity, so it is crucial to get a correct reading of the next day price level.

from nordpool.

magnusoverli avatar magnusoverli commented on June 25, 2024

Or does now() always relate to the hour being evaluated? If that is the case, could it work to compare as_timestamp(now()) | timestamp_custom("%F") against a list of known holidays?

from nordpool.

Hellowlol avatar Hellowlol commented on June 25, 2024

https://github.com/custom-components/nordpool#additional-costs

Yes, its patched so it always refer to the hour for the price.

from nordpool.

Hellowlol avatar Hellowlol commented on June 25, 2024

Instead if a static list of holydays you can use https://github.com/partofthething/next-holiday-sensor

from nordpool.

magnusoverli avatar magnusoverli commented on June 25, 2024

Oh, the list is not static, it is dynamically provided by the Holidays integration (https://github.com/bruxy70/Holidays). It seems it does much of the same as the one you suggest?

from nordpool.

Hellowlol avatar Hellowlol commented on June 25, 2024

Please post your solution so other can reuse it if they face the same issue.

from nordpool.

magnusoverli avatar magnusoverli commented on June 25, 2024

Sure! :-)
Within a "it works on my machine" scope, here is my template:

    {# January to March - Weekend and holiday taxes #}
    {% if (as_timestamp(now()) | timestamp_custom("%F")) in (state_attr('calendar.holidays','holidays') | list) and (now().month >= 1 and now().month <= 3) %}
      {% set el_taxes = 0.3558 %}
    {# April to December - Weekend and holiday taxes #}
    {% elif (as_timestamp(now()) | timestamp_custom("%F")) in (state_attr('calendar.holidays','holidays') | list) and (now().month >= 4) %}
      {% set el_taxes = 0.4393 %}
    {# January to March - Dyatime taxes #}
    {% elif (now().month >= 1 and now().month <= 3) and (now().hour >= 6 and now().hour <= 22) %}
      {% set el_taxes = 0.4738 %}
    {# January to March - Night taxes #}
    {% elif (now().month >= 1 and now().month <= 3) and (now().hour >= 23 or now().hour <= 5) %}
      {% set el_taxes = 0.3558 %}
    {# April to December - Day taxes #}
    {% elif (now().month >= 4) and (now().hour >= 6 and now().hour <= 22) %}
      {% set el_taxes = 0.5573 %}
    {# April to December - Night taxes #}
    {% elif (now().month >= 4) and (now().hour >= 23 or now().hour <= 5) %}
      {% set el_taxes = 0.4393 %}
    {% endif %}
    {% if current_price > 0.875 %}
        {% set subs = (current_price - 0.875) * 0.9 %}
        {% set additional_cost = el_taxes - subs %}
    {% elif current_price <= 0.875 %}
        {% set additional_cost = el_taxes %}
    {% endif %}
    {{ additional_cost | round(4) }}

I've also posted it in the HA community forums (HA Foums) and at Hjemmeautomasjon.no (Hjemmeautomasjon)

from nordpool.

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.