Mariusthvdb / custom-ui

Add templates and icon_color to Home Assistant UI
163 stars 30 forks source link

Adding wildcard to sensor name causes error #58

Closed ingo916 closed 2 years ago

ingo916 commented 2 years ago

If I add an * in the sensor name to include all devices similar in name I get an error when I check the config. If I add the sensors individually it works fine

Entry in customize.yaml with wildcard

binary_sensor.lumi_lumi_sensor_wleakaq1*_ias_zone: templates: icon_color: > if (state === 'on') return 'red'; return 'steelblue';

Sensors listed individually works

binary_sensor.lumi_lumi_sensor_motion_aq2_c2abbc07_ias_zone: templates: icon_color: > if (state === 'on') return 'red'; return 'steelblue';

binary_sensor.front_door_motion: templates: icon_color: > if (state === 'on') return 'red'; return 'steelblue';

Error checking config

extra keys not allowed @ data['customize']['binary_sensor.lumi_lumi_sensor_wleakaq1*_ias_zone']

image

Mariusthvdb commented 2 years ago

please format your code correctly.

do read the examples, where it is stated that globs need to go under

homeassistant:
  customize_glob:

having said that, when using a wildcard in a regular customize: section, this error is exposed:

Schermafbeelding 2022-04-22 om 09 13 42

since your error is different, and displayed in the config checker, I suspect it to be a different issue. So, again: post your code correctly formatted, so we can check.

it is clear though about the section you made the error in.... ['customize']

bratanon commented 2 years ago

When using this:

# configuration.yaml
input_boolean:
  test:
    name: Test boolean

template:
  - binary_sensor:
      - name: Test xx boolean
        state: "{{ states('input_boolean.test') }}"
      - name: Test yy boolean
        state: "{{ is_state('input_boolean.test', 'off') }}"
# customize_glob.yaml
"binary_sensor.test_*_boolean":
  templates:
    icon: >
      return (state === 'on') ? 'mdi:test-tube' : 'mdi:test-tube-off';
    icon_color: >
      if (state === 'on') return 'red';
      return 'yellow';

It works as expected.

As @Mariusthvdb said, please move your customization's to the correct config and try again.

I will close this for now. Please feel free to re-poen it again if needed.