Log state 'unavailable' as -1

I’m trying / failing to track device availability state via InfluxDB / Grafana - state 0/Off and 1/On is sent, but not ‘Unavailable’. It seems previous discussion on this subject usually end with ‘unavailable is not a state’ - this makes sense in the ‘power on=1, power off=0’ context, but state ‘unavailable’ seems highly relevant in the connected device / IoT universe.

Suggested feature: log unavailable state as -1 in HASS. Perhaps there’s a dev reason not to do this, or perhaps this flies in the face of established ‘state logic’ (thou shalt not apply negative values to state). If that’s the case, is there an easy way to create a custom state ‘unavailable = -1’ as default for all entities, rather than creating applying a custom sensor template to each one?

Ultimately, I’m working to improve stability across my connected devices - this includes fine-tuning wifi settings, experimenting with different protocols, and testing different hubs. The example that raised this suggestion: my TP-Link (hs300) devices have always experienced intermittent connectivity issues in HASS - I’ve fine-tuned like mad and am now controlling them via a separate Node-Red container. It would be very helpful to compare availability metrics between Node-Red and HASS-connected devices as I chase root cause (which probably will end up ‘TP-Link is just a terrible smartswitch platform’). Of course, this is just one example - overall, I’d like to compare availability between protocols (Z-Wave, Zigbee, wifi, etc), vendors (Hue, LIFX, GE, etc.), access points, rooms, etc. My relevant data resides in InfluxDB, so HASS history doesn’t help.

I think ‘Unavailable’ would be more like null than -1 which might be a valid state for some device. I also think that recognizing that data is known to be unavailable is important vs having stale data. Some HA device states that aren’t numeric have blank space in the history bar (i.e. the OpenGarage vehicle sensor while the garage door is open and blocking that detection). I have also seen blank space in numeric history graphs for some sensors when they are unavailable.

I am going to submit a separate feature request regarding Z-Wave that I believe is relevant here, especially since this request is arguably stale. That having been said, I don’t know what your particular history data looks like, but perhaps you could use helpers to gather this data via automations that set said helpers to one value when an entity becomes unavailable and another value when a valid state is detected.