Take the case of a product that supports analog inputs from a variety of 0 to 5v sensors. The input voltage may have a variety of meanings depending on the sensor's function. For example, they could measure light, current, humidity, temperature, pressure, etc. Further, assume this device can report the actual measured voltage and also a meaningful number related to the input sensor's purpose
Now, assume I have built a custom indigo plugin device for this device and defined 2 states in Devices.xml: voltage and sensorValue. The voltage level is placed in voltage and whatever the sensor is actually measuring goes into sensorValue. So far, so good.
Now, for clarity, I would like one additional state. It will have the same value as sensorState, but with a meaningful name. Like humidity of temperature.
Right now I create these states on the fly as discussed in this post from 2014. That works. But, it has one drawback. Sometimes as the device is being instantiated in Indigo, like on server startup or plugin restart, a sensor measurement is received before the new state is available, so the updateStateOnServer attempt throws an Indigo error. The problem is, of course, short-lived. Note, other than the difference of this single state, all of the Indigo devices created for this product are identical.
So, my question is... Is there a way to create the new state so that it is persistent once it has been created (I.e. it survives plugin restarts)? Or, is there some other approach to this issue?
BTW, Yes, I know I can try to fine-tune the timing, but, a lot depends on external code over which I have no control.