lovelace-mushroom icon indicating copy to clipboard operation
lovelace-mushroom copied to clipboard

feat(graph): add graph card

Open piitaya opened this issue 2 years ago • 6 comments

Fixes https://github.com/piitaya/lovelace-mushroom/issues/74

TODO : merge graph and entity card for simplicity.

piitaya avatar May 08 '22 19:05 piitaya

If someone, like me, needs this card, they can temporarily use a combination of mini-graph-card and stack in card as a workaround. It's not a perfect solution, but it doesn't clash too much with the rest of the dashboard. Below is the code to obtain a card similar to the one not yet implemented:

type: custom:stack-in-card
cards:
  - type: custom:mushroom-template-card
    primary: Temperatura
    secondary: '{{ states(entity) }} °C'
    icon: mdi:thermometer
    icon_color: |-
      {% if is_state(entity, 'unknown') %}
          
      {% elif states(entity) | float >= 45 %}
         red
      {% elif states(entity) | float >= 42 %}
         orange
      {% elif states(entity) | float >= 39 %}
         amber
      {% elif states(entity) | float >= 36 %}
         yellow
      {% else %}
         green
      {% endif %}
    entity: sensor.cpu_temperature
  - type: custom:mini-graph-card
    entities:
      - sensor.cpu_temperature
    group: true
    show:
      icon: false
      name: false
      state: false
    hours_to_show: 6
    points_per_hour: 3
    color_thresholds:
      - value: 0
        color: '#47a04b'
      - value: 36
        color: '#ffeb3b'
      - value: 39
        color: '#ffc107'
      - value: 42
        color: '#ff9800'
      - value: 45
        color: '#f44336'

The result: image

alessandroias avatar May 24 '22 15:05 alessandroias

Hey @alessandroias

Really thank you for sharing, I've took your code and updated it to my needs. I'm sharing it below.

type: horizontal-stack
cards:
  - type: custom:stack-in-card
    cards:
      - type: custom:mushroom-template-card
        primary: Temperatura
        secondary: '{{ states(entity) }} °C'
        icon: mdi:thermometer
        icon_color: |-
          {% if is_state(entity, 'unknown') %}
            disabled
          {% elif states(entity) | float >= 28 %}
             red
          {% elif states(entity) | float >= 25 %}
             orange
          {% elif states(entity) | float >= 23 %}
            amber
          {% elif states(entity) | float >= 19 %}
             light-blue
          {% else %}
             blue
          {% endif %}
        entity: sensor.quarto_temperatura
      - type: custom:mini-graph-card
        entities:
          - sensor.quarto_temperatura
        group: true
        show:
          icon: false
          name: false
          state: false
        hours_to_show: 6
        points_per_hour: 3
        color_thresholds:
          - value: 0
            color: '#007aff'
          - value: 19
            color: '#5ac8fa'
          - value: 23
            color: '#ffcc00'
          - value: 25
            color: '#ff9500'
          - value: 28
            color: '#ff3b30'
  - type: custom:stack-in-card
    cards:
      - type: custom:mushroom-template-card
        primary: Umidade
        secondary: '{{ states(entity) }} %'
        icon: mdi:water-percent
        icon_color: |-
          {% if is_state(entity, 'unknown') %}
            disabled
          {% elif states(entity) | float >= 70 %}
             blue
          {% elif states(entity) | float >= 50 %}
             green
          {% else %}
             red
          {% endif %}
        entity: sensor.quarto_umidade
      - type: custom:mini-graph-card
        entities:
          - sensor.quarto_umidade
        group: true
        show:
          icon: false
          name: false
          state: false
        hours_to_show: 6
        points_per_hour: 3
        color_thresholds:
          - value: 0
            color: '#ff3b30'
          - value: 50
            color: '#4cd964'
          - value: 70
            color: '#007aff'

The results: image

raphaeleduardo42 avatar Jun 04 '22 23:06 raphaeleduardo42

Thanks for the template @raphaeleduardo42 but it does seem to have an error. When the temperatur is at for example 22° the graph and the icon dont have the same color. The icon is light-blue and the graph is amber in this case. Any idea whats wrong?

2022-06-09_09h40_19

type: custom:stack-in-card
cards:
  - type: custom:mushroom-template-card
    primary: Temperatur
    secondary: '{{ states(entity) }} °C'
    icon: mdi:thermometer
    icon_color: |-
      {% if is_state(entity, 'unknown') %}
        disabled
      {% elif states(entity) | float >= 28 %}
         red
      {% elif states(entity) | float >= 25 %}
         orange
      {% elif states(entity) | float >= 23 %}
        amber
      {% elif states(entity) | float >= 19 %}
         light-blue
      {% else %}
         blue
      {% endif %}
    entity: sensor.thermometer_temperature
  - type: custom:mini-graph-card
    entities:
      - sensor.thermometer_temperature
    group: true
    show:
      icon: false
      name: false
      state: false
    hours_to_show: 6
    points_per_hour: 3
    color_thresholds:
      - value: 0
        color: '#007aff'
      - value: 19
        color: '#5ac8fa'
      - value: 23
        color: '#ffcc00'
      - value: 25
        color: '#ff9500'
      - value: 28
        color: '#ff3b30'

lunatik98 avatar Jun 09 '22 07:06 lunatik98

The repository decluttering-card can also be used to create "templates". This can make adding multiple sensors a lot easier without needing to repeat the same code every time:

Example that was added on top of the Lovelace configuration:

decluttering_templates:
  mushroom-graph-card:
    card:
      type: custom:stack-in-card
      cards:
        - type: custom:mushroom-template-card
          primary: '[[name]]'
          secondary: '{{ states(entity) }} [[unit]]'
          icon: '[[icon]]'
          icon_color: '[[color]]'
          entity: '[[entity]]'
          tap_action:
            action: more-info
          hold_action:
            action: none
          double_tap_action:
            action: none
        - type: custom:mini-graph-card
          entities:
            - '[[entity]]'
          line_color: '[[color]]'
          group: true
          show:
            icon: false
            name: false
            state: false
views:
 - ...

How the template can be used in a card:

type: horizontal-stack
cards:
  - type: custom:decluttering-card
    template: mushroom-graph-card
    variables:
      - name: Temperatur
      - unit: °C
      - color: red
      - icon: mdi:thermometer
      - entity: sensor.aqara_sensor_schlafzimmer_temperature

  - type: custom:decluttering-card
    template: mushroom-graph-card
    variables:
      - name: Humidity
      - unit: '%'
      - color: blue
      - icon: mdi:water-percent
      - entity: sensor.aqara_sensor_schlafzimmer_humidity

  - type: custom:decluttering-card
    template: mushroom-graph-card
    variables:
      - name: Pressure
      - unit: hPa
      - color: grey
      - icon: mdi:car-cruise-control
      - entity: sensor.aqara_sensor_schlafzimmer_pressure

This way, you can kind of "fake" a new card and only need to provide the variables to change the values.

mwantia avatar Aug 02 '22 22:08 mwantia

Hi Im curious, what is holding this back?

shreyasajj avatar Aug 03 '22 14:08 shreyasajj

Any news on this?

hendrikbl avatar Sep 08 '22 06:09 hendrikbl

This feature would be really awesome

bartaspoz avatar Nov 09 '22 23:11 bartaspoz