Hey everyone, I wanted to share my experience with using the history_stats sensor in Home Assistant. I was trying to track bird sightings in my backyard using an MQTT sensor, and I wanted to display the count of each species since the start of the day. At first, I ran into a bit of a roadblock because the state parameter in the sensor configuration didn’t seem to accept templates. Here’s what I tried:
yaml
sensor:
- platform: history_stats
name: Bird Sightings
entity_id: sensor.bird_common_name
state: “{{ states(‘sensor.bird_common_name’) }}”
type: count
start: “{{ now().replace(hour=0, minute=0, second=0, microsecond=0) }}”
end: “{{ now() }}”
Unfortunately, this setup didn’t give me the results I was hoping for. After a bit of research and trial and error, I found a workaround! Instead of using a template for the state, I realized I could create a separate sensor for each bird species and use input_text entities to manually update the counts. While it’s not as seamless as I’d hoped, it gets the job done and allows me to track multiple species at once.
I’d love to hear if anyone else has found a more elegant solution or if they’ve encountered similar challenges with history_stats. Let’s keep the discussion going and help each other out!
Cheers,
[Your Name]