Binning of values (eg illuminance)

Hello all,

What’s the simplest way to bin continuous sensor values? E.g. illuminance

0-20 lux as Bin 1,

20-50 lux as Bin 2,

etc. In some ways this is not so different from the hysteresis helper, but with multiple bins.

This could of course be done via if/then queries, but just wonder whether something is built in.

Thanks!

Which Bin do you actually want 20 to be sorted into?

@123’s method satisfies the second one, for the first you could use something like:

{% set lux = 20 %}
{% set bins = [ 20, 50, 75, 105, 135, 165, 195, 215] %}
Bin {{ ((bins + [lux]) | sort).index(lux) + 1 }}
3 Likes