{"id":1172,"date":"2022-09-17T07:36:22","date_gmt":"2022-09-17T07:36:22","guid":{"rendered":"https:\/\/www.creatingsmarthome.com\/?p=1172"},"modified":"2023-11-12T08:19:34","modified_gmt":"2023-11-12T08:19:34","slug":"home-assistant-nord-pool-spot-prices-and-how-to-automate-devices-for-cheapest-hours","status":"publish","type":"post","link":"https:\/\/www.creatingsmarthome.com\/index.php\/2022\/09\/17\/home-assistant-nord-pool-spot-prices-and-how-to-automate-devices-for-cheapest-hours\/","title":{"rendered":"Home Assistant: Nord Pool Spot prices and how to automate devices for cheapest hours"},"content":{"rendered":"\n<p>Most of this information can already be found around the internet, but since I wanted to integrate one as well for my Home Assistant instance, why not to share the same with you?<\/p>\n\n\n\n<p>So, the energy prices have gone up by a mile. The best way to balance the energy bill is to schedule some devices to cheapest hours of the day.. those devices could be something like washing machines, water boilers or car charging? Most of the devices needs a specific timeframe to run so sequential cheap hours are needed instead of scattered ones. It&#8217;s generally a bad idea to run a washing machine at 01:00, pause it at 02:00 and then continue at 05:00 \ud83d\ude42<\/p>\n\n\n\n<p><strong>Note: There&#8217;s now also an advanced version available now that uses local calendar and has support to stretch the sequence between two days (e.g. 22.00 &#8211; 06.00).  More details can be found from a separate <a href=\"https:\/\/www.creatingsmarthome.com\/index.php\/2023\/04\/12\/home-assistant-advanced-nord-pool-cheapest-hours-with-local-calendar-support\/\" data-type=\"URL\" data-id=\"https:\/\/www.creatingsmarthome.com\/index.php\/2023\/04\/12\/home-assistant-advanced-nord-pool-cheapest-hours-with-local-calendar-support\/\">blog post<\/a>.<\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"Integrating-Nord-Pool-to-the-Home-Assistant\">Integrating Nord Pool to the Home Assistant<\/h2>\n\n\n\n<p>First we need to get the <a href=\"https:\/\/www.nordpoolgroup.com\/en\/Market-data1\/Dayahead\/Area-Prices\/ALL1\/Hourly\/?view=table\" data-type=\"URL\" data-id=\"https:\/\/www.nordpoolgroup.com\/en\/Market-data1\/Dayahead\/Area-Prices\/ALL1\/Hourly\/?view=table\" target=\"_blank\" rel=\"noreferrer noopener\">Nord Pool prices<\/a> into the system so a new integration is needed. Luckily (again) someone has already made <a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/custom-components\/nordpool\" data-type=\"URL\" data-id=\"https:\/\/github.com\/custom-components\/nordpool\" target=\"_blank\">it happen<\/a> and it can be installed using <a rel=\"noreferrer noopener\" href=\"https:\/\/hacs.xyz\" data-type=\"URL\" data-id=\"https:\/\/hacs.xyz\" target=\"_blank\">HACS<\/a>. If you don&#8217;t know what HACS is, it&#8217;s a Home Assistant Community Store, a place where tons of integrations and frontend elements are published and can be easily installed. Just need to remember that those are not official Home Assistant components and are maintained by individual people and therefore can break more easily than official ones.<\/p>\n\n\n\n<p>Anyway, start by installing <a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/custom-components\/nordpool\" data-type=\"URL\" data-id=\"https:\/\/github.com\/custom-components\/nordpool\" target=\"_blank\">Nord Pool custom component<\/a>. This integration does not have UI configuration so the has to be done manually to the configurations.yaml.<\/p>\n\n\n\n<p>For example, here&#8217;s my config:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>nordpool:\n\nsensor:\n  - platform: nordpool\n    VAT: true\n    currency: \"EUR\"\n    price_in_cents: true\n    region: \"FI\"\n    precision: 3\n    price_type: kWh<\/code><\/pre>\n\n\n\n<p>In above configration firstly we enable the integration and second we configure the sensor to use region Finland and currency in Euros. Some tweaking to precision and VAT is also done, but more configuration details can be found from the <a href=\"https:\/\/github.com\/custom-components\/nordpool\" data-type=\"URL\" data-id=\"https:\/\/github.com\/custom-components\/nordpool\" target=\"_blank\" rel=\"noreferrer noopener\">integration repository<\/a>.<\/p>\n\n\n\n<p>After everything is configured, restart the Home Assistant and continue to the UI part.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Making the UI<\/h2>\n\n\n\n<p>First let&#8217;s find the entity id from our integrations. In Home Assistant go to <strong>Settings-&gt;Devices &amp; Services-&gt;Entities<\/strong> and search with the filter &#8216;<em>nordpool<\/em>&#8216;. You should find a entity id (that is same as unique id) and write it down somewhere. Unique id is generated by the Nord Pool integration from the configuration we made in the previous chapter.<\/p>\n\n\n\n<p>For this part I&#8217;m using <a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/RomRider\/apexcharts-card\" data-type=\"URL\" data-id=\"https:\/\/github.com\/RomRider\/apexcharts-card\" target=\"_blank\">Apex Charts Card<\/a> that is very versatile graphical presentation card of various values. Again, this frontend card can be installed using <a href=\"https:\/\/www.hacs.xyz\/\">HACS<\/a>. So go to the HACS and search for Apex and install it.<\/p>\n\n\n\n<p>After installation is succeeded, it&#8217;s time to configure two cards (one for today and one for tomorrow).<\/p>\n\n\n\n<p>Here&#8217;s my configuration for the cards (example UI shown at the end of this chapter):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>type: 'custom:apexcharts-card'\ngraph_span: 24h\nheader:\n  title: Energy price today (snt\/kWh)\n  show: true\nspan:\n  start: day\nnow:\n  show: true\n  label: Now\nseries:\n  - entity: sensor.nordpool_kwh_fi_eur_3_10_024\n    type: column\n    data_generator: |\n      return entity.attributes.raw_today.map((start, index) =&gt; {\n        return &#091;new Date(start&#091;\"start\"]).getTime(), entity.attributes.raw_today&#091;index]&#091;\"value\"]];\n      });<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>type: custom:apexcharts-card\ngraph_span: 1d\nheader:\n  title: Energy price tomorrow (snt\/kWh)\n  show: true\nspan:\n  start: day\n  offset: +1d\nseries:\n  - entity: sensor.nordpool_kwh_fi_eur_3_10_024\n    type: column\n    data_generator: |\n      return entity.attributes.raw_tomorrow.map((start, index) =&gt; {\n        return &#091;new Date(start&#091;\"start\"]).getTime(), entity.attributes.raw_tomorrow&#091;index]&#091;\"value\"]];\n      });<\/code><\/pre>\n\n\n\n<p>Again, you can use the same configurations, just remember to change the proper entity id for the cards (the one that we wrote down in previous chapter).<\/p>\n\n\n\n<p>That&#8217;s it! Now there should be todays electrical spot prices and tomorrows spot prices available in the Home Assistant for any use!<\/p>\n\n\n\n<p>To make it smart keep on reading the next chapters..<\/p>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-1 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"848\" height=\"636\" data-id=\"1185\" src=\"https:\/\/www.creatingsmarthome.com\/wp-content\/uploads\/2022\/09\/Screenshot-2022-09-16-at-16.05.50.png\" alt=\"\" class=\"wp-image-1185\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"852\" height=\"634\" data-id=\"1186\" src=\"https:\/\/www.creatingsmarthome.com\/wp-content\/uploads\/2022\/09\/Screenshot-2022-09-16-at-16.06.04.png\" alt=\"\" class=\"wp-image-1186\"\/><\/figure>\n<\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Finding the cheapest hours<\/h2>\n\n\n\n<p>One of the key points of having Nord pool is of course finding the cheapest hour(s) and automate devices to run during those hours. <\/p>\n\n\n\n<p>For this I&#8217;ve created a template sensor that ensures validity of next day prices (usually published by Nord Pool at 12:00) and finds the sweet spot of requested lenght!<\/p>\n\n\n\n<p>It&#8217;s easily modifiable by changing numberOfSequentialHours (how long period are we looking for), firstHour (first possible hour we want to start) and last hour (final hour we want to stop latest). E.g. you can also use it to find cheapest hours during the next night by setting the last hour to something like 06:00.<\/p>\n\n\n\n<p><strong>Note: There&#8217;s now also an advanced version available now that uses local calendar and has support to stretch the sequence between two days (e.g. 22.00 &#8211; 06.00).  More details can be found from a separate <a href=\"https:\/\/www.creatingsmarthome.com\/index.php\/2023\/04\/12\/home-assistant-advanced-nord-pool-cheapest-hours-with-local-calendar-support\/\" data-type=\"URL\" data-id=\"https:\/\/www.creatingsmarthome.com\/index.php\/2023\/04\/12\/home-assistant-advanced-nord-pool-cheapest-hours-with-local-calendar-support\/\">blog post<\/a>.<\/strong> You might want to skip into that blog post from this point forward..<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sensor:\n  - platform: template\n    sensors:\n      cheapest_hours_energy_tomorrow:\n        device_class: timestamp\n        friendly_name: Cheapest sequential electricity hours\n        value_template: &gt;\n          {%- set numberOfSequentialHours = 3 -%}\n          {%- set lastHour = 23 -%}\n          {%- set firstHour = 0 -%}\n\n          {%- if state_attr('sensor.nordpool_kwh_fi_eur_3_10_024', 'tomorrow_valid') == true -%}\n            {%- set ns = namespace(counter=0, list=&#091;], cheapestHour=today_at(\"00:00\") + timedelta( hours = (24)), cheapestPrice=999.00) -%}\n            {%- for i in range(firstHour + numberOfSequentialHours, lastHour+1) -%}\n              {%- set ns.counter = 0.0 -%}\n              {%- for j in range(i-numberOfSequentialHours, i) -%}\n                {%- set ns.counter = ns.counter + state_attr('sensor.nordpool_kwh_fi_eur_3_10_024', 'tomorrow')&#091;j] -%}\n              {%- endfor -%}\n              {%- set ns.list = ns.list + &#091;ns.counter] -%}\n              {%- if ns.counter &lt; ns.cheapestPrice -%}\n                {%- set ns.cheapestPrice = ns.counter -%}\n                {%- set ns.cheapestHour = today_at(\"00:00\") + timedelta( hours = (24 + i - numberOfSequentialHours)) -%}\n              {%- endif -%}\n            {%- endfor -%}\n            {{ ns.cheapestHour }}\n            {%- set ns.cheapestPrice = ns.cheapestPrice \/ numberOfSequentialHours -%}\n          {%- endif -%}\n\n\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Finally making the automations<\/h2>\n\n\n\n<p>Now that we know the cheapest hours for the next day, only thing to do is actually do the automations for various devices.<\/p>\n\n\n\n<p>My automation is actually in two parts: <\/p>\n\n\n\n<div class=\"wp-block-group is-nowrap is-layout-flex wp-container-core-group-is-layout-ad2f72ca wp-block-group-is-layout-flex\">\n<ul class=\"wp-block-list\">\n<li>First I save the cheapest hour(s) at <strong>23:10<\/strong>, because we can&#8217;t be following &#8216;tomorrow&#8217; state after midnights since it obviously is not &#8216;tomorrow&#8217; anymore after that \ud83d\ude42\n<ul class=\"wp-block-list\">\n<li><strong>UPDATE:<\/strong> Time changed from 18:00 to 23:10. If cheapest hours happens between automation start time and midnight, the device might start on a wrong day!<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>Second I run the automation when the time trigger is hit<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"860\" height=\"468\" src=\"https:\/\/www.creatingsmarthome.com\/wp-content\/uploads\/2022\/09\/Screenshot-2022-09-16-at-16.07.13.png\" alt=\"\" class=\"wp-image-1184\"\/><\/figure>\n<\/div>\n\n\n\n<pre class=\"wp-block-code\"><code># Helper to keep the start time\ninput_datetime:\n  device_start_time:\n    name: Device Start Time\n    has_time: true\n    has_date: false\n\nautomation:\n# Update time trigger to cheapest hours\n  - id: '1663398489357'\n    alias: 'Set device start time'\n    description: ''\n    trigger:\n    - platform: time\n      at: '23:10:00'\n    condition:\n    - condition: not\n      conditions:\n      - condition: state\n        entity_id: sensor.cheapest_hours_energy_tomorrow\n        state: unknown\n    action:\n    - service: input_datetime.set_datetime\n      data:\n        time: '{{ as_timestamp(states(''sensor.cheapest_hours_energy_tomorrow'')) | timestamp_custom(''%H:%M'') }}'\n      target:\n        entity_id: input_datetime.device_start_time\n    mode: single\n\n# Finally do the actions when time trigger is hit\n  - id: '1663399614818'\n    alias: Increase heating\n    description: ''\n    trigger:\n    - platform: time\n      at: input_datetime.device_start_time\n    condition: &#091;]\n    action:\n    - service: climate.set_temperature\n      data:\n        temperature: 24\n      target:\n        entity_id: climate.heat_pump\n    mode: single\n<\/code><\/pre>\n\n\n\n<p>Nord pool integration have had some issue of not updating properly from time to time (not happened to me though), so with this kind of automation previous day time schedule is being kept if the price template fails for a reason or another. That way no critical devices are left in cold (like water heater).<\/p>\n\n\n\n<p>In my example I&#8217;m just increasing heating values, change it to anything you wish to use on cheap hours. Just remember to turn it off as well if the action is not just simple launch action.<\/p>\n\n\n\n<p><strong>If you made it this far, you can also check the ready made Home Assistant package in the <a rel=\"noreferrer noopener\" href=\"https:\/\/www.creatingsmarthome.com\/index.php\/2022\/11\/06\/home-assistant-nord-pool-cheapest-hours-package\/\" target=\"_blank\">next post<\/a>!<\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>So far so good.. even though I&#8217;m currently having still a static electric price for some months, I&#8217;m using this automation for the common good. I believe that if it&#8217;s possible to time electric consumption for the cheapest hours it will eventually balance the high and lows in general.<\/p>\n\n\n\n<p>Anyway, possibilities to run devices at cheaper prices are great as long as the device has a remote control option! This type of behaviour could be also used for heating to reserve heat into structural parts of the house (e.g. floor heating) during nights.<\/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-97da4800-b620-4432-a397-172611778771\">\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>Most of this information can already be found around the internet, but since I wanted to integrate one as well for my Home Assistant instance,&hellip;<\/p>\n","protected":false},"author":1,"featured_media":1199,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[3,100],"tags":[105,217,106,7,218,219,221,8,220],"class_list":["post-1172","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-guide","category-home-assistant","tag-automation","tag-electricity","tag-energy-saving","tag-home-assistant","tag-nord-pool","tag-price","tag-smart-electricity","tag-smart-home","tag-timer","has-post-thumbnail-archive"],"acf":[],"featured_image_src":"https:\/\/www.creatingsmarthome.com\/wp-content\/uploads\/2022\/09\/Screenshot-2022-09-16-at-16.20.04-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\/1172","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=1172"}],"version-history":[{"count":33,"href":"https:\/\/www.creatingsmarthome.com\/index.php\/wp-json\/wp\/v2\/posts\/1172\/revisions"}],"predecessor-version":[{"id":2556,"href":"https:\/\/www.creatingsmarthome.com\/index.php\/wp-json\/wp\/v2\/posts\/1172\/revisions\/2556"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.creatingsmarthome.com\/index.php\/wp-json\/wp\/v2\/media\/1199"}],"wp:attachment":[{"href":"https:\/\/www.creatingsmarthome.com\/index.php\/wp-json\/wp\/v2\/media?parent=1172"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.creatingsmarthome.com\/index.php\/wp-json\/wp\/v2\/categories?post=1172"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.creatingsmarthome.com\/index.php\/wp-json\/wp\/v2\/tags?post=1172"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}