{"id":2136,"date":"2023-08-30T13:01:43","date_gmt":"2023-08-30T13:01:43","guid":{"rendered":"https:\/\/www.creatingsmarthome.com\/?p=2136"},"modified":"2025-09-05T05:57:46","modified_gmt":"2025-09-05T05:57:46","slug":"home-assistant-hourly-imported-exported-energy-balance-in-solar-automations","status":"publish","type":"post","link":"https:\/\/www.creatingsmarthome.com\/index.php\/2023\/08\/30\/home-assistant-hourly-imported-exported-energy-balance-in-solar-automations\/","title":{"rendered":"Home Assistant: Hourly Imported\/Exported Energy Balance in Solar Automations"},"content":{"rendered":"\n<p>In Finland we have this so called energy balance (&#8220;<em>tuntinetotus<\/em>&#8220;) meaning that sold and bought energy are being summed up every hour (or 15 minutes, depending of the electrical company) before adding up to the electricity bill. So, if you are consuming much less energy than producing in a one hour, the rest of the energy will be sold to the energy company. However, to get most use of the self produced energy, as much as possible &#8216;<em>should<\/em>&#8216; be consumed yourself.<em><strong>*<\/strong><\/em><\/p>\n\n\n\n<p><strong>An example<\/strong>: you are producing 1kWh of energy in the first 30 minutes and not consuming any. Then using 1kWh in the next 30min within the same hour and not producing any, total cost of the energy will be 0\u20ac. <strong>Without energy balance<\/strong>, you would first selling 1kWh and then buying back 1kWh and thus paying the transfer costs of the bought back energy.<\/p>\n\n\n\n<p>This got me thinking that I would like to get realtime information of the energy balance of the current hour so I could run automations or manually trigger devices with excess balanced energy. E.g. <em>every half an hour I check the current balance and run water heater the rest of the hour, if the balance is negative enough<\/em>. Target is always to have 0 kWh balance at the end of each hour.<\/p>\n\n\n\n<p><sup>* Of course sometimes it&#8217;s better to sell product electricity instead of using yourself for a better profit, but this automation does not take that into consideration<\/sup><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"507\" height=\"107\" src=\"https:\/\/www.creatingsmarthome.com\/wp-content\/uploads\/2023\/08\/Screenshot-2023-08-30-at-15.16.21.png\" alt=\"\" class=\"wp-image-2174\" srcset=\"https:\/\/www.creatingsmarthome.com\/wp-content\/uploads\/2023\/08\/Screenshot-2023-08-30-at-15.16.21.png 507w, https:\/\/www.creatingsmarthome.com\/wp-content\/uploads\/2023\/08\/Screenshot-2023-08-30-at-15.16.21-300x63.png 300w\" sizes=\"auto, (max-width: 507px) 100vw, 507px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Requirements<\/h2>\n\n\n\n<p>For this helper a <strong>local energy production<\/strong> is required (obviously) and a Home Assistant integrated device that can <strong>read your consumed and sold energy<\/strong> in real time. <\/p>\n\n\n\n<p>In my house I got 8.6kWp Solar system with Growatt Inverter and <em>EM340 ModBus energy meter*<\/em> where I can get realtime data of imported and exported energy. <\/p>\n\n\n\n<p><sup>* Guide coming later up, how to integrate WallBox Pulsar Plus + EM340 PowerBoost to Home Assistant for realtime energy information. <\/sup><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Setting up the Home Assistant utility meters<\/h2>\n\n\n\n<p>So, for starters we are going to create two utility meters that cycles every hour: one for import and one for export.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>utility_meter:\n  hourly_energy_in_kwh:\n    name: Hourly Energy In\n    source: sensor.energy_total_in\n    cycle: hourly\n  hourly_energy_out_kwh:\n    name: Hourly Energy Out\n    source: sensor.energy_total_out\n    cycle: hourly<\/code><\/pre>\n\n\n\n<p>Those two entities can now be used to check how much energy were imported and exported every hour.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Creating template energy balance entity<\/h2>\n\n\n\n<p>Next step is just to sum those up so we get the total balance that is updated realtime.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>template:\n  - sensor:\n    - name: \"Energy balance current hour\"\n      unique_id: energy_balance_current_hour\n      device_class: energy\n      unit_of_measurement: kWh\n      state: &gt;\n        {{ ((states('sensor.hourly_energy_in') | float) - (states('sensor.hourly_energy_out') | float)) |&nbsp;round(2) }}<\/code><\/pre>\n\n\n\n<p>That&#8217;s it! The energy balance is now visible!<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"557\" height=\"386\" src=\"https:\/\/www.creatingsmarthome.com\/wp-content\/uploads\/2023\/08\/Screenshot-2023-08-24-at-13.45.57.png\" alt=\"\" class=\"wp-image-2161\" srcset=\"https:\/\/www.creatingsmarthome.com\/wp-content\/uploads\/2023\/08\/Screenshot-2023-08-24-at-13.45.57.png 557w, https:\/\/www.creatingsmarthome.com\/wp-content\/uploads\/2023\/08\/Screenshot-2023-08-24-at-13.45.57-300x208.png 300w\" sizes=\"auto, (max-width: 557px) 100vw, 557px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">The automation<\/h2>\n\n\n\n<p>Here&#8217;s an example automation how I turn on my water heater for 30 minutes, if I have enough excess solar energy from the first half an hour. My water heater is using 3000 watts of power while heating, so 30 minute heating requires 1500kWh of energy. So when ever I have 1.5 kWh of excess energy on 30 minute mark, I can turn on water heater for next 30 minutes for &#8216;free&#8217;. Here&#8217;s an example automation how I&#8217;m currently using it:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>alias: \"Energy: Water Boiler on excess solar balance\"\ndescription: &gt;-\n  Turns on water boiler for 30 minutes when solar balance exceeds 1.5kwh on 30th\n  minute\ntrigger:\n  - platform: time_pattern\n    minutes: \"30\"\ncondition:\n  - condition: numeric_state\n    entity_id: sensor.energy_balance_current_hour\n    above: 1.5\naction:\n  - service: switch.turn_on\n    data: {}\n    target:\n      entity_id: switch.water_boiler\n  - delay:\n      hours: 0\n      minutes: 30\n      seconds: 0\n      milliseconds: 0\n  - service: switch.turn_off\n    data: {}\n    target:\n      entity_id: switch.water_boiler\nmode: single<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>Of course this automation is not perfect, since I&#8217;m still getting more and more energy if the sun is shining so I still end up more energy sold than used within an hour hour. Once I manage to automate my water heater system fully I&#8217;m going to change this automation to use something else..<\/p>\n\n\n\n<p>Anyhow, simple combination of utility meters and a template sensor to do the full job. Now we are able to get realtime information of current energy balance and run automations regarding it. Should improve my total energy management by an inch at least if nothing else \ud83d\ude42<\/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-7071e94d-2398-425a-bed0-e7fb9cded5c2\">\n<p id=\"ub-styled-box-bordered-content-e29ae8c1-008f-4261-9585-dd104de89429\"><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>In Finland we have this so called energy balance (&#8220;tuntinetotus&#8220;) meaning that sold and bought energy are being summed up every hour (or 15 minutes,&hellip;<\/p>\n","protected":false},"author":1,"featured_media":2161,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[100,317],"tags":[105,314,315,313,7,8,305,312,316,310],"class_list":["post-2136","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-home-assistant","category-solar-power","tag-automation","tag-em340","tag-enabler","tag-energy-meter","tag-home-assistant","tag-smart-home","tag-solar","tag-solar-energy","tag-solar-panels","tag-solar-power","has-post-thumbnail-archive"],"acf":[],"featured_image_src":"https:\/\/www.creatingsmarthome.com\/wp-content\/uploads\/2023\/08\/Screenshot-2023-08-24-at-13.45.57.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\/2136","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=2136"}],"version-history":[{"count":37,"href":"https:\/\/www.creatingsmarthome.com\/index.php\/wp-json\/wp\/v2\/posts\/2136\/revisions"}],"predecessor-version":[{"id":4544,"href":"https:\/\/www.creatingsmarthome.com\/index.php\/wp-json\/wp\/v2\/posts\/2136\/revisions\/4544"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.creatingsmarthome.com\/index.php\/wp-json\/wp\/v2\/media\/2161"}],"wp:attachment":[{"href":"https:\/\/www.creatingsmarthome.com\/index.php\/wp-json\/wp\/v2\/media?parent=2136"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.creatingsmarthome.com\/index.php\/wp-json\/wp\/v2\/categories?post=2136"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.creatingsmarthome.com\/index.php\/wp-json\/wp\/v2\/tags?post=2136"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}