Hey everyone,
Here’s a way to dynamically select the number of hours a history graph shows.
This project relies 100% on the config-template-card, so all credits go to the developer.
First, we create an input_select entity.
input_select:
hours_to_show:
name: Hours to show
options:
- 24
- 12
- 4
- 2
- 48
- 72
initial: 24
Then the code for creating our card is the following:
type: vertical-stack
cards:
- type: entities
entities:
- entity: input_select.hours_to_show
name: Select Hours to Show
- type: 'custom:config-template-card'
variables:
- 'states[''input_select.hours_to_show''].state'
entities:
- input_select.hours_to_show
card:
type: history-graph
entities:
- entity: sensor.watts
name: Watts
hours_to_show: '${vars[0]}'
refresh_interval: 0
The whole idea is that we use the ‘${vars[0]}’ in the hours_to_show field.
UPDATE
See this post on how to select different sensors.
UPDATE
See this post on how to dynamically change the card’s title.
UPDATE
See this post on how to show entire calendar days, example yesterday, 3 days ago etc