Ideas to solution wanted

I have the following scenario. I have many Power measurement devices.

I need to show a dashboard, where devices that meets specific values, either show or turns red.

The devices messured is CNC machines. In idle, they consume around 200 watts, in engaged they use up to 900 watts, and in running above 1000 watts. So I need to show the engaged machines, as this state shouldn’t happen.

I’ve been looking on conditional cards, but seems like its either a specific value or state. Also been looking at Card mod, but my abilities aren’t sufficient to create such CSS.

Any help would be appreciated.

When you say “many”, are we talking about ~10, ~50, ~250, ~1000??

This depends on the card you are using. Many of those supports templates to define icons and colors (and visibility), so you could select different colors based on the power range.

If we are talking about just a few devices, you can also create a template sensor for each of your devices to track it’s state (off, idle/armed, running, etc).

approx 40.

But I got this working

card_mod:
  style: |
    ha-card {
      color: {% if states('sensor.204_energy_usage')|int < 250 %} green {% elif states('sensor.204_energy_usage')|int < 1000 %} red {% else %} initial {% endif %}

1 Like

So, there are multiple ways of doing this (this is the beauty of Home Assistant) and I will try to share some here. Hopefully other people will come with more ideas and then you can get inspired and find what works better for you.

Card-mod is probably one of the most flexible and powerful ways, but it can be an issue if you are not confortable with CSS.

For cases like this where you will have to use templates, the Mushroom Template Card is also great, and you will be able to setup one and then duplicate that 40 times, just change one line (your sensor id). It might be a good option for 40 sensors:

Try this:

type: custom:mushroom-template-card
entity: sensor.204_energy_usage
primary: '{{ state_attr(entity, ''friendly_name'') }}'
secondary: |-
  {%- set power = states(entity) | float(0) %} {%- if power < 100 %}
    Stopped
  {%- elif power < 250 %}
    Idle
  {%- elif power < 1000 %} 
    Engaged
  {%- else %}
    Running
  {%- endif %}
  {{ power | round(1) }}W
icon: mdi:engine
icon_color: |-
  {% set power = states(entity) | float(0) %} {% if power < 100 %}
    blue
  {% elif power < 250 %}
    green
  {% elif power < 1000 %} 
    orange
  {% else %}
    red
  {% endif %}
fill_container: true
multiline_secondary: true
tap_action:
  action: more-info
hold_action:
  action: more-info
layout: vertical

If you go this way, either with Mushroom or other single-entity card, you will need one card per CNC so you may want organize those inside a grid card, so you can define the number or cards per row based on your screen size:

type: grid
cards:
  - type: custom:mushroom-template-card
    entity: sensor.201_energy_usage
    primary: '{{ state_attr(entity, ''friendly_name'') }}'
    secondary: |-
      {%- set power = states(entity) | float(0) %} {%- if power < 100 %}
        Stopped
      {%- elif power < 250 %}
        Idle
      {%- elif power < 1000 %} 
        Engaged
      {%- else %}
        Running
      {%- endif %}
      {{ power | round(1) }}W
    icon: mdi:engine
    icon_color: |-
      {% set power = states(entity) | float(0) %} {% if power < 100 %}
        blue
      {% elif power < 250 %}
        green
      {% elif power < 1000 %} 
        orange
      {% else %}
        red
      {% endif %}
    fill_container: true
    multiline_secondary: true
    tap_action:
      action: more-info
    hold_action:
      action: more-info
    layout: vertical
  - type: custom:mushroom-template-card
    entity: sensor.202_energy_usage
    primary: '{{ state_attr(entity, ''friendly_name'') }}'
    secondary: |-
      {%- set power = states(entity) | float(0) %} {%- if power < 100 %}
        Stopped
      {%- elif power < 250 %}
        Idle
      {%- elif power < 1000 %} 
        Engaged
      {%- else %}
        Running
      {%- endif %}
      {{ power | round(1) }}W
    icon: mdi:engine
    icon_color: |-
      {% set power = states(entity) | float(0) %} {% if power < 100 %}
        blue
      {% elif power < 250 %}
        green
      {% elif power < 1000 %} 
        orange
      {% else %}
        red
      {% endif %}
    fill_container: true
    multiline_secondary: true
    tap_action:
      action: more-info
    hold_action:
      action: more-info
    layout: vertical
  - type: custom:mushroom-template-card
    entity: sensor.203_energy_usage
    primary: '{{ state_attr(entity, ''friendly_name'') }}'
    secondary: |-
      {%- set power = states(entity) | float(0) %} {%- if power < 100 %}
        Stopped
      {%- elif power < 250 %}
        Idle
      {%- elif power < 1000 %} 
        Engaged
      {%- else %}
        Running
      {%- endif %}
      {{ power | round(1) }}W
    icon: mdi:engine
    icon_color: |-
      {% set power = states(entity) | float(0) %} {% if power < 100 %}
        blue
      {% elif power < 250 %}
        green
      {% elif power < 1000 %} 
        orange
      {% else %}
        red
      {% endif %}
    fill_container: true
    multiline_secondary: true
    tap_action:
      action: more-info
    hold_action:
      action: more-info
    layout: vertical
  - type: custom:mushroom-template-card
    entity: sensor.204_energy_usage
    primary: '{{ state_attr(entity, ''friendly_name'') }}'
    secondary: |-
      {%- set power = states(entity) | float(0) %} {%- if power < 100 %}
        Stopped
      {%- elif power < 250 %}
        Idle
      {%- elif power < 1000 %} 
        Engaged
      {%- else %}
        Running
      {%- endif %}
      {{ power | round(1) }}W
    icon: mdi:engine
    icon_color: |-
      {% set power = states(entity) | float(0) %} {% if power < 100 %}
        blue
      {% elif power < 250 %}
        green
      {% elif power < 1000 %} 
        orange
      {% else %}
        red
      {% endif %}
    fill_container: true
    multiline_secondary: true
    tap_action:
      action: more-info
    hold_action:
      action: more-info
    layout: vertical
  - type: custom:mushroom-template-card
    entity: sensor.205_energy_usage
    primary: '{{ state_attr(entity, ''friendly_name'') }}'
    secondary: |-
      {%- set power = states(entity) | float(0) %} {%- if power < 100 %}
        Stopped
      {%- elif power < 250 %}
        Idle
      {%- elif power < 1000 %} 
        Engaged
      {%- else %}
        Running
      {%- endif %}
      {{ power | round(1) }}W
    icon: mdi:engine
    icon_color: |-
      {% set power = states(entity) | float(0) %} {% if power < 100 %}
        blue
      {% elif power < 250 %}
        green
      {% elif power < 1000 %} 
        orange
      {% else %}
        red
      {% endif %}
    fill_container: true
    multiline_secondary: true
    tap_action:
      action: more-info
    hold_action:
      action: more-info
    layout: vertical
  - type: custom:mushroom-template-card
    entity: sensor.206_energy_usage
    primary: '{{ state_attr(entity, ''friendly_name'') }}'
    secondary: |-
      {%- set power = states(entity) | float(0) %} {%- if power < 100 %}
        Stopped
      {%- elif power < 250 %}
        Idle
      {%- elif power < 1000 %} 
        Engaged
      {%- else %}
        Running
      {%- endif %}
      {{ power | round(1) }}W
    icon: mdi:engine
    icon_color: |-
      {% set power = states(entity) | float(0) %} {% if power < 100 %}
        blue
      {% elif power < 250 %}
        green
      {% elif power < 1000 %} 
        orange
      {% else %}
        red
      {% endif %}
    fill_container: true
    multiline_secondary: true
    tap_action:
      action: more-info
    hold_action:
      action: more-info
    layout: vertical

If you want to clean-up your screen a bit (as I understood you just wanna show the ones thar are engaged, right?) you can create a template sensor for each one of your CNCs and then use that in a conditional card, so you hide the ones that are not engaged.

The template sensor will look like:

template:
  - sensor:
    - name: 204_energy_usage_status
      state: >-
        {%- set power = states(entity) | float(0) %}
        {%- if power < 100 %}
          Stopped
        {%- elif power < 250 %}
          Idle
        {%- elif power < 1000 %} 
          Engaged
        {%- else %}
          Running
        {%- endif %}

Than you can have a conditional card which will only be visible if the CNC is engaged (or when you are in edit mode). It would be like this:

type: conditional
conditions:
  - entity: sensor.204_energy_usage_status
    state: Engaged
card:
  type: custom:mushroom-template-card
  entity: sensor.204_energy_usage
  primary: '{{ state_attr(entity, ''friendly_name'') }}'
  secondary: |-
    {%- set power = states(entity) | float(0) %} {%- if power < 100 %}
      Stopped
    {%- elif power < 250 %}
      Idle
    {%- elif power < 1000 %} 
      Engaged
    {%- else %}
      Running
    {%- endif %}
    {{ power | round(1) }}W
  icon: mdi:engine
  icon_color: |-
    {% set power = states(entity) | float(0) %} {% if power < 100 %}
      blue
    {% elif power < 250 %}
      green
    {% elif power < 1000 %} 
      orange
    {% else %}
      red
    {% endif %}
  fill_container: true
  multiline_secondary: true
  tap_action:
    action: more-info
  hold_action:
    action: more-info
  layout: vertical
1 Like

All those options above will require you creating one card per CNC, which can be some work, specially if you are planning to expand in the future.

One option is using some card which supports many entities at the same time. I use the Flex table card in one of my dashboards. It is quite flexible to select multiple sensors and work with the data on each column of a table. Take a look:

type: custom:flex-table-card
title: Power Consumption (Top 5)
entities:
  include: sensor.*_power(_[0-9]+)?
  exclude:
    - sensor.*total_power(_[0-9]+)?
    - sensor.all_*
    - sensor.*_all_*
columns:
  - data: friendly_name
    name: Entity name
    modify: >-
      x.replace("- Power", "").replace("- power", "").replace("Power",
      "").replace("power", "")
  - data: state
    name: Power
    suffix: W
    fmt: number
    align: right
    modify: Math.round(x)
sort_by: state-
max_rows: 5
clickable: true

In your case, it would probably be something like this:

type: custom:flex-table-card
title: Power Consumption (Top 5)
entities:
  include: sensor.*_energy_usage(_[0-9]+)?
columns:
  - data: friendly_name
    name: CNC
  - data: state
    name: Power
    suffix: W
    fmt: number
    align: right
    modify: Math.round(x) 
sort_by: state-
clickable: true

And we probably can play with the modify in order to show the status (idle, engeged, etc.).

There is another couple of cards you can use:

type: custom:auto-entities
show_empty: false
sort:
  method: state
  numeric: true
  reverse: true
card:
  type: custom:bar-card
  title: CNC machines
  positions:
    icon: 'off'
  height: 20px
  min: 0
  max: 1250
  severity:
    - color: red
      from: 1000
      to: 99999
    - color: orange
      from: 250
      to: 1000
    - color: green
      from: 100
      to: 250
    - color: blue
      from: 0
      to: 100
filter:
  include:
    - entity_id: sensor.*_energy_usage
  exclude:
    - state: unavailable
    - state: '0.0'
    - state: '0'

For this one I was inspired by this post from @Holdestmade. It’s nice to see how good ideas spreads fast over here… :smiley:

1 Like