Auto sorting of power monitors

First thing, I see posts with what looks to be a screenshot of the yaml code but is able to be copied from the top right corner, how do I do this for my post?, I will add it this to this help request to see what exsist and what I can add to do what I would like to do.

I have a vertical stack of custom bar cards to show me the real time power consumption status of the power hungry item in my home, I would like it to automatically sort them so the highest to lowest is from top to bottom, how would the code look in relation to the existing code I have currently? I will post the configuration when I know how to do it without it being a screenshot.

Cheers for any help.

type: custom:bar-card
icon: mdi:battery
entities:
  - entity: sensor.solahart_power
    name: Solahart
  - entity: sensor.spa_power
    name: Spa
  - entity: sensor.living_ac_power
    name: Living AC
  - entity: sensor.master_ac_energy_power
    name: Master AC
  - entity: sensor.bailey_s_ac_energy_power
    name: Bailey's AC
  - entity: sensor.rhys_s_ac_energy_power
    name: Rhys's AC
  - entity: sensor.declans_ac_energy_power
    name: Declan's AC
  - entity: sensor.washing_machine_power
    name: Washing Machine
  - entity: sensor.dishwasher_power
    name: Dishwasher
  - entity: sensor.oven_power
    name: Wall Oven
  - entity: sensor.cooktop_power
    name: Induction Cooktop
  - entity: sensor.ice_machine_power
    name: Ice Machine
min: 0
max: 4000
positions:
  icon: 'off'
  indicator: null
  name: inside
severity:
  - color: Red
    from: 2500
    to: 5000
  - color: orange
    from: 1500
    to: 2499
  - color: green
    from: 1000
    to: 1499
  - color: null
    from: 100
    to: 999
  - color: 'n'
    from: -5
    to: 15
sort:
  - position: null
    from: 4000
    to: 0
columns: 1
limit_value: true

Use the “Preformatted text” button…

That button can be hidden under the cog icon button on mobile devices. There is also an alternative method and a lot of other useful information in the Forurn FAQ.

Tried it and all I get is this below, not in a yaml form, what am I doing wrong?


type:%20custom%3Abar-card%0Aicon%3A%20mdi%3Abattery%0Aentities%3A%0A%20%20-%20entity%3A%20sensor.solahart_power%0A%20%20%20%20name%3A%20Solahart%0A%20%20-%20entity%3A%20sensor.spa_power%0A%20%20%20%20name%3A%20Spa%0A%20%20-%20entity%3A%20sensor.living_ac_power%0A%20%20%20%20name%3A%20Living%20AC%0A%20%20-%20entity%3A%20sensor.master_ac_energy_power%0A%20%20%20%20name%3A%20Master%20AC%0A%20%20-%20entity%3A%20sensor.bailey_s_ac_energy_power%0A%20%20%20%20name%3A%20Bailey's%20AC%0A%20%20-%20entity%3A%20sensor.rhys_s_ac_energy_power%0A%20%20%20%20name%3A%20Rhys's%20AC%0A%20%20-%20entity%3A%20sensor.declans_ac_energy_power%0A%20%20%20%20name%3A%20Declan's%20AC%0A%20%20-%20entity%3A%20sensor.washing_machine_power%0A%20%20%20%20name%3A%20Washing%20Machine%0A%20%20-%20entity%3A%20sensor.dishwasher_power%0A%20%20%20%20name%3A%20Dishwasher%0A%20%20-%20entity%3A%20sensor.oven_power%0A%20%20%20%20name%3A%20Wall%20Oven%0A%20%20-%20entity%3A%20sensor.cooktop_power%0A%20%20%20%20name%3A%20Induction%20Cooktop%0A%20%20-%20entity%3A%20sensor.ice_machine_power%0A%20%20%20%20name%3A%20Ice%20Machine%0Amin%3A%200%0Amax%3A%204000%0Apositions%3A%0A%20%20icon%3A%20'off'%0A%20%20indicator%3A%20null%0A%20%20name%3A%20inside%0Aseverity%3A%0A%20%20-%20color%3A%20Red%0A%20%20%20%20from%3A%202500%0A%20%20%20%20to%3A%205000%0A%20%20-%20color%3A%20orange%0A%20%20%20%20from%3A%201500%0A%20%20%20%20to%3A%202499%0A%20%20-%20color%3A%20green%0A%20%20%20%20from%3A%201000%0A%20%20%20%20to%3A%201499%0A%20%20-%20color%3A%20null%0A%20%20%20%20from%3A%20100%0A%20%20%20%20to%3A%20999%0A%20%20-%20color%3A%20'n'%0A%20%20%20%20from%3A%20-5%0A%20%20%20%20to%3A%2015%0Asort%3A%0A%20%20-%20position%3A%20null%0A%20%20%20%20from%3A%204000%0A%20%20%20%20to%3A%200%0Acolumns%3A%201%0Alimit_value%3A%20true%0A

Don’t use the copy button in the three dots icon at the bottom of the card.

Click in the yaml view of the card then Ctrl + A to select everything, then Ctrl + C to copy the YAML, then Ctrl + V to paste in the forum. You can also probably do all that with your right click context menu in your web browser instead of the keyboard shortcuts.

1 Like

I’m actually on my phone, I already tried highlighting all then copy, then paste, if I paste it into a note pad, it looks ok but not tabbed correctly as yaml looks, yet while the copy is still saved in the phones clip board, I paste the same info here, and I get what you can see above? It’s an iPhone I’m on, is there some other way to do it, the yaml is too long for a single screenshot?

Cheers

Do not post screenshots. We can not easily edit them to help you like we can with yaml.

Yeah it won’t work from your phone, use a desktop PC.

1 Like

Make sure there is a blank line above and below your code and include them in the marking before clicking the </> icon

1 Like

Nah it’s not that. Copying from the HA app copies as percent encoded for some reason (at least it does on iOS).

2 Likes

Thanks, did it fro PC when I got home.

Any help re auto sorting fro highest real time on yp to lowest on the bottom would be much arreciated I’m a bit stuck with that bit>

Cheers for anyone’s help.

I use the third party auto-entities card to do that, pretty sure it won’t work with bar card though:

type: custom:auto-entities
card:
  type: entities
  title: Currently Drawing Power
filter:
  include:
    - entity_id: sensor.*_power
  exclude:
    - state: '0.0'
    - state: '-0.0'
    - state: '0'
    - state: '-0'
    - entity_id: sensor.*grid*
    - entity_id: sensor.*lp20*
    - entity_id: sensor.*sb6*
    - entity_id: sensor.import
    - entity_id: sensor.self_total
    - entity_id: sensor.*solar*
    - entity_id: sensor.*ups_*
sort:
  method: state
  numeric: true
  reverse: true

Here is how it will work with the Bar-Card

The sort is based on the “method: state” - as that is the state of the entity

My bar-card has some additional code to make it pretty - so the content under “card-mod” can be omitted -

type: custom:auto-entities
card:
  type: custom:bar-card
  title: ''
  width: null
  icon: mdi:battery
  align: split
  columns: 1
  decimal: ''
  height: 30
  max: 100
  unit_of_measurement: '%'
  animation:
    state: 'off'
    speed: 2
  severity:
    - from: '0'
      to: '20'
      color: red
    - from: '21'
      to: '40'
      color: orange
    - from: '41'
      to: '49'
      color: yellow
    - from: '50'
      to: '100'
      color: green
      hide: false
  card_mod:
    style: |-
      bar-card-value {
        margin-right: 25px;
        font-size: 13px;
        font-weight: bold;
       }
      bar-card-backgroundbar { 
       border-radius: 12px;
       margin-top: 9px;
       background: grey;
       opacity: 50%;
      } 
      bar-card-currentbar { 
      border-radius: 12px;
      margin-top: 9px;
      }
      bar-card-contentbar {
        margin-top: 9px;
        margin-left: 8px;
      }
entities: []
sort:
  method: state
  numeric: true
  reverse: false
filter:
  include:
    - entity_id: sensor.*battery
  exclude: null

image

1 Like

Yeh thanks tom_I, I got it working with custom bar card as well including severity coloring as well, but wanted to wait till I got hoe to be able to copy the yaml to this reply. Also attached is a screen shot. The only thing left to try and clean it up is some kind of exclusion for states of 0 to 15w so that items dont show up with just noise of 3.2w and 8w, but all in all, seems to work well.

Doh! light in my head just switched on, I was over thinking it, rathe than trying to exclude a range from 0.1 to 15.0, I just added this - state: ‘>15’ in the exclusions list to eliminate any sensors with insignificant readings becoming visible. So now its doing everything I wanted it to do. Thanks to all the responces.

type: custom:auto-entities
filter:
  include:
    - entity_id: sensor.*_power
  exclude:
    - state: '0.0'
    - state: '-0.0'
    - state: '0'
    - state: '-0'
    - state: '>15'
    - entity_id: sensor.energy_monitor_channel_1_power
    - entity_id: sensor.energy_monitor_channel_2_power
    - entity_id: sensor.*grid*
    - entity_id: sensor.*lp20*
    - entity_id: sensor.*sb6*
    - entity_id: sensor.import
    - entity_id: sensor.self_total
    - entity_id: sensor.*solar*
    - entity_id: sensor.*ups_*
sort:
  method: state
  numeric: true
  reverse: true
card:
  type: custom:bar-card
  min: 0
  max: 4000
  severity:
    - color: Red
      from: 2500
      to: 5000
    - color: orange
      from: 1500
      to: 2499
    - color: green
      from: 1000
      to: 1499
    - color: null
      from: 100
      to: 999
    - color: 'n'
      from: -5
      to: 15
  limit_value: true
  positions:
    icon: 'off'
    indicator: null
    name: inside

1 Like