I’ve only recently discovered history_stats and I’ve started going bonkers on using it in conjunction with the Harmony remote integration to get stats on gaming/TV time used. The problem is, I’m ending up with loads of repetition which is starting to look a bit unmanageable. For instance, I have this at the moment for the last 24h use:
- platform: history_stats
name: Gaming time 24h - Xbox
entity_id: sensor.harmony_remote_lounge
state: 'Xbox Series X'
type: time
duration: 24h
end: '{{ now() }}'
- platform: history_stats
name: Gaming time 24h - PS5
entity_id: sensor.harmony_remote_lounge
state: 'PS5'
duration: 24h
end: '{{ now() }}'
- platform: history_stats
name: Gaming time 24h - Switch (docked)
entity_id: sensor.harmony_remote_lounge
state: 'Switch'
type: time
duration: 24h
end: '{{ now() }}'
- platform: history_stats
name: TV time 24h - Netflix
entity_id: sensor.harmony_remote_lounge
state: 'Netflix'
type: time
duration: 24h
end: '{{ now() }}'
- platform: history_stats
name: TV time 24h - Sky
entity_id: sensor.harmony_remote_lounge
state: 'Sky Q'
type: time
duration: 24h
end: '{{ now() }}'
… and I’d like to do the same thing for a week duration, and maybe month, which is going to result in a massive load of text which is mostly all the same lines, especially when I will probably also have a template for each one to convert the decimal hours into hours and minutes. Is there any way to reduce some of that duplication and bloat?
I was hoping I’d be able to do something like this:
- platform: history_stats
type: time
duration: 24h
end: '{{ now() }}'
entities:
- entity_id: sensor.harmony_remote_lounge
name: Gaming time 24h - Xbox
state: 'Xbox Series X'
- entity_id: sensor.harmony_remote_lounge
name: Gaming time 24h - PS5
state: 'PS5'
- entity_id: sensor.harmony_remote_lounge
name: Gaming time 24h - Switch (docked)
state: 'Switch'
- entity_id: sensor.harmony_remote_lounge
name: TV time 24h - Netflix
state: 'Netflix'
- entity_id: sensor.harmony_remote_lounge
name: TV time 24h - Sky
state: 'Sky Q'
… but I see that’s not valid. Are there any other options to do the same thing with less lines & repetition? Am I using the wrong tool for the job? Wondering if maybe I should be using the sql interface instead in some way…