!input in automation/blueprint + templates

Hi,

I’ve modified a blueprint to my need but I want to make it more generic.

One of the things I changed was the control of brightness:

              brightness_step_pct: >
                {% if (state_attr('light.lampada_lara', 'brightness')/2.54) > 20 %}
                  -20
                {% elif 11 < (state_attr('light.lampada_lara', 'brightness')/2.54) < 20 %}
                  -10
                {% elif (state_attr('light.lampada_lara', 'brightness')/2.54) <= 11 %}
                  {{ 1-(state_attr('light.lampada_lara', 'brightness')/2.54) }}
                {% endif %}

As you can see I’ve put the entity name there.

The original blueprint always call the entity as

target:

              entity_id: !input zha_entity_light

So I tried many things to replace ‘light.lampada_lara’ to !input zha_entity_light withou sucess.

I tried the following:

‘!input zha_entity_light’
“!input zha_entity_light”
!input zha_entity_light

I also tried to add a variable:

variables:
  device_id: !input zha_device
  light_id: !input zha_entity_light

and then use the variable there as:

light_id
‘light_id’
[light_id]

But those didn’t work.

Is there a solution?

Tks

You cannot use the yaml !input method directly in templates, you must assign the value of the input to a variable as in you did in

variables:
  device_id: !input zha_device
  light_id: !input zha_entity_light

Depending on how/where in the automation you need access to that data, you may need to assign them as trigger_variables. Then your template would be as follows:

brightness_step_pct: >
  {% set brightness = state_attr(light_id, 'brightness') / 2.54 %}
  {% if brightness > 20 %}
    -20
  {% elif 11 < brightness < 20 %}
    -10
  {% elif brightness <= 11 %}
    {{ 1 - brightness }}
  {% endif %}

Tried that and got

“Error: Error rendering data template: AttributeError: ‘list’ object has no attribute ‘lower’”

Here is the “Automation config” in Traces

image

That error is not coming from that part of the blueprint

So where does it come from?

Here is the print from trace

And here is the full code from blueprint:

blueprint:
  domain: automation
  name: Controlling lights using Philips Hue Dimmer Switch (RWL021)
  description: Take the swith fast into use with pre-set configuration.
  input:
    zha_device:
      name: Philips Hue Dimmer Switch (RWL021 only)
      description: The swith to be taken into use.
      selector:
        device:
          integration: zha
          model: RWL021
          multiple: false
    zha_entity_light:
      name: Light or a light group
      description: Light or a light group to be controlled.
      selector:
        entity:
          multiple: true
          integration: zha
          domain:
            - light
  source_url: https://gist.github.com/Rantaki/33c9e74821e08c4419539e7a8e46007c
mode: queued
max_exceeded: silent
variables:
  device_id: !input zha_device
  light_id: !input zha_entity_light
trigger:
  - platform: event
    event_type: zha_event
condition: "{{ trigger.event.data.device_id == device_id }}"
action:
  - variables:
      command_type: "{{ trigger.event.data.command }}"
  - service: logbook.log
    data:
      name: Device
      message: "{{ device_id }}"
  - service: logbook.log
    data:
      name: Command
      message: "{{ command_type }}"
  - service: logbook.log
    data:
      name: device_id
      message: "{{ trigger.event.data.device_id }}"
  - choose:
      - conditions: '{{ command_type == "on_press" }}'
        sequence:
          - service: light.turn_on
            data:
              brightness_pct: 100
              transition: 0.3
            target:
              entity_id: !input zha_entity_light
      - conditions: '{{ command_type == "off_press" }}'
        sequence:
          - service: light.turn_off
            target:
              entity_id: !input zha_entity_light
            data:
              transition: 0.3
      - conditions: '{{ command_type == "down_hold" }}'
        sequence:
          - service: light.turn_on
            data:
              brightness_step_pct: >
                {% set brightness = state_attr(light_id, 'brightness') / 2.54 %}
                {% if brightness > 20 %}
                  -20
                {% elif 11 < brightness < 20 %}
                  -10
                {% elif brightness <= 11 %}
                  {{ 1 - brightness }}
                {% endif %}
              transition: 0.4
            target:
              entity_id: !input zha_entity_light
      - conditions: '{{ command_type == "up_hold" }}'
        sequence:
          - service: light.turn_on
            data:
              brightness_step_pct: 15
              transition: 0.4
            target:
              entity_id: !input zha_entity_light
      - conditions: '{{ command_type == "up_short_release" }}'
        sequence:
          - service: light.turn_on
            data:
              brightness_pct: 70
              transition: 0.3
            target:
              entity_id: !input zha_entity_light
      - conditions: '{{ command_type == "down_short_release" }}'
        sequence:
          - service: light.turn_on
            data:
              brightness_pct: 10
              transition: 0.3
            target:
              entity_id: !input zha_entity_light
  - choose:
      - conditions:
          '{{ command_type == "on_press" or command_type == "up_short_release"
          }}'
        sequence:
          - delay: 0.4
          - service: light.turn_on
            data:
              kelvin: 3400
              transition: 0.5
            target:
              entity_id: !input zha_entity_light
      - conditions: '{{ command_type == "down_short_release" }}'
        sequence:
          - delay: 0.4
          - service: light.turn_on
            data:
              kelvin: 2300
              transition: 0.5
            target:
              entity_id: !input zha_entity_light

Does anyone have any clues? Tks