Hi all. I’m trying to have a sensor show the text HOME/AWAY based on the state of a bayesian binary sensor the same way that my trackers will do, using a badge. The bayesian filter itself is working fine (so far as I can tell) but I’ve been unable to get a sensor set up that will use the result of that to show an icon that includes the text HOME/AWAY.
Below is a screenshot of what I have currently.
The tracker ‘Daniels Tile’ is a straight up tracker and works fine and shows what I’m looking for with that ‘HOME’ text in the red bubble. The other two badges are firstly the Bayesian filter, which I’d eventually hide, and a binary_sensor with device_class of presence. It’s my understanding a templated binary_sensor is the way to go for this having done some reading and no luck adding the device_class to the bayesian sensor itself.
My binary_sensor.yaml file contains the following for those two relevant sensors
both sensors are showing a state of ‘on’ for the object and if the badge on the UI is clicked they display as ‘home’, which I believe is correct for these sensors. Just the UI doesn’t have the red badge with the word ‘Home’ I’d like to see which I was hoping “device_class: presence” would do. The reason for wanting that is I’d like to replace the icon of the house with a photo of the person the bayesian filter applies to, at which point having the text home or away will help identify the state.
Worth noting when I am away the Icon itself changes to the away house icon, again without that text I’m hoping to see on the badge. So presence is being detected, just I cant get the UI to display as I’d like.
You won’t be able to get that without it being a device_tracker device. Your’s is a binary sensor. You may be able to get what you want using MQTT and publishing the result to a topic. Then use this component to get it back as a device_tracker, which will add the word ‘home’, and ‘away’.
Thanks for the response. I had been using this link as a guide but I guess its not doable or I’ve misinterpreted what was happening there?
I’ll have a look at the MQTT or if that all becomes too much I guess I can just use an templated image with the ‘Home’ or ‘Away’ text as part of the image, or I can change the colour of the outer ring based on state.
There are many types of devices in home assistant. These types are called ‘domains’. The guide you are following is creating a device in the binary_sensor domain. This device has a typical behavior in the UI. That behavior differs from other domains. The domain that displays the words ‘home’ and ‘away’ on a badge is the device_tracker domain. Do you now see the problem? No matter what you do with that guide, you are creating a binary_sensor device and it will not display home/away on the badge because it is not a device_tracker device.
Your solution is to somehow create a device tracker device. One solution would be to create a MQTT device tracker device and an automation. The automation would watch your binary_sensor, when the state of the binary sensor changes, it would send that change to the MQTT device_tracker topic. This in turn would update the device_tracker. Then in the ui, only show the device tracker and ‘hide’ the binary sensor. Does that make more sense?
Thanks and yes, it makes sense. The hope had been that the UI behaviour for a binary_sensor with a ‘presence’ class would be similar to a device_tracker but thats clearly not the case. The ‘presence’ class had some UI impact in that the default icon became a house that would change state, but no text badge like I’d wanted. Given your excellent lead I’ve explored the MQTT option and it looks to be working as I’d like.
Given I’d seen the question posted previously, codes as follows:
Played around with getting an MQTT broker set up above which also seemed to be a necessary step. Something new to me but hey, least I have it now. And after the device was then added to known_devices, I set the ‘Picture’ and ‘Name’ to fit the UI
Unsure if its as clean as it could be, and I can certainly do with a few entity renames as that Bayesian observation list is hard to follow, but happy with the result.