Help needed using Template Light to control brightness and transition of Tradfri lights

Hi. It’s me again.

Coming to you awesome people looking for help regarding Template Light. I’m still quite new in the templating business.
After i have had problems with getting my IKEA Tradri Groups working in this thread i set the option “allow_tradfri_groups” in my config to “false” but i would still love to group my lights so i don’t have to type multiple entity ID’s into my automations and i felt like Template Light could do the job. :wink:

Parsing brightness to the Template Light as shown below work but only when the individual lights are one. I get this error in the log:

2017-11-14 07:38:41 ERROR (MainThread) [homeassistant.components.light.template] UndefinedError: ‘mappingproxy object’ has no attribute ‘brightness’
2017-11-14 07:38:41 ERROR (MainThread) [homeassistant.helpers.entity] Update for light.hallway fails
Traceback (most recent call last):
File “/usr/lib/python3.6/site-packages/homeassistant/helpers/entity.py”, line 204, in async_update_ha_state
yield from self.async_device_update()
File “/usr/lib/python3.6/site-packages/homeassistant/helpers/entity.py”, line 307, in async_device_update
yield from self.async_update()
File “/usr/lib/python3.6/asyncio/coroutines.py”, line 210, in coro
res = func(*args, **kw)
File “/usr/lib/python3.6/site-packages/homeassistant/components/light/template.py”, line 264, in async_update
if 0 <= int(brightness) <= 255:

Turning off the light.group does not work, it turns back on instantly but turns off the individual lights.

platform: template
lights:
  hallway:
    friendly_name: "Light Hallway"
    value_template: >-
      {% if is_state('light.hallway_panel_1', 'on') and is_state('light.hallway_panel_2', 'on') %}
        on
      {% else %}
        off
      {% endif %}
    turn_on:
      service: light.turn_on
      entity_id:
        - light.hallway_panel_1
        - light.hallway_panel_2
    turn_off:
      service: light.turn_off
      entity_id:
        - light.hallway_panel_1
        - light.hallway_panel_2
    level_template: >-
      {% if is_state('light.hallway', 'on') %}
        {{ (states.light.hallway_panel_1.attributes.brightness)|int }}
      {% else %}
        0
      {% endif %}
    set_level:
      service: light.turn_on
      data_template:
        entity_id:
          - light.hallway_panel_1
          - light.hallway_panel_2
        brightness: "{{ brightness }}"
        transition: "{{ transition }}"

Any help would be much appreciated as i am eager to learn this! :slight_smile:

1 Like

Did you solve this? I have a similar error, but next to brightness also with light.