If the sensor for any reason would give me something else than an array I would be fine if the template just resolved to the integer 0. However, either way I’ve tried, as soon as the sensor has invalid JSON, it will instead log a “JSONDecodeError”… I can’t figure out if there’s any way for the template to swallow that and give me a default value instead?
Come to think about it, if I move the template that takes the random value to the Rest sensor config then I should be able to use a default value in the script when the sensor is undefined (which I assumes it is for invalid json)… I’ll give that a try!