@celodnb
I had a closer look at the code you provided, and read your post a bit better.
This should give the same 7:00 timestamp (as a full datetime isoformat string) as you already had. Note that I have it end at “10:00”. My macro will take the end provided as the end of the 3 hour period, so if you provide end='07:00' the start of the 3 hour period will be 04:00 latest
Hi, really sorry for the late reply! Thanks for your efforts, but so far I’ve not got it working (but I also haven’t spent much time on it so far). Time’s limited these days, so right now I’m prioritising a couple of other HA projects when time between kids allows
I installed it thru HACS (Experimental Features enabled) and can see the jinja file in /config/custom_templates/cheapest_energy_hours.jinja.
I reloaded the Home Assistant Core Integration: Reload custom Jinja2 templates service call.
The integration I am using to pull the energy data from is EntsoE;
I use sensor “sensor.dynamische_prijzen_elektriciteit_average_electricity_price_today”; attribute is “prices_today”.
Attributes for above sensor look like this:
state_class: measurement
prices_today:
I am using the energy provider Tibber that provides the prices like this (see picture).
Is there a way to use the macro for this sensor format as well? If I try to apply the macro it always complains “UndefinedError: ‘h’ is undefined”. Any thoughts here that could help?
The macro expects a datetime (string) with the time the price is valid. I could add support for the list you now have, assuming the first item is the price at midnight.
Don’t know when I will find some time for that. You could also create a template sensor to transform your data to the expected format
It seems that I used a wrong macro logic. With
“{{ cheapest_energy_hours(‘sensor.tibber_prices_for_macro’, attr_today=‘today’, hours=1, lowest=True, mode=‘max’) }}”
it worked now. Many Thanks
Yes, I wanted to say you probably need to provide the attributes or keys. But I’ll look into it to make prevent this error and return a more informative error message
I have added a new version, 5.1.0 which now supports the data as provided by Tibber without the need for a template sensor.
v5.1.0
IMPROVEMENTS
This version adds support for data sources which don’t provide the date and time in the list with prices. 2 new parameters are added: datetime_in_data (defaults to true) and data_minutes (defaults to 60, only used when datetime_in_data is set to false). More information can be found in the documentation
Hi TheFes and thanks a lot for a great job. I have both “energi_data_service” and “nordpool” installed. I need a solution for battery charge when low price. How can I make sensors for cheapest and most expensive hours for night and day (i.e. 22:00 - 06:00 and 06:00 - 22:00). Period should be 3 or 4 hours?