{"id":3119,"date":"2021-12-17T21:46:14","date_gmt":"2021-12-17T21:46:14","guid":{"rendered":"https:\/\/martinsentech.no\/?p=3119"},"modified":"2025-09-06T12:18:56","modified_gmt":"2025-09-06T12:18:56","slug":"home-assistant-electrisity-price-graph","status":"publish","type":"post","link":"https:\/\/martinsentech.no\/index.php\/2021\/12\/17\/home-assistant-electrisity-price-graph\/","title":{"rendered":"Home Assistant &#8211; Electrisity Price Graph"},"content":{"rendered":"\n<p>I wanted to see my Power Consumption together with Electricity Price in a nice graphical representation.<\/p>\n<p>For that, I used ApexCharts-Card: <a href=\"https:\/home\/user\/pub\/martinsentech\/github.com\/RomRider\/apexcharts-card\">https:\/home\/user\/pub\/martinsentech\/github.com\/RomRider\/apexcharts-card<\/a><\/p>\n<p>The graph uses data from Tibber, Tibber Data, and Nordpool integrations.<\/p>\n<ul>\n<li>Tibber: <a href=\"https:\/home\/user\/pub\/martinsentech\/www.home-assistant.io\/integrations\/tibber\/\">https:\/home\/user\/pub\/martinsentech\/www.home-assistant.io\/integrations\/tibber\/<\/a><\/li>\n<li>Tibber Data: <a href=\"https:\/home\/user\/pub\/martinsentech\/github.com\/Danielhiversen\/home_assistant_tibber_data\">https:\/home\/user\/pub\/martinsentech\/github.com\/Danielhiversen\/home_assistant_tibber_data<\/a><\/li>\n<li>Nordpool: <a href=\"https:\/home\/user\/pub\/martinsentech\/github.com\/custom-components\/nordpool\">https:\/home\/user\/pub\/martinsentech\/github.com\/custom-components\/nordpool<\/a><\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p>The result is shown in the image, and the code can be downloaded here:<\/p>\n<p>&nbsp;<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;yaml&quot;,&quot;mime&quot;:&quot;text\/yaml&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;YAML&quot;,&quot;language&quot;:&quot;YAML&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;yaml&quot;}\">type: custom:apexcharts-card\nheader:\n  show: true\n  title: Power Usage Hourly vs Electricity Price\n  show_states: true\n  colorize_states: true\nnow:\n  show: true\n  label: Now\ngraph_span: 72h\nspan:\n  start: day\n  offset: '-24h'\napex_config:\n  xaxis:\n    labels:\n      format: dd.MM\n  chart:\n    zoom:\n      enabled: true\n    toolbar:\n      show: true\n      tools:\n        zoom: true\n        zoomin: false\n        zoomout: false\n        pan: false\n        reset: true\n  tooltip:\n    fixed:\n      enabled: true\n      position: bottomLeft\nyaxis:\n  - id: first\n    apex_config:\n      min: 0\n      opposite: true\n      forceNiceScale: true\n      decimalsInFloat: 2\n      labels:\n        show: true\n  - id: second\n    apex_config:\n      opposite: false\n      forceNiceScale: true\n      decimalsInFloat: 1\n      labels:\n        show: true\nall_series_config:\n  stroke_width: 4\nseries:\n  - entity: sensor.nordpool_kwh_oslo_nok_3_10_025\n    yaxis_id: first\n    name: Yesterday\n    type: area\n    curve: stepline\n    float_precision: 2\n    stroke_width: 2\n    opacity: 0.05\n    extend_to: false\n    offset: '-1min'\n    show:\n      in_header: false\n      legend_value: false\n      in_chart: true\n      extremas: true\n      offset_in_name: false\n    color: '#00FF00'\n  - entity: sensor.nordpool_kwh_oslo_nok_3_10_025\n    yaxis_id: first\n    name: Today\n    type: area\n    curve: stepline\n    float_precision: 2\n    stroke_width: 2\n    opacity: 0.5\n    extend_to: false\n    offset: '-1min'\n    show:\n      in_header: false\n      legend_value: false\n      extremas: true\n      offset_in_name: false\n    color: '#0080FF'\n    data_generator: |\n      return entity.attributes.raw_today.map((p) =&gt; {\n        return [new Date(p.start), p.value];\n      });\n  - entity: sensor.nordpool_kwh_oslo_nok_3_10_025\n    yaxis_id: first\n    name: Tomorrow\n    type: area\n    curve: stepline\n    float_precision: 2\n    stroke_width: 2\n    opacity: 0.2\n    offset: '-1min'\n    show:\n      in_header: false\n      legend_value: false\n      extremas: true\n      offset_in_name: false\n    color: '#FF7F00'\n    data_generator: |\n      return entity.attributes.raw_tomorrow.map((p) =&gt; {\n        return [new Date(p.start), p.value];\n      });\n  - entity: sensor.accumulated_consumption_current_hour\n    yaxis_id: second\n    name: Power Usage\n    type: line\n    float_precision: 2\n    stroke_width: 2\n    opacity: 1\n    color: '#FF0000'\n    extend_to: false\n    show:\n      in_header: true\n      legend_value: false\n    group_by:\n      func: max\n  - entity: sensor.nordpool_kwh_oslo_nok_3_10_025\n    yaxis_id: first\n    name: Price Now\n    type: area\n    curve: stepline\n    float_precision: 2\n    stroke_width: 0\n    opacity: 0.1\n    extend_to: false\n    show:\n      in_header: true\n      legend_value: false\n      in_chart: true\n    color: '#0080FF'\n  - entity: sensor.average_of_3_highest_hourly_consumption\n    yaxis_id: second\n    name: 3 Highest Avarage\n    type: line\n    float_precision: 2\n    stroke_width: 2\n    opacity: 1\n    color: '#800080'\n    extend_to: false\n    show:\n      in_header: true\n      legend_value: false\n      in_chart: false<\/pre><\/div>\n\n\n\n<p>Below is a screenshot from my phone in Light Mode.<\/p>\n\t<div class=\"img has-hover x md-x lg-x y md-y lg-y\" id=\"image_1547936021\">\n\t\t\t\t\t\t\t\t<div class=\"img-inner dark\" >\n\t\t\t<img loading=\"lazy\" decoding=\"async\" width=\"494\" height=\"399\" src=\"https:\/\/martinsentech.no\/wp-content\/uploads\/2022\/09\/Apexchart_Card-PowerUsagePrice-Light.png\" class=\"attachment-large size-large\" alt=\"\" srcset=\"https:\/\/martinsentech.no\/wp-content\/uploads\/2022\/09\/Apexchart_Card-PowerUsagePrice-Light.png 494w, https:\/\/martinsentech.no\/wp-content\/uploads\/2022\/09\/Apexchart_Card-PowerUsagePrice-Light-300x242.png 300w\" sizes=\"auto, (max-width: 494px) 100vw, 494px\" \/>\t\t\t\t\t\t\n\t\t\t\t\t<\/div>\n\t\t\t\t\t\t\t\t\n<style>\n#image_1547936021 {\n  width: 100%;\n}\n<\/style>\n\t<\/div>\n\t\n\n<p>I have 3 template sensors to find the cheapest hours:<\/p>\n<ul>\n<li>Cheapest 3 hours<\/li>\n<li>Cheapest 4 hours<\/li>\n<li>Cheapest 6 hours<\/li>\n<\/ul>\n<p>The code below should be placed in&nbsp;<code>sensors.yaml<\/code>.<\/p>\n<p>&nbsp;<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;yaml&quot;,&quot;mime&quot;:&quot;text\/yaml&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;YAML&quot;,&quot;language&quot;:&quot;YAML&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;yaml&quot;}\">- platform: template\n  sensors:\n    cheapest_3_hours:\n      value_template: &gt;-\n        {% set l=state_attr('sensor.nordpool_kwh_no1_nok_3_10_025', 'raw_today')|sort(attribute='value') %}\n        {{ (now() &gt;= l[0].start and now() &lt;= l[0].end)\n          or (now() &gt;= l[1].start and now() &lt;= l[1].end)\n          or (now() &gt;= l[2].start and now() &lt;= l[2].end) }}\n\n- platform: template\n  sensors:\n    cheapest_4_hours:\n      value_template: &gt;-\n        {% set l=state_attr('sensor.nordpool_kwh_no1_nok_3_10_025', 'raw_today')|sort(attribute='value') %}\n        {{ (now() &gt;= l[0].start and now() &lt;= l[0].end)\n          or (now() &gt;= l[1].start and now() &lt;= l[1].end)\n          or (now() &gt;= l[2].start and now() &lt;= l[2].end)\n          or (now() &gt;= l[3].start and now() &lt;= l[3].end) }}\n\n- platform: template\n  sensors:\n    cheapest_6_hours:\n      value_template: &gt;-\n        {% set l=state_attr('sensor.nordpool_kwh_no1_nok_3_10_025', 'raw_today')|sort(attribute='value') %}\n        {{ (now() &gt;= l[0].start and now() &lt;= l[0].end)\n          or (now() &gt;= l[1].start and now() &lt;= l[1].end)\n          or (now() &gt;= l[2].start and now() &lt;= l[2].end)\n          or (now() &gt;= l[3].start and now() &lt;= l[3].end)\n          or (now() &gt;= l[4].start and now() &lt;= l[4].end)\n          or (now() &gt;= l[5].start and now() &lt;= l[5].end) }}<\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>I wanted to see my Power Consumption tougher with Electricity Price on a nice graphical representation.<\/p>\n","protected":false},"author":1,"featured_media":3465,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[77],"tags":[],"class_list":["post-3119","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-smart-house"],"jetpack_featured_media_url":"https:\/\/martinsentech.no\/wp-content\/uploads\/2022\/09\/Apexchart_Card-PowerUsagePrice-Dark.png","_links":{"self":[{"href":"https:\/\/martinsentech.no\/index.php\/wp-json\/wp\/v2\/posts\/3119","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/martinsentech.no\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/martinsentech.no\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/martinsentech.no\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/martinsentech.no\/index.php\/wp-json\/wp\/v2\/comments?post=3119"}],"version-history":[{"count":33,"href":"https:\/\/martinsentech.no\/index.php\/wp-json\/wp\/v2\/posts\/3119\/revisions"}],"predecessor-version":[{"id":3648,"href":"https:\/\/martinsentech.no\/index.php\/wp-json\/wp\/v2\/posts\/3119\/revisions\/3648"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/martinsentech.no\/index.php\/wp-json\/wp\/v2\/media\/3465"}],"wp:attachment":[{"href":"https:\/\/martinsentech.no\/index.php\/wp-json\/wp\/v2\/media?parent=3119"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/martinsentech.no\/index.php\/wp-json\/wp\/v2\/categories?post=3119"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/martinsentech.no\/index.php\/wp-json\/wp\/v2\/tags?post=3119"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}