Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add nth hour attribute to sensor #358

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jjguti
Copy link

@jjguti jjguti commented Dec 6, 2023

Adds an attribute of the price "rank" of the current hour in the day. It makes it easy to write automations that get triggered on the i.e. "5 cheapest hours on the day", "the 3 most expensive hours of the day" and so on.

@stigvi
Copy link

stigvi commented Jan 24, 2024

This is a good idea. But still, how useful is it? If I want to charge my car on the N number of cheapest hours, I usually want to do that between 16:00 when I am home from work and to 07:00 next day. But my car won't be charged at all if the cheapest hours is before 16:00. And you make an artificial split at midnight even if prices are available the next day, too. So this sensor could indicate a lot of cheap hours before midnight, but there are even cheaper hours after midnight when the car is finished charging.

But I still think your idea is good, but I would want a configurable time frame so that I could find the cheapest hours between a time this day and a time next day.

@jjguti
Copy link
Author

jjguti commented Jan 24, 2024

Sure, I understand what you mean. My use case is slightly dfferent, I want to warm the house on the cheapest hours of the day and for that this sensor is very useful (since the house unlike the car is always there).

Sure we could go over midnight but that introduces some problems too, I think. For example what happens if the hours for the next day change the distribution of cheap hours? We could end up with many more or less cheap hours than we want.

My $0.02

@stigvi
Copy link

stigvi commented Jan 24, 2024

I liked your idea so much that I have already implemented it on my own system. I am not using this Nordpool integration much so it is implemented in pyscript. I append the tomorrow list to the end of the today list and then select the 24 prices from 14:00 to 14:00 next day. This is sorted and I set the value on a nth_cheapest_hour_1414 sensor.

And I do the same for a nth_cheapest_hour_1605 sensor, but select the prices from 16:00 to 05:00 before sorting.

Prices are read from Nordpool usually between 13:00 and 14:00 so I think my time period from 14:00 to 14:00 is less affected by price changes than a midnight to midnight sensor.

@sangvikh
Copy link
Contributor

sangvikh commented Oct 2, 2024

I do it differently for my water heater. I look at the cheapest n (4) hours the next 12 hours. It's not too hard to do with the list of prices today and tomorrow. So all the required information is in the nordpool integration already fortunately.

{% if is_state_attr("sensor.nordpool", "tomorrow_valid", True) %}
    {{ state_attr("sensor.nordpool", "current_price") <= ((state_attr("sensor.nordpool", "today")  + state_attr("sensor.nordpool", "tomorrow"))[now().hour : now().hour + 12] | sort)[4 - 1] }}
{% else %}
    {% if now().hour <= 12 %}
        {{ state_attr("sensor.nordpool", "current_price") <= ((state_attr("sensor.nordpool", "today"))[now().hour : now().hour + 12] | sort)[4 - 1] }}
    {% else %}
        {{ state_attr("sensor.nordpool", "current_price") <= ((state_attr("sensor.nordpool", "today"))[12:24] | sort)[4 - 1] }}
    {% endif %}
{% endif %}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants