I was trying to set up a quarantine meter that I saw on Reddit. It seemed to work but the number of hours away from home seemed way off. So tracking it down it sees that my home/away stats are off. There are 336 hours in 14 days. but some reason my tracking sensors are always 90 or so hours off. Not sure why they are missing. To determine home/away I am just using bluetooth connection to my RPi. there is one corner of my apartment where BT does drop out (another issue for another topic), but it should set me to not_home. Which still should add into the 336 hours. Current values show away_stats=19.32 and home_stats=221.55. total of 240.85 with a missing 95.15 hours. Was I abducted by aliens during this time?? Where did this time go?
I am using these as the sensor for testing. Is there another state for a person entity besides not_home and home?? Figure I have something wrong with my person entity which is creating bad values in the final calculations.
- platform: history_stats
name: away_stats
entity_id: person.me
state: "not_home"
duration:
days: 14
end: "{{ now() }}"
- platform: history_stats
name: home_stats
entity_id: person.me
state: "home"
duration:
days: 14
end: "{{ now() }}"
And this is the full sensors for the quarantine meter. Mainly for fun but also to understand how HA is working.
- platform: template
sensors:
hours_outside_per_day_me:
friendly_name: Hours Outside
value_template: >
{% set d, h, m = state_attr("sensor.quarantine_meter_me", "value").split() %}
{% set d, h, m = d[:-1] | int, h[:-1] | int, m[:-1] | int %}
{% set hours_outside = ((14 - d) * 86400 - h * 3600 - m * 60) / 3600 %}
{{ (hours_outside / 14) | round(1) }}
- platform: history_stats
name: Quarantine meter Me
entity_id: person.me
state: "home"
type: ratio
duration:
days: 14
end: "{{ now() }}"
- platform: history_stats
name: Quarantine meter times left
entity_id: person.me
state: "home"
type: count
duration:
days: 14
end: "{{ now() }}"