Pull cheapest electricity price for template sensor - Solar

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

1 Like

thanks for your work, this is a really helpful macro for those new hourly price power suppliers

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

:sparkles: 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

What’s Changed

Full Changelog: Comparing v5.0.3...v5.1.0 · TheFes/cheapest-energy-hours · GitHub

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?

There are examples in the documentation.
Can you show what you already tried?

I have tested this template:


I have got only the value of the chepest energy hour not a perion when these hourse are. And I have maked a sensor:
image

use mode='start' (which is the default) to get the start date and time of that period

Got this:


The cheapest hours start 02:00 and 1 houre ahead?

1hour is your timezone. It starts 1:00 zulu. In your timezone it is 2:00.
Start for 3 hours period at 2 o’clock

Thanks a lot. I need a sensor for the most expensive 3 hourse.

mode='start', cheapest=false

This is all explained in the documentation

Yes I see, but excuse me for my low programming understanding. Thanks for help. I will try make some automatisation.

I have tried to make a new sensor for macro from Nordpool. When I put this in the template editor it looks like that:


Is it correct?
Should it be placed in sensors.yaml?

Sorry, what are you trying to do here?

The sensors provided by the Nordpool custom integration already provide the data needed for the macro. There is no further template sensor required to use the macro if you use the Nordpool integration.

Regarding your question:

  • Your sensor is not outputting anything for the today attribute. It is only setting some variables
  • The code is in the modern template sensor format, and can’t be placed in sensor.yaml as it is using the template integration and not the sensor integration. The way you have it now it should be placed directly in your configuration.yaml. You could create a template.yaml and incldue it from your configuration.yaml. In that case you can paste it in there without the first line (with template:). I will be best to remove 2 spaces on each line as well, to avoid issues when you add more template entities.

Do you mean I can use Nordpool instead for energi_data service without any adjustment? Like this:
{{ cheapest_energy_hours(‘sensor.nordpool_kwh_se4_sek_2_00_0’, hours=3, end=‘10:00’, mode=‘max’) }}

Yes, you can use the nordpool sensor like that.

1 Like

Hi @TheFes , Great Macro you have created. Just started to play with it and use it to show the lowest and highest price of the day etc.
My Wife wants me to put on the display which hours she is “allowed” to do laundry :slight_smile: without it being to expensive. I noticed in the documentation about lists, how would I go and create a list of datetime, price values for the entire day to show when the price is below e.g 3.00.

Thanks in advance.

The macro is intended to find connected least expensive hours. If you want to display all hours below a certain price, you can just use the raw data from the attribute of your price sensor.