Changing the history graph timescale with State Switch and Decluttering Cards

I’m trying to change the time scale of a history graph from a dashboard.
The final objective is to dynamically change the time scale of a whole dashboard, powered by mini-graph cards.
I’m using state switch to action the ‘tabs’, and decluttering to assign a different duration parameter to the same template.
Here’s the outcome so far:HAdash
As you can see, the card doesn’t refresh when loaded the second time.
Do you have an idea on how to improve this approach, or a suggestion to an alternative way?
Here’s the code:

decluttering_templates:
  history_graph:
    default:
      - icon: fire
    card:
      type: history-graph
      entities:
        - sun.sun
      hours_to_show: '[[hours]]'
      refresh_interval: 0
      name: '[[name]]'
      show_icon: false
views:
  - path: default_view
    title: Home
    cards:
      - type: horizontal-stack
        cards:
          - type: button
            tap_action:
              action: navigate
              navigation_path: '#one'
            entity: sun.sun
            show_icon: false
            name: one day
          - type: button
            tap_action:
              action: navigate
              navigation_path: '#two'
            entity: sun.sun
            show_icon: false
            name: two days
          - type: button
            tap_action:
              action: navigate
              navigation_path: '#week'
            entity: sun.sun
            show_icon: false
            name: one week
      - type: 'custom:state-switch'
        entity: hash
        default: one
        states:
          one:
            type: 'custom:decluttering-card'
            template: history_graph
            variables:
              - hours: 24
          two:
            type: 'custom:decluttering-card'
            template: history_graph
            variables:
              - hours: 48
          week:
            type: 'custom:decluttering-card'
            template: history_graph
            variables:
              - hours: 168

Have a read of this:

2 Likes

Thanks, it worked perfectly, with the benefit of the input entity being stateful, and preserving the choice when switching between views.