home-assistant / frontend

:lollipop: Frontend for Home Assistant
https://demo.home-assistant.io
Other
4.12k stars 2.81k forks source link

Error in describing action when target is a template in blueprint input defaults #21884

Open seblu opened 2 months ago

seblu commented 2 months ago

Checklist

Describe the issue you are experiencing

Let's imagine the following blueprint:

blueprint:
  name: Cover Daily
  domain: automation
  input:
    covers:
      name: Cover(s)
      selector:
        target:
          entity:
            domain: cover
    open_action:
      name: Open action(s)
      description: Actions to open the cover(s).
      default:
      - service: cover.open_cover
        target: "{{ covers }}"
      selector:
        action:

The automation edition interface display the following error message : Error in describing action: cannot use 'in' operator to search for "area_id" in "{{ covers }}".

Here is a screenshot of how it's displayed. screenshot_gram_20240904_235030

The automation works as expected, so it's mainly an UI errors because a code is expecting a map and not a string for targets.

Describe the behavior you expected

To not display errors and propose YAML edition.

Steps to reproduce the issue

  1. Create a blueprint with an input with a default with a target template
  2. Create an automation based on this blueprint

What version of Home Assistant Core has the issue?

2024.9.0

What was the last working version of Home Assistant Core?

No response

In which browser are you experiencing the issue with?

firefox,chrome

Which operating system are you using to run this browser?

Arch Linux, Android

State of relevant entities

No response

Problem-relevant frontend configuration

No response

Javascript errors shown in your browser console/inspector

TypeError: cannot use 'in' operator to search for "area_id" in "{{ covers }}"
    y script_i18n.ts:102
    f script_i18n.ts:53
    value ha-automation-action-row.ts:230
    update lit-element.ts:160
    performUpdate reactive-element.ts:1329
    scheduleUpdate reactive-element.ts:1261
    _$Ej reactive-element.ts:1233
    requestUpdate reactive-element.ts:1208
    set reactive-element.ts:726
    j lit-html.ts:1883
    _$AI lit-html.ts:1825
    v lit-html.ts:1192
    g lit-html.ts:1540
    _$AI lit-html.ts:1384
    p directive-helpers.ts:195
    update repeat.ts:342
    _$AS directive.ts:134
    N lit-html.ts:1085
    _$AI lit-html.ts:1362
    v lit-html.ts:1192
    g lit-html.ts:1540
    _$AI lit-html.ts:1384
    B lit-html.ts:2183
    update lit-element.ts:165
    performUpdate reactive-element.ts:1329
    scheduleUpdate reactive-element.ts:1261
    _$Ej reactive-element.ts:1233
    requestUpdate reactive-element.ts:1208
    set reactive-element.ts:726
    j lit-html.ts:1883
    _$AI lit-html.ts:1825
    v lit-html.ts:1192
    g lit-html.ts:1540
    _$AI lit-html.ts:1384
    B lit-html.ts:2183
    update lit-element.ts:165
    performUpdate reactive-element.ts:1329
    scheduleUpdate reactive-element.ts:1261
    _$Ej reactive-element.ts:1233
    requestUpdate reactive-element.ts:1208
    set reactive-element.ts:726
    update dynamic-element-directive.ts:28
    update dynamic-element-directive.ts:27
    _$AS directive.ts:134
    N lit-html.ts:1085
    _$AI lit-html.ts:1362
    v lit-html.ts:1192
    g lit-html.ts:1540
    _$AI lit-html.ts:1384
    B lit-html.ts:2183
    update lit-element.ts:165
    performUpdate reactive-element.ts:1329
    scheduleUpdate reactive-element.ts:1261
    _$Ej reactive-element.ts:1233
    requestUpdate reactive-element.ts:1208
    set reactive-element.ts:726
    j lit-html.ts:1883
    _$AI lit-html.ts:1825
    v lit-html.ts:1192
    g lit-html.ts:1540
    _$AI lit-html.ts:1384
    v lit-html.ts:1192
    g lit-html.ts:1540
    _$AI lit-html.ts:1384
    T lit-html.ts:1618
    _$AI lit-html.ts:1403
    v lit-html.ts:1192
    g lit-html.ts:1540
    _$AI lit-html.ts:1384
    v lit-html.ts:1192
    g lit-html.ts:1540
    _$AI lit-html.ts:1384
    v lit-html.ts:1192
    g lit-html.ts:1540
    _$AI lit-html.ts:1384
    B lit-html.ts:2183
    update lit-element.ts:165
    performUpdate reactive-element.ts:1329
    scheduleUpdate reactive-element.ts:1261
    _$Ej reactive-element.ts:1233
    requestUpdate reactive-element.ts:1208
    set reactive-element.ts:726
    j lit-html.ts:1883
script_i18n.ts:64:12


### Additional information

_No response_
ildar170975 commented 2 months ago

I do not think you can use this:

      - service: cover.open_cover
        target: "{{ covers }}"

1st, covers is not a variable - it is an "input" and is supposed to be used along with !input when addressed. 2nd, do not think that it is allowed to use other inputs/variables for default.

seblu commented 2 months ago
  1. The template is rendered when the automation is fired. cover is a variable in the context of where open_action is substituted. I removed the end of the blueprint to simplify the report. Here is what is look like.
action:
- variables:
    covers: !input covers
- choose:
  - alias: Open cover(s)
    conditions:
    - condition: trigger
      id: sunrise
    sequence: !input open_action

This is an elegant way to create default actions. IIRC, sequence cannot use templates.

  1. It's documented :

    You can use a template returning a native dictionary as well, which is useful if the attributes to be set depend on the situation.

Not a perfect argument but let me remind you that the blueprint/automation works (and for months), so the core is accepting it.

ildar170975 commented 2 months ago
  1. cover is a variable in the context of where open_action is substituted

This is an important info; otherwise it was not clear since you are using same name for a variable & input. Tried to reproduce your case, it seems to work OK, no errors in Log:

blueprint:
  name: test_input
  domain: automation
  input:
    input_INPUT_BOOLEAN:
    input_ACTION:
      default:
        - service: input_boolean.toggle
          target:
            entity_id: >-
              {{ INPUT_BOOLEAN }}
      selector:
        action:
trigger: []
action:
  - variables:
      INPUT_BOOLEAN: !input input_INPUT_BOOLEAN
  - sequence: !input input_ACTION
automation:
  - alias: test_input_1
    id: test_input_1
    use_blueprint:
      path: test/test_input.yaml
      input:
        input_INPUT_BOOLEAN: input_boolean.test_boolean_2
ildar170975 commented 2 months ago

BTW, have you tried to expand this block? It shows this in my simplified case: image and it is possible to create an automation in yaml successfully.

seblu commented 2 months ago

Yes, no problem with block expansion and we can edit the YAML. The issue is in the label/description of the expandable block.

I guess the function which try to describe the action (create the text) try to parse the target of the YAML but is unhappy with target not being a map, because it can't use in on strings.