{"id":2543,"date":"2023-11-12T14:55:41","date_gmt":"2023-11-12T14:55:41","guid":{"rendered":"https:\/\/www.creatingsmarthome.com\/?p=2543"},"modified":"2023-12-03T10:13:25","modified_gmt":"2023-12-03T10:13:25","slug":"home-assistant-advanced-nord-pool-cheapest-hours-automation-non-sequential","status":"publish","type":"post","link":"https:\/\/www.creatingsmarthome.com\/index.php\/2023\/11\/12\/home-assistant-advanced-nord-pool-cheapest-hours-automation-non-sequential\/","title":{"rendered":"Home Assistant: Advanced Nord Pool Cheapest Hours automation (non-sequential)"},"content":{"rendered":"\n<p>I guess there are people that have been waiting for this extension of cheapest hours automation for a while now and it&#8217;s finally here: <strong>non-sequential version cheapest hours package<\/strong>! <\/p>\n\n\n\n<p>This article is continuation to <a href=\"https:\/\/www.creatingsmarthome.com\/index.php\/2023\/04\/12\/home-assistant-advanced-nord-pool-cheapest-hours-with-local-calendar-support\/\" data-type=\"link\" data-id=\"https:\/\/www.creatingsmarthome.com\/index.php\/2023\/04\/12\/home-assistant-advanced-nord-pool-cheapest-hours-with-local-calendar-support\/\">Home Assistant: Sequential cheapest hours automation<\/a> so I&#8217;d really suggest to read that one first. This article also points to it in couple of sections.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Features of the package<\/h2>\n\n\n\n<p>The automation I&#8217;m presenting here finds the cheapest hours from Nord Pool sensor and creates local calendar entries on cheapest hours. This Home Assistant package also acts upon cheapest hours calendar events and performs action when cheapest hours event is started. And this is the <strong>non-sequential<\/strong> version that can create multiple entries on a day! <\/p>\n\n\n\n<p>Here\u2019s the list this automation package implements (<strong>feature list<\/strong>):<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Calculate number of cheapest hours when Nord Pool spot prices are received<\/li>\n\n\n\n<li>Support for two days (today + tomorrow)<\/li>\n\n\n\n<li>Rather easy to configure<\/li>\n\n\n\n<li>Once prices are received from the Nord Pool, calendar events are created<\/li>\n\n\n\n<li>Possible sequential hours are merged with each other<\/li>\n\n\n\n<li>Devices(s) will start when \u2018cheapest hours\u2019 -calendar event begins<\/li>\n\n\n\n<li>Device(s) will stop when \u2018cheapest hours\u2019 -calendar event is over<\/li>\n\n\n\n<li>If prices are not fetched by 23:15, create a static cheapest hours event (sequential) from configured start time and end after number of hours specified. This will provide us a failsafe that no critical devices are being left out of electricity (e.g. water boiler).<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Pre-requisites<\/h2>\n\n\n\n<p><strong>This is where I&#8217;m going to refer previous <a href=\"https:\/\/www.creatingsmarthome.com\/index.php\/2023\/04\/12\/home-assistant-advanced-nord-pool-cheapest-hours-with-local-calendar-support\/\" data-type=\"link\" data-id=\"https:\/\/www.creatingsmarthome.com\/index.php\/2023\/04\/12\/home-assistant-advanced-nord-pool-cheapest-hours-with-local-calendar-support\/\">cheapest hours articles<\/a>.<\/strong><\/p>\n\n\n\n<p>If you have not used the advanced cheapest hours package earlier, you should start by <a href=\"https:\/\/www.creatingsmarthome.com\/index.php\/2023\/04\/12\/home-assistant-advanced-nord-pool-cheapest-hours-with-local-calendar-support\/#setting-up-the-local-calendar\" data-type=\"link\" data-id=\"https:\/\/www.creatingsmarthome.com\/index.php\/2023\/04\/12\/home-assistant-advanced-nord-pool-cheapest-hours-with-local-calendar-support\/#setting-up-the-local-calendar\">creating a local calendar for Home Assistant<\/a> and <a href=\"https:\/\/www.creatingsmarthome.com\/index.php\/2022\/09\/17\/home-assistant-nord-pool-spot-prices-and-how-to-automate-devices-for-cheapest-hours\/#Integrating-Nord-Pool-to-the-Home-Assistant\" data-type=\"link\" data-id=\"https:\/\/www.creatingsmarthome.com\/index.php\/2022\/09\/17\/home-assistant-nord-pool-spot-prices-and-how-to-automate-devices-for-cheapest-hours\/#Integrating-Nord-Pool-to-the-Home-Assistant\">integrating Nord Pool into Home Assistant<\/a>.<\/p>\n\n\n\n<p>Once these steps are done, continue forward. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Setting up the package<\/h2>\n\n\n\n<p>Advanced cheapest hours package can be found from my&nbsp;<a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/kotope\/ha_nordpool_cheapest_hours\/blob\/main\/advanced_cheapest_hours.yaml\" target=\"_blank\">Cheapest hours <\/a><a href=\"https:\/\/github.com\/kotope\/ha_nordpool_cheapest_hours\/blob\/main\/advanced_cheapest_hours_non_sequential.yaml\" target=\"_blank\" rel=\"noreferrer noopener\">GitHub<\/a><a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/kotope\/ha_nordpool_cheapest_hours\/blob\/main\/advanced_cheapest_hours.yaml\" target=\"_blank\"> page<\/a>, so download it and copy it on your Home Assistant \u2018<em>config<\/em>\u2018 folder.<\/p>\n\n\n\n<p>After copied, find the&nbsp;<em>homeassistant:<\/em>&nbsp;-block from your&nbsp;<em>configurations.yaml<\/em>&nbsp;file and add the package include on it. If you don\u2019t have&nbsp;<em>homeassistant:<\/em>&nbsp;-block, just copy the whole block in any root level of&nbsp;<em>configuration.yaml<\/em>&nbsp;file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>homeassistant:\n  packages:\n    cheapest_hours_non_sequential: !include advanced_cheapest_hours_non_sequential.yaml<\/code><\/pre>\n\n\n\n<p>More details about Home Assistant packages can be found from&nbsp;<a href=\"https:\/\/www.home-assistant.io\/docs\/configuration\/packages\/\">here<\/a>. Or if in doubt, leave a comment on the comment field and I\u2019ll try to help you out \ud83d\ude42<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Configuration<\/h2>\n\n\n\n<p>As usual in my creations, I&#8217;ve added #CHANGE-ME comments to places where you need to configure your own data. In the main template sensor configurations there are following entries that needs configuration:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Amount of cheapest hours in search\nnumber_of_hours: 4\n# Search starting hour\nfirst_hour: 21\n# Search ending hour\nlast_hour: 08\n# Is the first_hour today (true \/ false). If false, first_hour needs to be before last_hour.\nstarting_today: true\n# Nord pool sensor id. Check it ouf from your integrations page!\nsensor: sensor.nordpool_kwh_fi_eur_3_10_024 \n# If nordpool fetch fails, starting time to make the calendar entry\nfail_safe_starting: '00:00' <\/code><\/pre>\n\n\n\n<p>Along with the main configuration, there are <strong>few several places to make changes in the code<\/strong>. Most of them are &#8216;<em>sensorId<\/em>&#8216; values that should refer to the template sensor defined earlier. No need to change these <strong>unless you are actually making multiple separate automations<\/strong> or just want to change the names.<\/p>\n\n\n\n<p>However, there&#8217;s one <strong>crucial thing to change<\/strong>, the actions what actually need to be done when the cheapest hours starts. So, do what-ever-you-like at this point:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>then:\n# CHANGE-ME: Actions to do when cheap hour starts\n  - service: input_boolean.turn_on\n    entity_id: input_boolean.test_switch\nelse:\n# CHANGE-ME: Actions to do when cheap hour ends\n  - service: input_boolean.turn_off\n    entity_id: input_boolean.test_switch<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Creating multiple automations<\/h2>\n\n\n\n<p>Ok, so you might want to have multiple automations for different amount of hours or different configurations? At that point, you need to do these steps:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Make a copy the template sensor<\/strong> at the beginning and set unique_id + name to something suitable<\/li>\n\n\n\n<li><strong>Create copy of first automation<\/strong> (<em>cheapest_hours_non_sequential_calendar_trigger<\/em>) and rename + make proper actions to do what-ever-you-like. Also change the sensorId to refer your newly created template sensor.<\/li>\n\n\n\n<li><strong>Change<\/strong> <em>cheapest_hours_non_sequential_set_sequence<\/em> automation to contain another sensorId (name as you like) and <strong>create another <em>action<\/em><\/strong> to call <em>script.cheapest_hours_create_multi_calendar<\/em> with this new data<\/li>\n\n\n\n<li><strong>Change<\/strong> <em>cheapest_hours_non_sequential_failsafe<\/em> to contain another sensorId as in previous step and <strong>create another failsafe action<\/strong> to call <em>script.cheapest_hours_create_multi_calendar<\/em> with this new data<\/li>\n<\/ol>\n\n\n\n<p>That&#8217;s it, you should be able to create multiple action by doing those steps. I will be adding an example to the GitHub with multiple entries some rainy day.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What&#8217;s coming up next&#8230;<\/h2>\n\n\n\n<p>One step closer to save energy. However, using configuring multiple entries and automations can be time consuming and so far my cheapest hours automations differs from each others more or less. I&#8217;m planning to implement a v2 version of all of these that contain some common code so that those scripts + helpers could be used between each other. <\/p>\n\n\n\n<p>And for more, a web configuration utility is on my TODO list as well. Wouldn&#8217;t hold my breath for it soon though, it might take some time to implement a full web app for building these with my spare time.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n<div style=\"border: 3px dashed #abb8c3; border-radius: 0%; background-color: inherit; \" class=\"ub-styled-box ub-bordered-box wp-block-ub-styled-box\" id=\"ub-styled-box-f05b34aa-b681-4a48-a8eb-832df3780c33\">\n<p id=\"ub-styled-box-bordered-content-\"><h5 class=\"wp-block-heading has-text-align-center\">Did you find this guide helpful? You can keep the blog going by bidding me a coffee!<\/h5>\r\n<center>\r\n<script type=\"text\/javascript\" src=\"https:\/\/cdnjs.buymeacoffee.com\/1.0.0\/button.prod.min.js\" data-name=\"bmc-button\" data-slug=\"tokorhon\" data-color=\"#FFDD00\" data-emoji=\"\"  data-font=\"Cookie\" data-text=\"Buy me a coffee\" data-outline-color=\"#000000\" data-font-color=\"#000000\" data-coffee-color=\"#ffffff\" ><\/script>\r\n<\/center><\/p>\n\n\n<\/div>","protected":false},"excerpt":{"rendered":"<p>I guess there are people that have been waiting for this extension of cheapest hours automation for a while now and it&#8217;s finally here: non-sequential&hellip;<\/p>\n","protected":false},"author":1,"featured_media":2569,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[100],"tags":[105,273,269,224,267,268,106,78,7,218,266,8,339,272],"class_list":["post-2543","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-home-assistant","tag-automation","tag-car-charging","tag-cheap-prices","tag-cheapest-hours","tag-energy","tag-energy-price","tag-energy-saving","tag-heating","tag-home-assistant","tag-nord-pool","tag-nordpool","tag-smart-home","tag-spot-prices","tag-water-boiler","has-post-thumbnail-archive"],"acf":[],"featured_image_src":"https:\/\/www.creatingsmarthome.com\/wp-content\/uploads\/2023\/11\/cheapest_hours_energy_non_sequential-1.png","author_info":{"display_name":"Toni","author_link":"https:\/\/www.creatingsmarthome.com\/index.php\/author\/topsy\/"},"_links":{"self":[{"href":"https:\/\/www.creatingsmarthome.com\/index.php\/wp-json\/wp\/v2\/posts\/2543","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.creatingsmarthome.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.creatingsmarthome.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.creatingsmarthome.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.creatingsmarthome.com\/index.php\/wp-json\/wp\/v2\/comments?post=2543"}],"version-history":[{"count":28,"href":"https:\/\/www.creatingsmarthome.com\/index.php\/wp-json\/wp\/v2\/posts\/2543\/revisions"}],"predecessor-version":[{"id":2587,"href":"https:\/\/www.creatingsmarthome.com\/index.php\/wp-json\/wp\/v2\/posts\/2543\/revisions\/2587"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.creatingsmarthome.com\/index.php\/wp-json\/wp\/v2\/media\/2569"}],"wp:attachment":[{"href":"https:\/\/www.creatingsmarthome.com\/index.php\/wp-json\/wp\/v2\/media?parent=2543"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.creatingsmarthome.com\/index.php\/wp-json\/wp\/v2\/categories?post=2543"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.creatingsmarthome.com\/index.php\/wp-json\/wp\/v2\/tags?post=2543"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}