Coder Social home page Coder Social logo

Afternoon rank about spotprices2ha HOT 4 OPEN

t3m3z avatar t3m3z commented on August 23, 2024
Afternoon rank

from spotprices2ha.

Comments (4)

T3m3z avatar T3m3z commented on August 23, 2024

Yes, your use case seems to reasonable.

Maybe something like below would suite your needs? That could be used as an automation condition to decide whether to turn on/off heating. You give start time, stop time and desired "rank" X. The code searches for Xth cheapest hour during the desired period and stores the price of that hour to variable "limit". And finally the code checks whether we are in currently in the desired time period and whether the current electricity price is lower than the limit found.

This way you don't need to calculate ranks for each hour and store the results of that. Maybe not the most elegant solution but this should give you needed tools to fulfill your use case. Please test this thoroughly as I just wrote the code quite quickly as an starting point for you.

{% set start = today_at("12:00") %}
{% set stop = start + timedelta(hours=6) %}
{% set rank = 3  %}

{% set limit = (state_attr('sensor.shf_data', 'data') | selectattr("Timestamp", "ge", start | as_timestamp) | selectattr("Timestamp", "lt", stop | as_timestamp) | sort(attribute="TotalPrice"))[rank]["TotalPrice"] %}

{{ now() > start and now() < stop and states('sensor.shf_electricity_price_now') | float < limit }}

image

from spotprices2ha.

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.