There are some devices at home that doesn’t matter if they run now or within two hours, right? For example, the Domestic Hot Water (DHW) electric heater, the air conditioning, the dishwasher, the washing machine… Furthermore, you might have some batteries, and you want them to discharge only during the most expensive hours.
This blueprint is ideal for all those who want to save money with the PVPC electricity pricing in Spain. It will automatically turn on the device for the specified number of hours and turn it back off for the rest of the day.
PVPC sensor : REQUIRED sensor created using the PVPC integration that contains the hourly price of the electricity.
How many hours? : REQUIRED. Number of hours per day you want the device to be on.
When to turn on the device? : REQUIRED. Choose whether you want to turn on your device during the cheapest or most expensive periods of the day.
DEVICES TO CONTROL:
Target devices: Device to turn on. If the device you would like to run cannot be passed to the homeassistant.turn_on service, you can create a script and call this script from the blueprint. It is not necessary to define a device here, but actions can also be called when the pricing conditions are met from the advanced features below.
Turn on the devices?: Do you want to turn on the devices when the pricing conditions are met?
Turn off the devices?: Do you want to turn off the devices when the pricing conditions are met?
ADDITIONAL PARAMETERS:
Time gap: Optional. Number of hours to wait before turning the device on again. IMPORTANT: This works only within the same day.
Exclude some hours: Optionally, select hours you want to exclude from the optimization.
ACTION ON SELECTED HOURS: Action to execute when the pricing conditions are met.
Actions before turning on the device.
Actions after turning on the device.
ACTION FOR THE REST OF THE DAY: Action to execute when the pricing conditions are NOT met.
Copy-paste the content from this link to a new file inside your configuration’s blueprint folder.
Changelog
2024-11-12: Moving to v2! Added the actions before and after turning on/off, and the switch to select whether to turn on or off. Also added the sections for inputs, which makes that the minimum HA version is now 2024.6. This will speed up the configuration on situations like the one mentioned by @iesgeber .
2024-09-22: Enhanced descriptions.
2024-05-20: Added the features to select whether to turn on the device during the most expensive or the cheapest hours. Also, added the possibility to exclude some hours from the calculation. Nice feature requests from @ramos45 and @afternet .
2023-12-03: Added the functionality to define a time gap between consecutive runs. Nice feature request from @dani-sh .
This is great, but after using it for a while, I have noticed that usually the 2 cheapest hours of the day are correlative, and this is not optimal for some uses (hot water is a clear example)
I was thinking that for these use cases we need to find the lowest average price of the X hours (2 hours for example) with a delay of at least Y hours between the sampled prices.
Unfortunately I don’t see how to code that into a blueprint. Hopefully you will!
Hi @dani-sh , I think it would be a great new feature! I’ll think about how to implement it robustly and I’ll do it! I’ll post it here when I get a solution (suggestions are accepted )
After 21h each day, read the attribute next best at, this is the ordered list of hours from cheapest to most expensive.
Pick first and save it
On_hours[0] = Next_best_at[0]
for each Next_best_at :
if abs(first - next) > Y # if there is a difference of more than Y hours (about 5 for a 100L water heater)
return next # finishes the process and returns the hour
This loop can be repeated for as many hours as one needs wrapped in a for loop.
I just updated the blueprint with your feature request. It is more or less what you proposed, but it runs every hour, as the automation is triggered on every change of the PVPC sensor. Then, it runs a loop to pick up hours of the day when the device should be on:
It selects the cheapest hour.
It “blocks” a number of hours before and after the selected hour, so that the device will be off before and after the cheapest hour. This number is defined in the new input field called “Time gap”. Setting it to 0 omits this step.
It starts again, selecting the cheapest hour from the remaining ones.
The loop runs as many times as it is necessary. For example, if I set up that the device has to turn on 5 times per day, it will run the loop 5 times.
I’ve tested the new code and I think it is working fine, but please tell me about any inconvenience.
Enjoy!
To get this new feature, you should just redownload the blueprint code!
Downloaded and set up again, although I had to delete the previous automation and instance of the blueprint. As easy to set up as the previous one, I’ll keep you posted.
Nice! Maybe the web interface is not ready to update/replace blueprints. I usually do it from the Samba share complement, which makes files accessible as a network shared folder. I access the folder from the IP address of my Home Assistant instance and the user-password configured by the complement. Then, I just look for the file containing the blueprint code and I replace it with the new version. This avoids having to configure the automations again. However, the result is the same.
This blueprint is an automation, so, to stop running it at nigh, you can set up a another automation that turns this one off between 23h and 8h, and turns if back on during the day.
Yes, actually i’m doing that. The problem is that if i set for example 4h in a day, if there are 4 or more cheap hours in the night, it doesn’t turn on in the day
Would it be possible for you to make a plan like this but just the opposite? I explain.
Activate something but just when the light is most expensive, or the most expensive selected hours of the day.
Sería posible que hicieras un plano como este pero justo al contrario? Me explico.
Accionar algo pero justo cuando la luz esté más cara, o las horas escogidas más caras del día.
Thanks for your comments! They were inspiring for me, and I decided to modify the blueprint to add these two new features:
I added a new selector to exclude some hours from the calculation. I’m not sure how it can be useful, but I’m sure that @ramos45 does
Also, there is a new selector to choose whether to turn on the device during the cheapest hours or during the most expensive hours. It’s nice to have batteries and use them when the electricity is expensive, like @afternet! I wish I had some…
To benefit from these updates, you just need to redownload the blueprint.
I’ve tested the new code and I think it is working fine, and it is backwards compatible, but please tell me about any inconvenience.
Mil gracias! No me ha ido al principio, pero he podido solucionarlo al rato de actualizar. Voy a testear bien ambas opciones con precio bajo y alto, y te cuento como ha ido.
Este PLANO es que es justo lo que estaba buscando desde hacía meses.
Thank you! It didn’t work for me at first, but I was able to solve it after updating. I’m going to test both options with low and high prices well, and I’ll tell you how it goes.
This PLAN is just what I was looking for for months.
Thank you very much for the new features! In my case, eliminating night hours is useful for using it with devices that make noise. I think more people will find it useful.
Crees que sería posible que en el mismo plano añadieras la posibilidad de mandar un mensaje de telegram? Del tipo, se ha puesto en marcha el lavavajillas o algo así, editable como es lógico.
Esa posibilidad dentro del plano sería fabuloso. Mil gracias.
Hello Marc again
Do you think it would be possible for you to add the possibility of sending a Telegram message to the same plan? Like, the dishwasher has started or something like that, editable of course.
That possibility within the plane would be fabulous. Thank you.
For your purpose, you should create an automation that sends a Telegram message when the dishwasher is turned on or when its consumption is above a certain threshold. This is not the aim of this blueprint.
Llevo ya unas semanas usando el BLUEPRINT y en general funciona bien, pero he detectado 2 fallos que se me repiten a diario.
La automatización en los precios baratos enciende y apaga la luz correctamente (la luz la uso para testear el funcionamiento). Pero en los precios caros nunca enciende la luz.
Descarto la configuración porque es la misma y en el caso del precio barato si va correctamente.
Cuando he probado a encender una tira led con un color determinado, gracias a las escenas (mando imagen), pues con las escenas no funciona bien. El sensor sería “scene.led_pvpc_rojo”
Gracias por todo
Marc, hello again!
I’ve been using the BLUEPRINT for a few weeks now and it generally works well, but I’ve detected 2 faults that I have every day.
The automation in the cheap prices turns the light on and off correctly (I use the light to test how it works). But in the expensive prices it never turns the light on.
I discard the configuration because it is the same and in the case of the cheap price it works correctly.
When I have tried to turn on a led strip with a certain color, thanks to the scenes (image control), well with the scenes it doesn’t work well. The sensor would be “scene.led_pvpc_red”