# \[Custom-card\] Plotly

**URL:** <https://forum.hacf.fr/t/custom-card-plotly/20334>\
**Category:** BlaBlaBla & Suggestions\
**Tags:** custom-card\
**Created:** [Janvier 30, 2023, 12:08 UTC](https://forum.hacf.fr/t/custom-card-plotly/20334 "2023-01-30T12:08:18Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![FillR2](https://forum.hacf.fr/user_avatar/forum.hacf.fr/fillr2/32/14398_2.png) [@FillR2](https://forum.hacf.fr/u/FillR2)\
**Post date:** [Janvier 30, 2023, 12:08 UTC](https://forum.hacf.fr/t/custom-card-plotly/20334/1 "2023-01-30T12:08:19Z")

</div>

Ca a l’air sympa cette carte, je me demande si certains l’ont déjà utilisée ?

> **[GitHub - dbuezas/lovelace-plotly-graph-card: Highly customisable Lovelace...](https://github.com/dbuezas/lovelace-plotly-graph-card)**
>
> Highly customisable Lovelace card to plot interactive graphs. Brings scrolling, zooming, and much more! - GitHub - dbuezas/lovelace-plotly-graph-card: Highly customisable Lovelace card to plot inte...

[![](https://user-images.githubusercontent.com/777196/215200293-d2655190-1ae3-458f-a42a-cb85383b67db.png) ](https://user-images.githubusercontent.com/777196/215200293-d2655190-1ae3-458f-a42a-cb85383b67db.png)

> **[Discussions · Show And Tell · dbuezas/lovelace-plotly-graph-card](https://github.com/dbuezas/lovelace-plotly-graph-card/discussions/categories/show-and-tell)**
>
> Highly customisable Lovelace card to plot interactive graphs. Brings scrolling, zooming, and much more! - Discussions · Show And Tell · dbuezas/lovelace-plotly-graph-card

---

<div class="post-metadata">

**Author:** ![Pulpy-Luke](https://forum.hacf.fr/user_avatar/forum.hacf.fr/pulpy-luke/32/137426_2.png) [@Pulpy-Luke](https://forum.hacf.fr/u/Pulpy-Luke)\
**Post date:** [Janvier 30, 2023, 12:37 UTC](https://forum.hacf.fr/t/custom-card-plotly/20334/2 "2023-01-30T12:37:02Z")

</div>

Salut;  
J’ai souvent celle-ci (et pas apex), question de gout

---

<div class="post-metadata">

**Author:** ![FillR2](https://forum.hacf.fr/user_avatar/forum.hacf.fr/fillr2/32/14398_2.png) [@FillR2](https://forum.hacf.fr/u/FillR2)\
**Post date:** [Janvier 30, 2023, 12:50 UTC](https://forum.hacf.fr/t/custom-card-plotly/20334/3 "2023-01-30T12:50:09Z")

</div>

Quelques exemples pour donner des idées ? 🙂

---

<div class="post-metadata">

**Author:** ![Pulpy-Luke](https://forum.hacf.fr/user_avatar/forum.hacf.fr/pulpy-luke/32/137426_2.png) [@Pulpy-Luke](https://forum.hacf.fr/u/Pulpy-Luke)\
**Post date:** [Janvier 30, 2023, 5:06 UTC](https://forum.hacf.fr/t/custom-card-plotly/20334/4 "2023-01-30T17:06:43Z")

</div>

Pour définir un période par défaut, lissage, bouton zoom/etc masqué mais dispo.  
En version 2, la 3 n'est pas encore installée

 ![image](https://forum.hacf.fr/uploads/default/original/3X/1/5/1556e5a64178c97716a500eb7eaefe8e9da2e6e4.png)

```auto
      - type: custom:decluttering-card
        template: ploty_generic
        variables:
          - window: 30
          - show: 48
          - right_margin: 55
          - entities:
              - entity: sensor.processor_temperature
                name: Température
                line:
                  color: orange
              - entity: sensor.processor_use_percent
                name: Utilisation
                line:
                  color: red

```

et le template

```auto
  ploty_generic:
    default:
      color_scheme: dutch_field
      right_margin: 5
    element:
      type: custom:plotly-graph
      color_scheme: '[[color_scheme]]'
      fillcolor: rgba(168, 216, 234, 0.0)
      layout:
        margin:
          r: '[[right_margin]]'
      defaults:
        entity:
          layout:
            yaxis2:
              margin: 90
          line:
            width: 3
            shape: spline
          connectgaps: true
          show_value:
            right_margin: 15
          texttemplate: <b>%{y:.1f}</b>%{customdata.unit_of_measurement}
          lambda: |-
            (ys, xs) => {
              const MINUTES = [[window]] // <-- change here
              const window_size_ms = 1000*60*MINUTES 
              const result = {x:[], y:[]}
              let x_next = +xs[0] + window_size_ms
              let y_accum = 0
              let y_count = 0
              for (let i = 0; i < xs.length; i++) {
                const x = +xs[i]
                const y = +ys[i]
                if (x>x_next){
                  result.y.push(y_accum/y_count)
                  result.x.push(new Date(x_next))
                  y_accum = 0
                  y_count = 0
                  x_next = +x + window_size_ms
                }
                if (y){
                  // ignore unavailable/unknown state points
                  y_accum += y
                  y_count ++
                }
              } 
              return result;
            }
      hours_to_show: '[[show]]'
      refresh_interval: 10
      entities: '[[entities]]'

```

En version 2, la 3 n'est pas encore installée/adaptée

 ![image](https://forum.hacf.fr/uploads/default/original/3X/4/4/4495556512f1ddc8cd863a2e0389bfc389cf544f.png)

EDIT : Template en v3

```auto
  ploty_generic:
    default:
      color_scheme: dutch_field
      right_margin: 5
    element:
      type: custom:plotly-graph
      color_scheme: '[[color_scheme]]'
      fillcolor: rgba(168, 216, 234, 0.0)
      layout:
        margin:
          r: '[[right_margin]]'
      defaults:
        entity:
          layout:
            yaxis2:
              margin: 90
          line:
            width: 3
            shape: spline
          connectgaps: true
          show_value:
            margin:
              r: 5
          texttemplate: <b>%{y:.1f}</b>%{customdata.unit_of_measurement}
          filters:
            - sliding_window_moving_average:
                window_size: '[[window]]'
                extended: true
      hours_to_show: '[[show]]'
      refresh_interval: 10
      entities: '[[entities]]'

```

---

<div class="post-metadata">

**Author:** ![FillR2](https://forum.hacf.fr/user_avatar/forum.hacf.fr/fillr2/32/14398_2.png) [@FillR2](https://forum.hacf.fr/u/FillR2)\
**Post date:** [Janvier 31, 2023, 9:21 UTC](https://forum.hacf.fr/t/custom-card-plotly/20334/5 "2023-01-31T21:21:19Z")

</div>

Sympa cette carte, j'ai récupéré un exemple qui permet de faire de la prévision météo avec Openweathermap (je ne suis pas l'auteur du code):

 ![image](https://forum.hacf.fr/uploads/default/original/3X/b/7/b713932cbd4c965aa693ef1414b805347a0197f2.png)

```auto
type: custom:plotly-graph
title: Forecast
time_offset: 4.5d
entities:
  - entity: sensor.openweathermap_temperature
    legendgroup: 2
    name: 🌡 Temperature
    filters:
      - store_var: temperature
    fill: tozeroy
    fillcolor: rgba(214, 39, 40,.6)
    line:
      color: rgba(214, 39, 40, 1)
  - entity: weather.openweathermap
    legendgroup: 2
    showlegend: false
    name: Temperature
    fill: tozeroy
    fillcolor: rgba(214, 39, 40, .3)
    line:
      color: rgba(214, 39, 40, 1)
      dash: dot
    unit_of_measurement: °C
    filters:
      - fn: |-
          ({ meta, vars }) => ({
            xs: [vars.temperature.xs.slice(-1)[0],...meta.forecast.map(({ datetime }) => new Date(datetime))],
            ys: [vars.temperature.ys.slice(-1)[0],...meta.forecast.map(({ temperature }) => temperature)],
          })
  - entity: sensor.openweathermap_rain
    fillcolor: rgba(31, 119, 180,.6)
    line:
      color: rgba(31, 119, 180, 1)
    legendgroup: 1
    name: 🌧 Precipitation
    filters:
      - store_var: precipitation
    fill: tozeroy
  - entity: weather.openweathermap
    legendgroup: 1
    showlegend: false
    name: Precipitation
    fill: tozeroy
    fillcolor: rgba(31, 119, 180,.3)
    line:
      color: rgba(31, 119, 180, 1)
      dash: dot
    unit_of_measurement: mm
    filters:
      - fn: |-
          ({ meta, vars }) => ({
            xs: [vars.precipitation.xs.slice(-1)[0],...meta.forecast.map(({ datetime }) => new Date(datetime))],
            ys: [vars.precipitation.ys.slice(-1)[0],...meta.forecast.map(({ precipitation }) => precipitation)],
          })
defaults:
  entity:
    show_value: true
    line:
      shape: spline
layout:
  legend:
    itemwidth: 30
hours_to_show: 144

```

---

<div class="post-metadata">

**Author:** ![mimi](https://forum.hacf.fr/user_avatar/forum.hacf.fr/mimi/32/12689_2.png) [@mimi](https://forum.hacf.fr/u/mimi)\
**Post date:** [Mars 12, 2023, 5:49 UTC](https://forum.hacf.fr/t/custom-card-plotly/20334/6 "2023-03-12T17:49:01Z")

</div>

Hello FillR2,  
j'ai essayé et je ne sais pas pourquoi ça ne fonctionne pas :

 ![image](https://forum.hacf.fr/uploads/default/original/3X/c/0/c04e42c0a114c74af200c2b424a9b95f0b644569.png)  
J'ai loupé quelque chose ?

---

<div class="post-metadata">

**Author:** ![FillR2](https://forum.hacf.fr/user_avatar/forum.hacf.fr/fillr2/32/14398_2.png) [@FillR2](https://forum.hacf.fr/u/FillR2)\
**Post date:** [Mars 12, 2023, 10:18 UTC](https://forum.hacf.fr/t/custom-card-plotly/20334/7 "2023-03-12T22:18:31Z")

</div>

Hello Mimi,

Comme je l’ai indiqué, je ne suis pas l’auteur du code que j’ai copié tel quel, impossible de te dire ce qui ne va pas.

A noter quand même que ce code est valide à condistion d’avoir installé l’intégration OpenWeatherMap

---

<div class="post-metadata">

**Author:** ![mimi](https://forum.hacf.fr/user_avatar/forum.hacf.fr/mimi/32/12689_2.png) [@mimi](https://forum.hacf.fr/u/mimi)\
**Post date:** [Mars 13, 2023, 10:32 UTC](https://forum.hacf.fr/t/custom-card-plotly/20334/8 "2023-03-13T10:32:00Z")

</div>

bon merci quand même et oui j’ai bien l’intégration OpenWeatherMap.

---

<div class="post-metadata">

**Author:** ![FillR2](https://forum.hacf.fr/user_avatar/forum.hacf.fr/fillr2/32/14398_2.png) [@FillR2](https://forum.hacf.fr/u/FillR2)\
**Post date:** [Mars 13, 2023, 11:01 UTC](https://forum.hacf.fr/t/custom-card-plotly/20334/9 "2023-03-13T11:01:08Z")

</div>

J’ai utilisé le code dont le source est ici : [https://github.com/dbuezas/lovelace-plotly-graph-card/discussions/213](https://github.com/dbuezas/lovelace-plotly-graph-card/discussions/213)

---

<div class="post-metadata">

**Author:** ![FillR2](https://forum.hacf.fr/user_avatar/forum.hacf.fr/fillr2/32/14398_2.png) [@FillR2](https://forum.hacf.fr/u/FillR2)\
**Post date:** [Octobre 18, 2023, 10:38 UTC](https://forum.hacf.fr/t/custom-card-plotly/20334/10 "2023-10-18T22:38:12Z")

</div>

Je commence à jouer avec plotly, on peut faire des trucs puissants, par exemple, l'affichage ici de la température et de la consommation électrique Année courante + année A-1

 ![image](https://forum.hacf.fr/uploads/default/original/3X/9/3/934f652f01d55304ea1a4516e3c2e8cfa6e1d6c6.png)

Après pour ceux qui ont de l'imagination, on peut faire de sacrés trucs:

 ![image](https://forum.hacf.fr/uploads/default/original/3X/5/8/58d8a23e671ba64335ef2c49d5643bc394a02fa6.png)

Et en plus, c'est dynamique:

 ![image](https://forum.hacf.fr/uploads/default/original/3X/d/8/d8986664f482c8687b31d47b9e2f1ca6cb7a058c.png)

On peut aussi développer, c'est pas ce qu'il y a de plus simple, perso, je débute en utilisant les modèles proposés.

---

<div class="post-metadata">

**Author:** ![FillR2](https://forum.hacf.fr/user_avatar/forum.hacf.fr/fillr2/32/14398_2.png) [@FillR2](https://forum.hacf.fr/u/FillR2)\
**Post date:** [Janvier 8, 2024, 8:21 UTC](https://forum.hacf.fr/t/custom-card-plotly/20334/11 "2024-01-08T20:21:01Z")

</div>

J'ai réussi à faire un tableau de bord Energy amélioré ici :

> **[Analysis of electricity consumption compared with the previous year · dbuezas...](https://github.com/dbuezas/lovelace-plotly-graph-card/discussions/334)**
>
> For a long time now, I've been looking for a graph that would enable me to analyze my electricity consumption, particularly in relation to the previous year. Thanks to Plotly, I've been able to pro...

---

<div class="post-metadata">

**Author:** ![FillR2](https://forum.hacf.fr/user_avatar/forum.hacf.fr/fillr2/32/14398_2.png) [@FillR2](https://forum.hacf.fr/u/FillR2)\
**Post date:** [Juillet 28, 2024, 2:45 UTC](https://forum.hacf.fr/t/custom-card-plotly/20334/12 "2024-07-28T14:45:06Z")

</div>

Un petit coup de pub pour ce ce composant et cette nouvelle page avec pleins de graphiques possibles !

Alors à votre imagination:

 ![image](https://forum.hacf.fr/uploads/default/original/3X/8/b/8b9f1d4a32636699f2ce2507ee25d55f9bad40a4.png)

> <https://github.com/dbuezas/lovelace-plotly-graph-card/blob/master/discussion-index.md>
