Morning Community!
So I came across the history_stats component and built a sensor using documented examples, in this case, it’s to track states of a given device (in my case, device_tracker) and it appears that it’s not consistent. So I crawled around the forum looking for anything I could around history_stats and only one person had an issue due to typo whereas others had it working then stopped.
My setup:
HA 0.99.3 venv
history and recorder are at defaults (for the most part) in configuration.yaml – I can see the device_trackers I want in the History tab along with all the states it has. Using MySQL as a DB backend.
history:
default: info
recorder:
db_url: !secret mysql_url
And I have my device_tracker that I’m trying to pull history stats from:
This tracker has one of several states that I track: Home, Away, Work (Office), etc.
So I created a history_stats sensor which appears to be working for all my states except “Away”. This means “Work (Office)”, “School” and even “Home” all work as expected but “Away” doesn’t. Here’s my config around the previously mentioned sensors:
- platform: history_stats
name: Chris Time Home
entity_id: device_tracker.life360_chris_nodered
state: 'Home'
type: time
start: '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}'
end: '{{ now() }}'
- platform: history_stats
name: Chris Time Away
entity_id: device_tracker.life360_chris_nodered
state: 'Away'
type: time
start: '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}'
end: '{{ now() }}'
- platform: history_stats
name: Chris Time Office
entity_id: device_tracker.life360_chris_nodered
state: 'Work (Office)'
type: time
start: '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}'
end: '{{ now() }}'
- platform: template
sensors:
chris_time_away_today:
friendly_name: 'Away'
value_template: '{{ states.sensor.chris_time_away.attributes.value }}'
- platform: template
sensors:
chris_time_at_home_today:
friendly_name: 'Home'
value_template: '{{ states.sensor.chris_time_home.attributes.value }}'
- platform: template
sensors:
chris_time_at_work_office_today:
friendly_name: 'Work (Office)'
value_template: '{{ states.sensor.chris_time_office.attributes.value }}'
I know the sensor is case-sensitive and “Away” is “Away” in the history for the device_tracker. Home and Work (Office) and other various states work without issue but I cannot for the life of me figure out why “Away” is not working and thinking perhaps I can’t see the trees through the forest (although I just copied the sensor and adjusted the parameters for each, even the working ones.)
Can anyone see where my mistake is? Or can explain why this one state doesn’t seem to match when the others do without issue?
As always, appreciate the help and support!
-Chris