Dynamic days_to_show on a statistics-graph?

Is there a way to make the days_to_show dynamic on a statistics-graph?
I’ve tried this:

  - type: statistics-graph
    title: 'Lolo Weight'
    days_to_show: '{{states("input_number.lolo_weight_chart_days_to_show") | int}}'
    stat_types: mean
      - entity: sensor.lolo_weight
        name: Weight

But all I get is loading statistics
Am I missing something?
It would be nice to be able to change the time scale with an input_number or input_text

I did something like that with https://github.com/iantrich/config-template-card

type: custom:vertical-stack-in-card
title: BIER
  - type: entities
      - entity: input_select.hours_to_show
  - type: entities
      - entity: input_select.sensors_to_show
    show_header_toggle: false
  - type: custom:config-template-card
      - states['input_select.hours_to_show'].state
      - states['input_select.sensors_to_show'].state
      - setEntities: |
          entities => {
            if '${var[1]}' === 'Alles' {
              return ["sensor.temperatuur_bier", "sensor.temperatuur_fermenteerkast"];
            else {
              return ["sensor.temperatuur_bier", "sensor.temperatuur_fermenteerkast"];
      - input_select.hours_to_show
      - input_select.sensors_to_show
      type: custom:mini-graph-card
        - entity: sensor.temperatuur_bier
        - entity: sensor.setpunt_bier
        - entity: sensor.setpunt_fermenteerkast
        - entity: sensor.temperatuur_fermenteerkast
        - entity: sensor.temperatuur_garage
      hours_to_show: ${vars[0]}
      hour24: true
      points_per_hour: 15
      line_width: 3
      height: 250
        points: hover
        labels: true
        labels_secondary: true
        fill: fade
1 Like

Hey @lolouk44 - Did you ever solve this? I’m glad I’m not the only one that has come across this issue.

My template results to a number in the Dev Tools and I even tried with and without |int, but all I get is loading statistics as well.

I’ve submitted a bug - See if we’re just crazy :wink:
statistics-graph card shows “Loading statistics…” when using a dynamic variable for days_to_show · Issue #11085 · home-assistant/frontend (github.com)

Nope. The Days to show is static / hard coded for me. Not checked theunderlying code but I suspect it does not accept templates.

For the sake of someone else reading this. As of FEB 2022 - it’s not supported and sounds like it’s not going to be unless we get a script monkey to help us out - cause I sure don’t know how :frowning:

------ spacegaier on GITHUB (Refer to the github link earlier) ------
This is not supported. The docs state that you have to provide a numeric value in the card configuration, but you are providing a string and hoping that the frontend will evaluate that provided template into a number, which is not the case (not for this card, nor in general…with the exception of the markdown card).

You could raise a feature request, if you think that this is a needed feature, but then the next question would be: Why this configuration variable and not others and where do we draw the line then?

Guess the best compromise will be to use conditional cards with an input select to drive it.

1 Like

Ooo, that’s a crafty workaround. Somewhat hacky but I like it, will try this approach.

1 Like