I have an mqtt sensor in which state is the name of the bird that was last registered on my microphone. On the front end, I’d love to show the number of times that the species has occurred since today. I figured using history_stats is the best sensor, but the only thing I can’t figure out is if the state: parameter can be a template. This doesn’t result in another but a big goose egg of a result (pun heavily intended). As soon as I change the state to a static string (like “Black-capped Chickadee”) it works as expected.
Yes, I figured as much given that the docs didn’t have the template link like start or end do, but I thought I read that all mqtt sensors come in as strings. I could also try to value_template the mqtt sensor to force it into a string.
But I may still face the issue with how history_stats are configured that it just won’t work unless it’s static?
There’s gotta be a workaround here, even if its adding another sensor and using an attribute or something.
It doesn’t matter how many other sensors you create, a History Stats sensor will not accept anything other than a string value for its state option. It would need to support a template in order to reference another entity’s value.
If anyone else stumbles upon this and has ideas, I’m all ears. My next bet is to expand my appdaemon script to count and just dynamically create a species counter. Not my favorite as I was hoping for just a single counter entity, but better than nothing.
Ha, I appreciate that. I mostly
meant simple in terms of the concept.
So the device running the project sends a single MQTT string and topic which is ingested and parsed by appdaemon. Appdaemon then sends out each value as a new sensor for HA. The values are all MQTT sensors right now, but I do have the same script creating a sensor by set_state() and adding attributes.
Have appdeamon dynamically create a sensor for each bird it encounters. On when it’s seen, off when it’s not. Then use history stats for that. Or simply make a rolling count w/ appdeamon in the attributes and reset it when you feel the need. You can also handle restoring states to make sure your counts persist using pickle or a json file.
On my dashboard, I have each of the sensors update with the most recent MQTT data - so it always shows the most recently recorded bird. I was trying to fit the counter into a single sensor because it slightly eludes me how I’d dynamically pull in the correct history sensor based on the name of the common bird.
The state of the sensor.bird_common_name is a string like “House Finch” where the appdaemon count sensor would likely be sensor.house_finch_count. So unless there’s something I’m missing, would I have to do something like this?