Representing "Idle" states for MQTT Sensors

Good afternoon!

I’m working on a project that will send in values to Home Assistant via MQTT. I’m a little unclear how how best to represent “idle” states for sensors.

For example, the project will have a countdown timer, which when active will send number of seconds remaining. But when idle, doesn’t have a number of seconds remaining. Presumably I shouldn’t make the sensor “Unavailable”, because the sensor itself is still there and could become active. It’s not currently running. Would setting “Unknown” make more sense?

Similarly, I’ll have range sensors which may, at times, fail to report ranges. That’s not in my mind the same as “Unavailable”, as in the sensor is disconnected, but that that’s no object in range so it’s not getting a result. Again, “Unknown” state would seem more appropriate.

I’m unclear how to actually set a sensor to “Unknown” voluntarily, however. It seems that’s not possible, only setting unavailable. So am I barking up the wrong tree?


Don’t really know how to do it, but if you don’t mind the hackyness, you could send a value that is not a valid sensor reading, for example 1000 for a temperature sensor - reasonably the probe can’t be 1000 degrees - that would represent the idle state for the sensor. Then create a template sensor that takes its value from your mqtt sensor, if the value is not 1000, and if it is 1000 the template sensor value will be a const string like “idle”

That might be a workable hack. Worth a shot. I’m creating my sensors with MQTT Discovery, but I think you can create template sensors that way.