#blueprint input send notification to multiple device_id

1 messages · Page 1 of 1 (latest)

clever sluice
#

Hello Friends,
Been searching in internet but nothing worked in my case. Always getting below error. My understanding was for_each should loop through each item in its list

Error:value should be a string for dictionary value @ data['actions'][5]['sequence'][2]['else'][0]['device_id']. Got ['xxxxxxxxxx', 'yyyyyyyyyyy'].

input:
  notify_device:
    name: "Device to notify"
    selector:
      device:
        integration: mobile_app
        multiple: true
### removed lines in between
- if:
    - condition: template
      value_template: "{{ notify_device_id | length > 0 }}"
    then:
      - repeat:
          for_each: !input notify_device
          sequence:
            - device_id: repeat.item      ## This is where the problem is coming
              domain: mobile_app
              type: notify
              title: !input notification_title
              message: "The {{ binary_sensor_friendly_name }} is closed."
    else:
      - device_id: !input notify_device
        domain: mobile_app
        type: notify
        title: !input notification_title
        message: "The {{ binary_sensor_friendly_name }} is closed."
cloud wren
#

repeat.item needs to be in a template right?

clever sluice
#

i saw many exaple where it was used as repeat.item or '{{ repeat.item }}'

cloud wren
#

hmm wonder how that works

clever sluice
#

i mean other languages like python or shell script provides same way like below. What am I missing then. Any advise

do
  $a
done```
cloud wren
#

sure, but I'm not not aware that home assistant has that kind of syntax

#

I could be wrong but I've just never seen that before, and it would surprise me.

clever sluice
#

ok. How to send notification to multiple device then?

cloud wren
#

could you try it like this? device_id: "{{ repeat.item }}"

clever sluice
#

i could see everyone was doing with repeat and for_each

cloud wren
#

can you share where you saw that?

clever sluice
cloud wren
#

ohhh ok it's the else branch

#
else:
      - device_id: !input notify_device
#

You're passing a list where a single device id is expected

clever sluice
clever sluice
cloud wren
#

That error is suggesting you can't do that

#

you can't pass multiple device_ids to mobile app notify

#

you'd have to use a for_each loop again

clever sluice
#

is there any way to print the output of for_each for debugging like echo or print ?

cloud wren
#

I think even though you're guaranteeing the else won't be reached if the list length is one, the syntax check is still evaluating that entire branch with that input

#

so it's failing syntax check

clever sluice
#

let me generate that statement in GUI

#

if template return true then repeat with for_each or direct execution

cloud wren
#

even when there's only one device, !input notify_device is still a list

clever sluice
#

that onw works fine. I tested

cloud wren
#

The error you pasted says the error is in the else branch, that you're passing it a list of device ids

clever sluice
#

problem occurs while i enable multiple

#

ok let me disable else

#

Error:Unknown device '{{ repeat.item }}'.

#

now different error after disabling else

cloud wren
#

hmm, seems as if you can't put templates in that device action

#

This would get easier once mobile app transitions to using the notify entity, but for now I'm not sure I see an easy way to do this 🤔

clever sluice
#

ok. instead of device_id, let me try service with notify.mobile_app_**

cloud wren
#

You can do that, but it's not as easy to get from a device_id to the appropriate service name for that device

#

each device has its own service

clever sluice
#

😞 gave up for now!

wide hill
# clever sluice 😞 gave up for now!

Have you considered using Node Red, where what you are trying is easy? It seems like you have plenty of structured programming knowledge and could pick it up quickly. Lmk if you'd like any resource suggestions.