Got ten (and then some) of these....possible to compress?

HI,

have about 10 of these customizations for my hue sensors, on several attributes…

icon_color: >
  if (state < -5) return 'rgb(30, 255, 255)';
  if (state < 0) return 'rgb(30, 144, 255)';
  if (state < 10) return 'rgb(255, 255, 0)';
  if (state < 15) return 'rgb(255, 211, 30)';
  if (state < 20) return 'rgb(0, 128, 0)';
  if (state < 25) return 'rgb(255, 165, 0)';
  if (state < 30) return 'rgb(255, 0, 0)';
  if (state < 35) return 'rgb(85, 0, 0)';
  return 'rgb(47, 0, 0)';

guess you can imagine the length of that customize file… :wink: wouldn’t it be possible to have a customizations like this written out and name it temperature_customization, and use that for all sensors instead of the full set like above?

thx for having a look,
Marius

I have absolutely no idea if it will work, but, maybe use !secret?

This was my first thought too! write it once in secrets and then just use the secret over and over. I believe customize supports secrets as I used to pass a URL this way.

creative…:wink:
you mean like:

icon_color: > !secret temperature_icon_color

and

temperature_icon_color: 
     " if (state < -5) return 'rgb(30, 255, 255)';
      if (state < 0) return 'rgb(30, 144, 255)';
      if (state < 10) return 'rgb(255, 255, 0)';
      if (state < 15) return 'rgb(255, 211, 30)';
      if (state < 20) return 'rgb(0, 128, 0)';
      if (state < 25) return 'rgb(255, 165, 0)';
      if (state < 30) return 'rgb(255, 0, 0)';
      if (state < 35) return 'rgb(85, 0, 0)';
      return 'rgb(47, 0, 0)'; "

in secrets.yaml?

Yep, give it a try.

Thanks but i must have had another brainfreeze…

This is exactly what customize_glob is for…

sensor.*_motion_sensor_temperature:
  templates:
    icon_color: >
      if (state < -5) return 'rgb(30, 255, 255)';
      if (state < 0) return 'rgb(30, 144, 255)';
      if (state < 10) return 'rgb(255, 255, 0)';
      if (state < 15) return 'rgb(255, 211, 30)';
      if (state < 20) return 'rgb(0, 128, 0)';
      if (state < 25) return 'rgb(255, 165, 0)';
      if (state < 30) return 'rgb(255, 0, 0)';
      if (state < 35) return 'rgb(85, 0, 0)';
      return 'rgb(47, 0, 0)';

what was i thinking…