Set brightness in light template

Hi,

I have a ZigBee relay. The relay switches the bulbs in the garage, so I’d like to handle the relay as a light.
I have created the following template:

light:
  - platform: template
    lights:
      garazs_led:
        level_template:
          {% if is_state('switch.garage_relay','on') %}
             255
          {% else %}
             0
          {% endif %}
        value_template: "{{ states('switch.garage_relay') }}"
        friendly_name: "Garage Light"
        turn_on:
          service: switch.turn_on
          data: {}
          target:
            entity_id: switch.garage_relay
        turn_off:
          service: switch.turn_off
          data: {}
          target:
            entity_id: switch.garage_relay
        supports_transition_template: "{{ false }}"

It’s working fine, but I don’t get the brightness. What is the problem with this part of the code:

        level_template:
          {% if is_state('switch.garage_relay','on') %}
             255
          {% else %}
             0
          {% endif %}

At the very least it looks like you’re missing the multi-line YAML character:

        level_template: >
          {% if is_state('switch.garage_relay','on') %}
             255
          {% else %}
             0
          {% endif %}
1 Like

Is there a specific reason why you need brightness? If you don’t really need it, you can just use the Switch as Light helper.

1 Like

Sorry, but I didn’t copy the code from configuration.yaml correctly. Of course, the multiline YAML character is not missing from my working configuration.yaml, so something else must be the problem.

Yes, I know that I could use the ‘platform: switch’ option, but I use brightness in the relatively complex light-handling HA automation and Node-Red Java scripts.

I haven’t solved the brightness yet. The full garage reflector control in configuration.yaml:

  - platform: template
    lights:
      garage_reflector:
        friendly_name: "Garage Reflector"
        level_template: >-
          {% if is_state('switch.garage_reflector_relay','on') %} 255
          {% else %} 0
          {% endif %}
        turn_on:
          service: switch.turn_on
          data: {}
          target:
            entity_id: switch.garage_reflector_relay
        turn_off:
          service: switch.turn_off
          data: {}
          target:
            entity_id: switch.garage_reflector_relay
        supports_transition_template: "{{ false }}"

The control works perfectly, but there isn’t a brightness attribute of light.garage_reflector entity.

State attributes from Developer Tools/STATES:

supported_color_modes:
  - onoff
friendly_name: Garage Reflector
supported_features: 0

What could be the problem?