Help with creating current energy use graphs

Hello,

I am very new to HA, and have setup the energy menu that is integrated into HA.

Now i would like to create a second one with current use (like every 5 seconds for example)

I maneged to get this far:

But the example I found wich i would like to make looks like this:

I just cant get it done, also the example screen looks fullscreen and mine is very small.

Here is my config so far:

type: vertical-stack
cards:
  - type: horizontal-stack
    cards:
      - type: custom:mini-graph-card
        entities:
          - entity: sensor.solaredge_energy_today
        line_color: green
        line_width: 4
        font_size: 80
      - type: custom:mini-graph-card
        entities:
          - entity: sensor.power_consumption
        line_color: orange
        line_width: 4
        font_size: 80
      - type: custom:mini-graph-card
        entities:
          - entity: sensor.power_production
        line_color: red
        line_width: 4
        font_size: 80
  - type: custom:mini-graph-card
    name: Title
    entities:
      - entity: sensor.solaredge_current_power_kwh
        name: Zonne Panelen
        color: green
      - entity: sensor.power_consumption
        name: Stroom verbruik
        color: orange
      - entity: sensor.power_production
        color: red
    line_width: 3
    font_size: 100
    show:
      labels: true
      labels_secondary: true

Also, i have some as W and some as kW, all at W would look better I think.

Can someone maybe help me with this?

Set your view in panel mode :+1:

Thanks! did not know about that.
looks better now,

only one Template i made does not seem to work:

#
- platform: template
  sensors:
    power_consumption_w:
      friendly_name: Power Consumption (W)
      unit_of_measurement: "W"
      value_template: "{{ states('sensor.power_consumption')|float * 1000 }}"

# Calculate Remaining Power
- platform: template
  sensors:
    power_consumption_grid:
      friendly_name: Power Consumption Grid
      unit_of_measurement: "W"
      value_template: >
        {{ '%0.1f' | format(states('power_consumption_w') | float - 
                            states('solaredge_current_power') | float) }}

Read the docs about templates sensors. It should look like this :

template:
  - sensor:
      - name:  power_consumption_w
        unit_of_measurement: "W"
        state: "{{ states('sensor.power_consumption')|float * 1000 }}"
      - name: Power Consumption Grid
        unit_of_measurement: "W"
        state: >
          {{ '%0.1f' | format(states('power_consumption_w') | float - states('solaredge_current_power') | float) }}

and it goes to your configuration.yaml directly

I removed the 2 I had in sensors.yaml and placed your in the configuration.yaml.
But it still shows 0

About Templates, must i always place them in the configuration.yaml? i now have them all in sensors.yaml

having templates sensors in sensor.yaml is the old way. You should migrate them all according the new way :slight_smile:
Read the doc here : Template - Home Assistant

Wich one is displaying 0 ? power consumption grid ? Maybe the sensor you are reading is also at 0 ?

1 Like

Oke thanks, i still need to read and try understand a lot of HA.

The red power consumptin grid shows 0.
This one should show a total from "power consumption - solar energie = total use
example in screenshot:

So lets say I consume 1000 watt, get 500 from solar, it should show a red line to 500 red line (use from net)
i consume 1000, get 2000 from solar, it should show -1000 in a red line.

Found it, these 2 works.

  - sensor:
      - name: Power Consumption Grid
        unit_of_measurement: "W"
        state: >
          {{ '%0.1f' | format(states('sensor.power_consumption_w') | float - states('sensor.solaredge_current_power') | float) }}

  - sensor:
      - name: "Power Consumption Grid"
        unit_of_measurement: "W"
        state: >
          {% set PowerConsumption = states('sensor.power_consumption_w') | float %}
          {% set SolarPower = states('sensor.solaredge_current_power') | float %}

          {{ ((PowerConsumption - SolarPower)) | round(1) }}

But now i wonder, what’s the difference between those. and what meens % or %0.1f
and in the set PowerConsumption, set SolarPower, do those 2 values only exists here or did it create sensors or can i use these global now?

I think both sensors gives you the same output. In the first version you use the the python code 0.1f, meaning the result is formatted as a float value with one decimal.

The % use used within the template to execute the commands I think. You use it in almost all template definitions.

The second sensor converts the state of the input to float with the | float at the end. Better is to use | float(0) though. That also provides a default value of 0 in case the input is unavailable. Currently this still works without the default value, but will need mandatory in the December release I believe.

To your last question… Those variables are only temporary and usable within your template, not outside of it. I am not 100% sure though…

P.S. I see you also use the SolarEdge integration, you may find other useful templates and examples in my project.

1 Like

Thanks, wil look at it tomorrow!

Last question for today :stuck_out_tongue:

I would like to create a “current cost” for the current energy and gas use.

The energy intereation created:
sensor.energy_consumption_tarif_1_cost
sensor.energy_consumption_tarif_2_cost
I created a total one:

- name: Energy Consumption (tarif total) Cost
      state: >
        {% set EnergyConsumptionTarif1 = states('sensor.energy_consumption_tarif_1_cost') | float(0) %}
        {% set EnergyConsumptionTarif2 = states('sensor.energy_consumption_tarif_2_cost') | float(0) %}
        € {{ ((EnergyConsumptionTarif1 + EnergyConsumptionTarif2)) | round(3) }}

But this one is counting up instead of the “current cost”
is there a way to create something like:
Current cost a hour = kwh price x ‘Power Consumption Grid’

Same for the gas.

So as results I want 4 bars,
1 energy current cost. .
1 energy costs today
1 gas current cost
1 gas cost today

I think you should use the utility_meter integration. This creates a new sensor based on a selected input, and can be reset on an hourly, daily, monthly, yearly basis.
In your case you would create 2 meters which reset hourly and use that for the multiplication. That starts from 0 each hour.

I tried, but that does not work. it still counts, so only at the full hour it shows the energy price.
I think i just manualy set the energy price in it. Example 0.50 cent X current grid power.
Just have to find a way to switch between prices when daytime and negative (back to grid) values

Is there also a way to get the icons in here?
example:

Hi Ricks88,

I red your topic and that’s just what I need… :wink:

Could I have your final code, it would save me a lot of time ?

Thanks !

1 Like

Hi,

This is all the layout code:

type: vertical-stack
cards:
  - type: custom:gap-card
    height: 5
  - type: horizontal-stack
    cards:
      - type: custom:apexcharts-card
        header:
          title: Energie verbruik
          show: true
          show_states: true
          colorize_states: false
        graph_span: 2h
        layout: minimal
        series:
          - entity: sensor.power_consumption_w
            name: ' '
            unit: ' Watt'
            color: '#00648e'
            opacity: 0.5
            type: area
            curve: smooth
            stroke_width: 2
        apex_config:
          stroke:
            show: true
          legend:
            show: false
          yaxis:
            show: false
          chart:
            height: 175px
      - type: custom:apexcharts-card
        header:
          title: Oplevering Zonnepanelen
          show: true
          show_states: true
          colorize_states: false
        graph_span: 2h
        layout: minimal
        series:
          - entity: sensor.solaredge_current_power
            name: ' '
            unit: ' Watt'
            color: '#ffaa5b'
            opacity: 0.5
            type: area
            curve: smooth
            stroke_width: 2
        apex_config:
          stroke:
            show: true
          legend:
            show: false
          yaxis:
            show: false
          chart:
            height: 175px
      - type: custom:apexcharts-card
        header:
          title: Netto verbruik
          show: true
          show_states: true
          colorize_states: false
        graph_span: 2h
        layout: minimal
        series:
          - entity: sensor.power_consumption_grid_pos
            name: ' '
            unit: ' Watt'
            color: '#9a001d'
            opacity: 0.5
            type: area
            curve: smooth
            stroke_width: 2
          - entity: sensor.power_consumption_grid_neg
            name: ' '
            unit: ' Watt'
            color: '#8756cb'
            opacity: 0.5
            type: area
            curve: smooth
            stroke_width: 2
        apex_config:
          stroke:
            show: true
          legend:
            show: false
          yaxis:
            show: false
          chart:
            height: 175px
      - type: entity
        entity: sensor.solaredge_storage_level
        name: Energieopslag
        state_color: true
  - type: custom:stack-in-card
    mode: vertical
    cards:
      - type: entities
        entities: []
      - type: custom:apexcharts-card
        graph_span: 6hours
        header:
          show: true
          show_states: true
          colorize_states: true
        series:
          - entity: sensor.power_consumption_w
            name: Energie verbruik
            color: '#00648e'
            opacity: 0.3
            type: area
          - entity: sensor.solaredge_current_power
            name: Zonne Energie
            color: '#ffaa5b'
            opacity: 0.4
            type: area
          - entity: sensor.power_consumption_grid_pos
            name: Netto verbruik
            color: '#9a001d'
            opacity: 0.3
            type: area
          - entity: sensor.power_consumption_grid_neg
            name: Netto Teruglevering
            color: '#8756cb'
            opacity: 0.3
            type: area
        now:
          show: true
          color: red
          label: Nu
        apex_config:
          stroke:
            show: true
            width: 2
            curve: smooth
          legend:
            show: true
          yaxis:
            show: true
          chart:
            height: 550px
      - type: custom:gap-card
        height: 5

Thats what you needed?

Thank you…could you alsof give me the definitions of the sensors you use in this layout ?

Can i send a file somehow?

Or try this:

---
# Power Consumption Grid
# Bereken Energie verbruik - Opbrengst Zonnepanelen = netto verbruik
#
sensor:
  name: Power Consumption Grid
  unit_of_measurement: "W"
  icon: "mdi:transmission-tower"
  state: >
    {% set PowerConsumption = states('sensor.power_consumption_w') | float(0) %}
    {% set SolarPower = states('sensor.solaredge_current_power') | float(0) %}
    {{ ((PowerConsumption - SolarPower)) | round(1) }}

---
# Power Consumption Grid Negative only = Teruglevering
# Bereken Energie verbruik - Opbrengst Zonnepanelen = Netto Verbruik, show positive only dus alleen Teruglevering
#
sensor:
  name: Power Consumption Grid (Neg)
  unit_of_measurement: "W"
  icon: "mdi:transmission-tower-export"
  state: >-
    {% set PowerConsumption = states('sensor.power_consumption_w') | float(0) %}
    {% set SolarPower = states('sensor.solaredge_current_power') | float(0) %}
    {% set PowerConsumptionGridNeg = (PowerConsumption - SolarPower) | int %}
    {{ ([-10000, PowerConsumptionGridNeg, 0] |sort) [1] }}

---
# Power Consumption Grid Positive only
# Bereken Energie verbruik - Opbrengst Zonnepanelen = Netto Verbruik, show positive only
#
sensor:
  name: Power Consumption Grid (Pos)
  unit_of_measurement: "W"
  icon: "mdi:transmission-tower-import"
  state: >-
    {% set PowerConsumption = states('sensor.power_consumption_w') | float(0) %}
    {% set SolarPower = states('sensor.solaredge_current_power') | float(0) %}
    {% set PowerConsumptionGridPos = (PowerConsumption - SolarPower) | int %}
    {{ ([0, PowerConsumptionGridPos, 10000] |sort) [1] }}

---
# Power Consumption in Watt, kWh to W
#
sensor:
  name: Power Consumption (W)
  unit_of_measurement: "W"
  state: "{{ states('sensor.power_consumption')|float * 1000 }}"
  icon: "hass:lightning-bolt"

1 Like

Sorry for my late reaction.

First of all : thank you !

One problem : I presume I have too much data, cause when I put these graphs on my dashboard my computer is in trouble… I’m working with the Slimme Meter (via ESPHome).

Editing the data can be very slow, but on my Raspberry Pi 4b it is no problem…
I do not use ESPHome, just ‘SlimmeLezer’ P1 port.
It should only show data for 4hours or 6 in the big graph?