Anyone using the Sankey Chart Card?

I’ve been struggling with this for days, can anyone help?
I cant get any lines when i try to make an intermediary stop, and even without i cant get remaining parent state to show up.

type: custom:sankey-chart
height: 200
wide: true
unit_prefix: k
round: 1
min_box_height: 3
min_box_distance: 5
show_names: true
show_units: true
energy_date_selection: true
sections:
  - entities:
      - entity_id: sensor.accumulated_consumption_hedne
        name: Total Consumption
        type: entity
        children:
          - no_area
          - unknown
      - entity_id: no_area
        type: remaining_child_state
        name: No area
        color: purple
        children:
          - sensor.lights_energy
          - sensor.bathroom_thermostat_energy
          - sensor.easee_home_25869_lifetime_energy
          - sensor.office_heater_filtered_kwh
          - sensor.bedroom_heater_filtered_kwh
          - sensor.yacuzzi_energy
          - sensor.boiler_energy_energy
      - entity_id: unknown
        type: remaining_parent_state
        name: Unknown
        color: red
  - entities:
      - entity_id: sensor.lights_energy
        name: All lights
      - entity_id: sensor.bathroom_thermostat_energy
        name: Bathroom Heating
      - entity_id: sensor.easee_home_25869_lifetime_energy
        name: Car Charger
      - entity_id: sensor.office_heater_filtered_kwh
        name: Office Heating
      - entity_id: sensor.bedroom_heater_filtered_kwh
        name: Bedroom Heating
      - entity_id: sensor.yacuzzi_energy
        name: Yacuzzi
      - entity_id: sensor.boiler_energy_energy
        name: Water heater

you’re missing an - entities: tag under the Total Consumption Entity - you specify what the children ar, but then they’re listed in the same section as the parent.

1 Like

this must have asked before… so sorry if I missed that.
Can we set the sankey chart card to use 2 columns?

I have a view with layout-card option

type: custom:horizontal-layout
layout:
  max_cols: 2

and all that would need changing would be the sankey-chart. The rest need to remain in 2 columns.

fr a moment I believed there was a ‘per card’ option in layout-card, but as far as I can understand it, it can only set a card to a specific column, not both.

view_layout:
  column: 2

or. like:

type: custom:layout-card
#max_width: 100%
layout:
  max_cols: 2
cards:
  - type: custom:sankey-chart
    title: Energie verbruik

But that has an odd effect of even narrowing the card space inside a single column in the view.

havent gotten as far as using the grid option on the complete view, so hope there is a solution.

I do have a dedicated view also, and set it to panel mode. however, without going into a lot of details, we would need to use a vertical-stack with a bunch of horizontal stacks to get somewhere near what I an looking for. Let alone that these wouldn’t be as adaptive aas the current setting.

thx for having a look

edit

I now find Anyone using the Sankey Chart Card? - #15 by tom_l, using panel mode or sidebar…

Already using panel mode on another view as mentioned. sidebar is not for my purposes…

guess it wont go then.

Hi all,

I’ve recently started using Home Assistant so I’m pretty new.
I have added my mqtt smart plugs, templates and added a dashboard to my lovelace in configuration.yaml to show Energy Consumption:

template: !include templates.yaml
mqtt: !include mqtt.yaml

lovelace:
  mode: storage
  dashboards:
    lovelace-energy-consumption:
      mode: yaml
      title: Energy Consumption
      icon: mdi:chart-gantt
      show_in_sidebar: true
      filename: db-energy-consumption.yaml

The end result is:
my_sankey

However, I would like monitored loads to be a column to the right, so they’ll become bigger and better readable. I tried to do things with passthrough, but to no avail. I thought I might need a template sensor that would be the sum of those monitored loads, which is why I created the following templates.yaml:

- sensor:
    - unique_id: monitored_loads
      name: monitored_loads
      unit_of_measurement: "kWh"
      state_class: measurement
      device_class: energy
      state: >
          {% set variable = namespace(value = {}) %}
          {% set power = namespace(value = 0) %}
          {% for entity in states.sensor if (entity.entity_id.endswith("_consumption")) %}
            {% set variable.value = dict(variable.value, **{entity.name: entity.state }) %}
            {% set power.value = power.value |float + entity.state |float %}
          {% endfor %}
          {{ (power.value) |round(2) }}

I got the code from a youtube video and changed it to my need. I have a feeling it’s way more complicated than necessary, but I can confirm the monitored_loads sensor looks good when I view it. One thing that occurred to me was that the monitored_loads did not have a state attribute. It would just show “monitored_loads” when hovering the graph.

I’m reading my plugs with the following mqtt sensors:

  - unique_id: "server_room_consumption"
    name: "Server Room Consumption"
    state_topic: zigbee2mqtt/server_room
    device_class: "energy"
    state_class: "total_increasing"
    value_template: '{{ value_json.energy }}'
    unit_of_measurement: "kWh"

... etcetera...

Unfortunately I can’t get the monitored_loads to show up on the page. I just added it for now next to the smart plugs just to get it show on the chart, but it doesn’t. I think it may have something to do with the fact that all *_consumption sensors have a state with a float value and this template sensor does not. I also notice that those *_consumption sensors immediately show their graphs when I go to sensor info, while the template only shows a graph when I hit “Show more”. The dashboard db-energy-consumption.yaml:

views:
  - cards:
      - type: energy-date-selection
      - type: custom:sankey-chart
        show_names: true
        height: 200
        unit_prefix: k
        wide: true
        round: 2
        min_box_height: 3
        min_box_distance: 5
        show_states: true
        show_units: true
        energy_date_selection: true
        sections:
          - entities:
              - entity_id: sensor.solaredge_lifetime_energy
                name: Solar
                type: entity
                color: 'rgb(225 180 1)'
                children:
                  - sensor.p1_meter_3c39e72e77d4_total_power_export_t1
                  - total

              - entity_id: sensor.p1_meter_3c39e72e77d4_total_power_import_t1
                name: Grid
                type: entity
                color: 'rgb(229 93 102)'
                add_entities:
                  - sensor.p1_meter_3c39e72e77d4_total_power_import_t2
                children:
                  - sensor.p1_meter_3c39e72e77d4_total_power_export_t1
                  - total

          - entities:
              - entity_id: sensor.p1_meter_3c39e72e77d4_total_power_export_t1
                name: "To Grid"
                type: entity
                color: 'rgb(13 160 53)'
                add_entities:
                  - sensor.p1_meter_3c39e72e77d4_total_power_export_t2
                children: []

              - entity_id: total
                type: remaining_parent_state
                name: Total Consumed
                color: 'rgb(255 127 4)'
                children:
                  - unmonitored_loads
                  - sensor.monitored_loads
                  - sensor.garden_light_consumption
                  - sensor.desktop_consumption
                  - sensor.bed_heater_consumption
                  - sensor.freezer_small_consumption
                  - sensor.server_room_consumption
                  - sensor.work_consumption

          - entities:
              - entity_id: sensor.monitored_loads
                name: Monitored Loads
                type: entity
                attribute: monitored_loads
                color: 'rgb(58 103 158)'
              
              - entity_id: sensor.garden_light_consumption
                name: Garden Light
                type: entity
                color: 'rgb(58 103 158)'
              
              - entity_id: sensor.desktop_consumption
                name: Desktop
                color: 'rgb(58 103 158)'

              - entity_id: sensor.bed_heater_consumption
                name: Bed Heater
                color: 'rgb(58 103 158)'

              - entity_id: sensor.freezer_small_consumption
                name: Freezer
                color: 'rgb(58 103 158)'

              - entity_id: sensor.server_room_consumption
                name: Server Room
                color: 'rgb(58 103 158)'

              - entity_id: sensor.work_consumption
                name: Work Setup
                color: 'rgb(58 103 158)'

              - entity_id: unmonitored_loads
                type: remaining_parent_state
                name: Unmonitored Loads
                children: []

To recap, I want all monitored loads to have their own aggregated section, like a passhtrough section seen on other graphs here and have the monitored loads to be better visible on the right so they can make use of the entire height of the chart.

Other things I’ve been trying to do but fail miserably, is have the chart at 100% width like the very nice screenshots in this topic.

Last thing: If anybody can tell me or reference me to documentation on how to template yaml itself, that would be great. I’ve been repeating myself a lot in the configuration and I think you can do something like <<: to reuse predefined yaml sections. I have had some success on yaml lint, but HA wouldn’t accept it as valid because it thought my predefined block was an unknown integration (iirc).

I greatly appreciate any advice you guys have! Been toying with this until 4am :rofl:

I’m very nearly there but I want to use a passthrough for the “Inverter” in the 3rd column but I can’t get it working. What so I need to change/add?

type: custom:stack-in-card
title: Energy Distribution
cards:
  - type: energy-date-selection
  - type: custom:sankey-chart
    show_names: true
    unit_prefix: k
    round: 1
    wide: false
    energy_date_selection: true
    sections:
      - entities:
          - entity_id: sensor.daily_electricity_peak
            name: Day
            children:
              - daily_sum
            color: rgb(0,80,0)
          - entity_id: sensor.daily_electricity_off_peak
            name: Night
            children:
              - daily_sum
            color: rgb(0,127,0)
          - entity_id: sensor.solis_daily_generation
            name: Solar
            color: rgb(0,255,0)
            children:
              - daily_sum
          - entity_id: sensor.solis_daily_battery_discharge
            name: Battery
            color: rgb(127,255,127)
            children:
              - daily_sum
      - entities:
          - entity_id: daily_sum
            type: remaining_parent_state
            name: Total
            color: rgb(0,127,127)
            children:
              - daily_load
              - sensor.solis_daily_battery_charge
              - sensor.solis_daily_energy_exported
              - other
      - entities:
          - entity_id: daily_load
            type: remaining_child_state
            children:
              - sensor.solis_daily_backup_load
              - sensor.solis_daily_house_load
            name: Load
            color: rgb(140,80,80)
          - entity_id: other
            type: remaining_parent_state
            name: Inverter
            children:
              - other
      - entities:
          - entity_id: sensor.solis_daily_backup_load
            name: Utility / Garage
            color: rgb(80,0,0)
          - entity_id: sensor.solis_daily_house_load
            name: House
            color: rgb(150,0,0)
          - entity_id: other
            type: remaining_parent_state
            name: Inverter
          - entity_id: sensor.solis_daily_battery_charge
            name: Battery
            color: rgb(80,0,180)
          - entity_id: sensor.solis_daily_energy_exported
            name: Export
            color: blue

Very nice! Can you share the code of this dashboard?

Just change the type of the first Inverter to passthrough.

Then I get: Error: Entity not found other

Just means you need to move the ‘other’ entity to the right place. Whichever group it should be in.

This should be working (I am looking at it for the last 3 days… and can’t find anything wrong).

Can an other please have a look. I am definitely missing something…

It’s children not childeren

1 Like

That did the trick … completed missed it…

Thanks

Has anyone been able to get the autoconfigure to work?

My Energy Distribution has a fair start, so I thought it would work well with autoconfigure.

However, when I try the code from the Sankey Chart Card github page;

- type: custom:sankey-chart
  # ...any other options
  autoconfig:
    print_yaml: true # optional
    # any additional autoconfig options (listed below)

All that I get is;

Here is what it looks like in edit mode;

I’m looking to take advantage of the print_yaml that “Prints the auto generated configuration after the card so you can use it as a starting point for customization.”

Does anyone have this working, and if so, where am I messing up?

i did the same thing and used the printed yaml. worked fine. let me try a new one.

Edit.
It worked fine again.
new card, sankey, enable print yaml, save. that’s it

I don’t have a battery or low carbon FYI

1 Like

I’m trying to show how consumption splits into the categories of Transportation (EV charging) and Home (residence), the latter of which splits into Space Heating, Kitchen, and later others once I get some of it working.

So far, the entities are showing up, though no lines are visible.

type: custom:sankey-chart
title: Realtime Energy
show_names: true
min_box_height: 8
height: 500
energy_date_selection: true
sections:
  - entities:
      - entity_id: sensor.grid_import
        name: Grid Import
        color: ‘#4F00C0C’
        children:
          - entity_id: sensor.load_consumed_energy
      - entity_id: sensor.solaroutneg_wh
        name: Solar Energy
        color: '#e0b400'
        children:
          - entity_id: sensor.load_consumed_energy
          - entity_id: sensor.grid_export
      - entity_id: whatever321
        type: remaining_parent_state
        name: OtherInputs
  - entities:
      - entity_id: sensor.load_consumed_energy
        name: Total Load Consumption
      - entity_id: sensor.grid_export
        name: Grid Export
        children:
          - entity_id: sensor.transportation_consumption
          - entity_id: sensor.home
        remaining:
          name: Unmonitored
      - entity_id: Other-Consumption
        type: remaining_parent_state
        name: Other-Consumption
  - entities:
      - entity_id: sensor.transportation_consumption
        name: Transportation
        children:
          - entity_id: sensor.120v_ev_charger_total_daily_energy
          - entity_id: sensor.juicebox_energy_added
      - entity_id: sensor.home
        name: Home
        children:
          - entity_id: sensor.kitchen_load
      - entity_id: IntermediateUnmonitored
        type: remaining_parent_state
        name: Intermediate Unmonitored
  - entities:
      - entity_id: sensor.120v_ev_charger_total_daily_energy
        name: Clarity Charger
      - entity_id: sensor.juicebox_energy_added
        name: Soul Charger
      - entity_id: sensor.kitchen_load
        name: Kitchen Load
        children:
          - entity_id: sensor.refrigerator_total_daily_energy
          - entity_id: sensor.dishwasher_total_daily_energy
      - entity_id: UnmonitoredEnergy
        type: remaining_parent_state
        name: OtherUnmonitored
  - entities:
      - entity_id: sensor.refrigerator_total_daily_energy
        name: Refrigerator
      - entity_id: sensor.dishwasher_total_daily_energy
        name: Dishwasher
      - entity_id: RemainingEnergy
        type: remaining_parent_state
        name: OtherRemaining

Any mistakes jump out at anyone?

And I have tried multiple approaches to getting passthrough working;

  1. Default (no explicit entry)

  2. Adding passthrough entries in the column they are to ‘passthrough’

  3. Labeling them as passthrough in the final ‘leaf’ column (didn’t expect this to work but tried it anyway.

Currently the most recent code for the Sankey chart (below) that follows #2 approach above has the following error (though the juicebox sensor exists, is populated, ahd has been showing up);

Error: Invalid entity config {“type”:“passthrough”,“children”:[{“entity_id”:“sensor.juicebox_energy_added”}],“entity_id”:“sensor.juicebox_energy_added”}

type: custom:sankey-chart
title: Energy Categories
show_names: true
min_box_height: 8
height: 500
energy_date_selection: true
sections:
  - entities:
      - entity_id: sensor.grid_import
        name: Grid Import
        color: ‘#4F00C0C’
        children:
          - entity_id: sensor.load_consumed_energy
      - entity_id: sensor.solaroutneg_wh
        name: Solar Energy
        color: '#e0b400'
        children:
          - entity_id: sensor.load_consumed_energy
          - entity_id: sensor.grid_export
      - entity_id: whatever321
        type: remaining_parent_state
        name: OtherInputs
  - entities:
      - entity_id: sensor.load_consumed_energy
        name: Total Load Consumption
      - entity_id: sensor.grid_export
        name: Grid Export
        children:
          - entity_id: sensor.transportation_consumption
          - entity_id: sensor.home
        remaining:
          name: Unmonitored
      - entity_id: Other-Consumption
        type: remaining_parent_state
        name: Other-Consumption
  - entities:
      - entity_id: sensor.transportation_consumption
        name: Transportation
        children:
          - entity_id: sensor.120v_ev_charger_total_daily_energy
          - entity_id: sensor.juicebox_energy_added
      - entity_id: sensor.home
        name: Home
        children:
          - entity_id: sensor.kitchen_load
          - entity_id: sensor.space_heating
      - entity_id: IntermediateUnmonitored
        type: remaining_parent_state
        name: Intermediate Unmonitored
  - entities:
      - entity_id: sensor.juicebox_energy_added
        type: passthrough
        children:
          - entity_id: sensor.juicebox_energy_added
      - entity_id: sensor.120v_ev_charger_total_daily_energy
        type: passthrough
        children:
          - entity_id: sensor.120v_ev_charger_total_daily_energy
      - entity_id: sensor.kitchen_load
        name: Kitchen Load
        children:
          - entity_id: sensor.refrigerator_total_daily_energy
          - entity_id: sensor.dishwasher_total_daily_energy
      - entity_id: sensor.space_heating
        name: Space Heating
      - entity_id: UnmonitoredEnergy
        type: remaining_parent_state
        name: OtherUnmonitored
  - entities:
      - entity_id: sensor.juicebox_energy_added
        name: Level 2 Charger
      - entity_id: sensor.120v_ev_charger_total_daily_energy
        name: Level 1 Charger
      - entity_id: sensor.refrigerator_total_daily_energy
        name: Refrigerator
      - entity_id: sensor.dishwasher_total_daily_energy
        name: Dishwasher
      - entity_id: sensor.heat_pump_kwh
        name: Heat Pump
      - entity_id: sensor.furnace_kwh
        name: Furnace
      - entity_id: RemainingEnergy
        type: remaining_parent_state
        name: OtherRemaining

Please tell me what am I missing?

Update to above, determined and resolved the issue. See Update 2 for further issues.

I had incorrectly listed children entities starting with “entity_id:” which is incorrect. My chart now on this mostly rainy/cloudy/snowy day with the woodstove going;

image

Associated code;

type: custom:sankey-chart
title: Energy Categories
show_names: true
min_box_height: 8
height: 500
energy_date_selection: true
sections:
  - entities:
      - entity_id: sensor.grid_import
        name: Grid Import
        color: purple
        children:
          - sensor.load_consumed_energy
      - entity_id: sensor.solaroutneg_wh
        name: Solar Energy
        color: '#e0b400'
        children:
          - sensor.load_consumed_energy
          - sensor.grid_export
      - entity_id: whatever321
        type: remaining_parent_state
        name: OtherInputs
  - entities:
      - entity_id: sensor.load_consumed_energy
        name: Total Load Consumption
        children:
          - sensor.transportation_consumption
          - sensor.home_load
      - entity_id: sensor.grid_export
        name: Grid Export
      - entity_id: Other-Consumption
        type: remaining_parent_state
        name: Other-Consumption
  - entities:
      - entity_id: sensor.transportation_consumption
        name: Transportation
        children:
          - sensor.120v_ev_charger_total_daily_energy
          - sensor.juicebox_energy_added
      - entity_id: sensor.home_load
        name: Home
        children:
          - sensor.kitchen_load
          - sensor.space_heating
      - entity_id: IntermediateUnmonitored
        type: remaining_parent_state
        name: Intermediate Unmonitored
  - entities:
      - entity_id: sensor.juicebox_energy_added
        type: passthrough
        children:
          - sensor.juicebox_energy_added
      - entity_id: sensor.120v_ev_charger_total_daily_energy
        type: passthrough
        children:
          - sensor.120v_ev_charger_total_daily_energy
      - entity_id: sensor.kitchen_load
        name: Kitchen
        children:
          - sensor.refrigerator_total_daily_energy
          - sensor.dishwasher_total_daily_energy
      - entity_id: sensor.space_heating
        name: Space Heating
        children:
          - sensor.heat_pump_kwh
          - sensor.furnace_kwh
      - entity_id: UnmonitoredEnergy
        type: remaining_parent_state
        name: OtherUnmonitored
  - entities:
      - entity_id: sensor.juicebox_energy_added
        name: Level 2 Charger
      - entity_id: sensor.120v_ev_charger_total_daily_energy
        name: Level 1 Charger
      - entity_id: sensor.refrigerator_total_daily_energy
        name: Refrigerator
      - entity_id: sensor.dishwasher_total_daily_energy
        name: Dishwasher
      - entity_id: sensor.heat_pump_kwh
        name: Heat Pump
      - entity_id: sensor.furnace_kwh
        name: Furnace
      - entity_id: RemainingEnergy
        type: remaining_parent_state
        name: OtherRemaining

Now I can proceed adding all the other appliances and circuits I am (and will be) tracking, as well as figuring out the right was to use remaining_parent_state.

Update 2: Alas, the inability to create daily-resetting energy entities seems to be messing up the daily values in the chart. And changing a template from kWh to Wh to get all the algorithm components in the same measurement unit doesn’t seem to actually change the range, it just messes up the value. For example, Transportation_Consumption should be 22Wh instead of 22,000 Wh, which the History shows, which is not reflected in the value in the chart.

So I will likely have to start from scratch if I ever find a way to create daily-resetting energy entities, and advise anyone looking at my chart code above to avoid relying on it for hints and clues.

is there a way to combine 2 separate parts?
my dryer for example, is 240v so uses both lines. it would be great for it to show half from Line1 half from Line 2

You can have it as a child of both but it won’t be split in half. It will be mostly random.
You can create 2 templates in HA “Dryer half 1” & “Dryer half 2” and have “Dryer” as a child of those but that would add new layer where the halves are combined.
Once #8 is done you would be able to do this without an extra layer but you would still need the template entities to say how much comes from each line.

yeah, the visual there, where its selected as a child for each, isnt clear. it makes Other1 small, and leaves the Other2 big (instead of equal out of both) so i ended up creating 2 new entities for each in iotawatt (same idea as the template sensor).

so now i have Line 1, Line 2, BothLines 240v. and then now that subtract works, i subtracted the half of each from both of the Others, and uses the full entity under BothLines

i think you are right about #8 but for now my solution seems to look and feel fine. thanks for the reply. wasnt sure if there was some better way to do it.