Input select in scripts get value of selector

Hi,

i do have a problem with a script i’d like to write.

Idea: send text to a selected device over noti service

Problem: I somehow can not get a grip on the value from the selector field.

It would be an easy if else based on the select field.

## fields ##
fields:
  who:
    selector:
      select:
        options:
          - Daniel
          - Peter
        multiple: true
    name: Who
    description: Who will get the message?
    default: []
  text:
    selector:
      text: null
    name: Text
    description: Message to be sent.

## script ##
alias: Post
sequence:
  - if:
      - condition: template
        value_template:{{ who== "Peter"}} # <- here is the problem 
    then:
      - service: persistent_notification.create
        metadata: {}
        data:
          message: {{text}}
          title: Peter
    enabled: true
mode: single


I tried a lot of things. states..state of who. Maybe who conatins in id and i can’t compare (==) with a string.

Howdy caladrien,

You are setting up a list in the selector by allowing multiple, and are looking for a string in the notify. Set multiple to false. You can only notify one entity at a time.

There may be other problems, I’m not good at floating templates OTF and I didn’t test anything.

Assign Who to a variable then reference the variable in the template. I have changed the template so that it correctly handles the possibility that more than one person has been selected (because you have set the selector’s multiple option to true).

## fields ##
fields:
  who:
    selector:
      select:
        options:
          - Daniel
          - Peter
        multiple: true
    name: Who
    description: Who will get the message?
    default: []
  text:
    selector:
      text: null
    name: Text
    description: Message to be sent.

## script ##
alias: Post
sequence:
  - variables:
      w: !input Who
  - if:
      - condition: template
        value_template: "{{ 'Peter' in w }}" 
    then:
      - service: persistent_notification.create
        metadata: {}
        data:
          message: {{text}}
          title: Peter
    enabled: true