{"id":1257,"date":"2023-01-02T00:18:48","date_gmt":"2023-01-01T22:18:48","guid":{"rendered":"https:\/\/cln.io\/blog\/?p=1257"},"modified":"2023-01-12T23:53:21","modified_gmt":"2023-01-12T21:53:21","slug":"home-assistant-converting-wh-to-kwh","status":"publish","type":"post","link":"https:\/\/cln.io\/blog\/home-assistant-converting-wh-to-kwh\/","title":{"rendered":"Home assistant converting Wh to kWh (with integration or with a template sensor)"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">I was looking for a way to convert a home assistant integration entity of Wh to kWh (which is really just dividing by 1000) <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In theory, I should be using the &#8220;<a href=\"https:\/\/www.home-assistant.io\/integrations\/integration\/#energy\" target=\"_blank\" rel=\"noreferrer noopener\">Integration &#8211; Riemann sum integral<\/a>&#8221; but it was not working for me for some reason, so attached in this post is also the template way of converting Wh to kWh<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">On this page<\/p>\n\n\n\n<nav aria-label=\"Table of Contents\" class=\"wp-block-table-of-contents\"><ol><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/cln.io\/blog\/home-assistant-converting-wh-to-kwh\/#using-integration-riemann-sum-integral\">Using Integration &#8211; Riemann sum integral<\/a><ol><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/cln.io\/blog\/home-assistant-converting-wh-to-kwh\/#using-yaml\">Using YAML<\/a><\/li><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/cln.io\/blog\/home-assistant-converting-wh-to-kwh\/#using-the-ui\">Using the UI<\/a><\/li><\/ol><\/li><li><a class=\"wp-block-table-of-contents__entry\" href=\"https:\/\/cln.io\/blog\/home-assistant-converting-wh-to-kwh\/#using-a-template-sensor\">Using a template sensor<\/a><\/li><\/ol><\/nav>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"using-integration-riemann-sum-integral\">Using Integration &#8211; Riemann sum integral<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"using-yaml\">Using YAML<\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"yaml\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#from https:\/\/www.home-assistant.io\/integrations\/integration\/#energy\nsensor:\n  - platform: integration\n    source: sensor.current_power\n    name: energy_spent\n    unit_prefix: k\n    round: 2<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"using-the-ui\">Using the UI<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Head over to &#8220;Settings &gt; Devices &amp; Services &gt; [ontop of the page] select the Helpers tab &gt; [right down below] hit + Create Helper&#8221;<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"693\" height=\"450\" src=\"https:\/\/cln.io\/blog\/wp-content\/uploads\/2023\/01\/image.png\" alt=\"\" class=\"wp-image-1259\" srcset=\"https:\/\/cln.io\/blog\/wp-content\/uploads\/2023\/01\/image.png 693w, https:\/\/cln.io\/blog\/wp-content\/uploads\/2023\/01\/image-300x195.png 300w\" sizes=\"auto, (max-width: 693px) 100vw, 693px\" \/><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\">In the create helper wizard pick &#8220;Riemann sum integral sensor&#8221;<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/cln.io\/blog\/wp-content\/uploads\/2023\/01\/image-1.png\" alt=\"\" class=\"wp-image-1261\" width=\"498\" height=\"323\"\/><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\">Pick a name for your conversion sensor and the source of the data<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"811\" height=\"1024\" src=\"https:\/\/cln.io\/blog\/wp-content\/uploads\/2023\/01\/image-2-811x1024.png\" alt=\"\" class=\"wp-image-1262\" srcset=\"https:\/\/cln.io\/blog\/wp-content\/uploads\/2023\/01\/image-2-811x1024.png 811w, https:\/\/cln.io\/blog\/wp-content\/uploads\/2023\/01\/image-2-237x300.png 237w, https:\/\/cln.io\/blog\/wp-content\/uploads\/2023\/01\/image-2-768x970.png 768w, https:\/\/cln.io\/blog\/wp-content\/uploads\/2023\/01\/image-2-1216x1536.png 1216w, https:\/\/cln.io\/blog\/wp-content\/uploads\/2023\/01\/image-2.png 1238w\" sizes=\"auto, (max-width: 811px) 100vw, 811px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"using-a-template-sensor\">Using a template sensor<\/h2>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"yaml\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">template:\n    - sensor:\n        - name: \"Hallway heater (template sensor) kWh\"\n          unique_id: hallway_heater_template\n          unit_of_measurement: kWh\n          state: \"{{ states('sensor.hallway_heather_energy_consumption')|float\/1000}}\"\n          device_class: energy\n          state_class: total_increasing\n          attributes:\n            last_reset: \"1970-01-01T00:00:00+00:00\"<\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"683\" src=\"https:\/\/cln.io\/blog\/wp-content\/uploads\/2023\/01\/mostafa-mahmoudi-47jO5Y8nsYo-unsplash-1024x683.jpg\" alt=\"\" class=\"wp-image-1269\" srcset=\"https:\/\/cln.io\/blog\/wp-content\/uploads\/2023\/01\/mostafa-mahmoudi-47jO5Y8nsYo-unsplash-1024x683.jpg 1024w, https:\/\/cln.io\/blog\/wp-content\/uploads\/2023\/01\/mostafa-mahmoudi-47jO5Y8nsYo-unsplash-300x200.jpg 300w, https:\/\/cln.io\/blog\/wp-content\/uploads\/2023\/01\/mostafa-mahmoudi-47jO5Y8nsYo-unsplash-768x512.jpg 768w, https:\/\/cln.io\/blog\/wp-content\/uploads\/2023\/01\/mostafa-mahmoudi-47jO5Y8nsYo-unsplash-1536x1024.jpg 1536w, https:\/\/cln.io\/blog\/wp-content\/uploads\/2023\/01\/mostafa-mahmoudi-47jO5Y8nsYo-unsplash.jpg 1920w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">Photo by <a href=\"https:\/\/unsplash.com\/@mostafa_mahmoudi24?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText\" target=\"_blank\" rel=\"noreferrer noopener\">mostafa mahmoudi<\/a> on <a href=\"https:\/\/unsplash.com\/photos\/47jO5Y8nsYo?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText\" target=\"_blank\" rel=\"noreferrer noopener\">Unsplash<\/a>   <\/figcaption><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>I was looking for a way to convert a home assistant integration entity of Wh to kWh (which is really just dividing by 1000) In theory, I should be using the &#8220;Integration &#8211; Riemann sum [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1270,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,4],"tags":[],"class_list":["post-1257","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-automation","category-homeassistant"],"_links":{"self":[{"href":"https:\/\/cln.io\/blog\/wp-json\/wp\/v2\/posts\/1257","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cln.io\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cln.io\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cln.io\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cln.io\/blog\/wp-json\/wp\/v2\/comments?post=1257"}],"version-history":[{"count":4,"href":"https:\/\/cln.io\/blog\/wp-json\/wp\/v2\/posts\/1257\/revisions"}],"predecessor-version":[{"id":1271,"href":"https:\/\/cln.io\/blog\/wp-json\/wp\/v2\/posts\/1257\/revisions\/1271"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cln.io\/blog\/wp-json\/wp\/v2\/media\/1270"}],"wp:attachment":[{"href":"https:\/\/cln.io\/blog\/wp-json\/wp\/v2\/media?parent=1257"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cln.io\/blog\/wp-json\/wp\/v2\/categories?post=1257"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cln.io\/blog\/wp-json\/wp\/v2\/tags?post=1257"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}