Skip to content

Latest commit

 

History

21 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

Smart-load-switching-with-Shelly - Spot price driven load control for the Nordic countries.

💡 Tip: With this Shelly script one can optimize his/her household energy efficiency with concentrating the consumption of a selected “dumb” device e.g. water heater to the cheapest hours within the day.

Warning:

Programming and home automation are cool things but playing with electricity is not. If you are not comfortable with at least the basics of electrical installations and safety measures, then hire a skilled professional! If you intend to install your Shelly device inside of a household appliance within your home e.g. to a water heater, then consult the manufacturer or manual first, consider the loss of warranty and make sure not to bypass any in-built protection like heat limiter, circuit breaker, etc. Last but not least at all, always consider the power rating of your shelly relay, current to be switched and your load type, and use a contactor and RC snubber if required!

How does the script work?

Basically, the script uses publicly available hourly energy prices (spot price) as a switching criteria. Since the spot price varies greatly throughout the year, e.g. usually prices in winter are higher than in summer, both absolute and relative prices are used as conditions for switching in the following way. Energy prices are fetched from Elprisetjustnu’s API once a day (https://www.elprisetjustnu.se/). If the Shelly relay runs in auto-mode (SW input is on) then the relay is activated when:

  • The actual price within the given hourly interval is lower than the lower price limit
  • The actual price is higher than the lower limit but lower than the higher one and the current hour is amongst the sorted “n” lowest hours of the day where “n” is an integer between 1 and 24

The relay switches off or stays off when:

  • The actual price is above the higher limit

Should the relay be deactivated or activated manually in auto-mode, then its state will be corrected in the next iteration (60 seconds) to follow the logic dictated by the parameters.

If the auto-mode is inactive, then the relay can still be operated manually from the Shelly APP of from the device’s web interface either manually or by using scenes. Scenes and manual modes can also be completely satisfactory for some, and in this case the manual operation and scenes can mutually override each-other when they are triggered by e.g. a price change or from the Shelly App. Keep in mind that using auto-mode and scenes simultaneously can lead to unintended behavior and unnecessary troubleshooting though! :) Furthermore, the above logic assumes such "dumb" devices or resistive loads where it does not matter if the selected cheapest hours are not necessarily consecutive, which may not be the case for e.g. washing machines. The prerequisite for configuring scenes is that the price information, (which is delivered by a virtual component defined in the script running in the Shelly device), is available in the Shelly App. This requires at least a gen.2 pro or a gen.3 device.

Upgrading "dumb" devices to smart ones also has other benefits beyond consumption control and monitoring, such as an increased level of comfort without the need for an initial investment in a more modern household appliance, which can often be a hard-to-sell decision. This was precisely the case with the heater below.

A simplified wiring diagram of a retrofitted dual-mode (heat-pump combined with heating element) water heater.

Circuit diagram

Implementing the script

It is possible to create a new script either in the web-gui of your device or in the Shelly application. Copy the whole code to the window, set the required parameters according to your preferences and save it. Make sure that you have set all the required parameters properly, as for instance electricity region is critical to correctly fetch the hourly prices of your region! Then, your script is ready to start. It may worth checking the logs after start, to make sure that everything works as expected. Don’t forget to enable auto-run either, otherwise the script will not start after a power failure!

If you are completely new to Shelly scripting then you can read more about that here: https://www.shelly.com/blogs/scripts-library

Script start Script stop Script log

If you intend to use virtual components too, then you need to extract the Authorization cloud key from the application first and copy it to your config parameters (post_url).

Auth key

(Attention: the key can only be extracted once, and every new attempt will result in a new key!) Then, the virtual component and a virtual group (virtual components are not visible without being assigned to a group) needs to be created from the web-gui or from the application. If you are successful, then prices (both momentary and the price of used electricity) will be visible in your Shelly application.

Other opportunities

As said before, virtual components make it possible to use scenes triggered by the price information. Basically, scenes can be interpreted as automations and contain the same building blocks as: triggers, conditions and actions. An example of two scenes (one for activating the relay and one for deactivation) can be found below. Make sure though not to mix scenes and auto-mode as they can lead to unintended relay activation or deactivation! If you are happy with just using scenes, because e.g., absolute price limits completely satisfy your needs, then the best choice probably is to not use the SW input of your relay at all. If you would like to learn more about scenes than you can do it here:

https://shelly.guide/app-webapp/scenes-automations/

Scenes Heater on Heater off

References

It would be unfair not to mention these sources where I got a lot of inspiration from and even some code snippets:

Live Elpris – Svenska – The unofficial Shelly guide

https://github.com/LeivoSepp/Smart-heating-management-with-Shelly/tree/v4.6

https://github.com/martinkangur/shelly/blob/main/nordpool-simple.js

https://github.com/ALLTERCO/shelly-script-examples

About

Spot price driven load control for the Nordic countries.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages