Simple Rest Help

Hi All,
Im sure im overly complicating this as ive tried a hundred different ways.

Id like to pass “device” as well as “message” to my notify script

  - name: ga_broadcast
    platform: rest
    resource: !secret assistant_relay_url
    method: POST_JSON
    data_template:
      user: "Home Assistant"
      broadcast: "true"
      talkback: "false"
      command: "{{ message }}" 
      device: "{{ device }}"

I cant for the life of me work out how to do this. Id assume something very simple like

message: hello
data:
    device: "Living Room speaker"

However, this is not working.
Any points please experts?

Well, the message is part of the service data.

data:
  device: "Living Room speaker"
  message: hello
1 Like

I get “required key not provided then” for Message.

Passing “Message” works fine, it just doesnt receive “Device”

The “Service Data” field is for Service Data, there is no need for data: here, that’s for calling it programatically.
In this field,

device: "Living Room Speaker"
message: "Hello"

should just work.

Unfortunately, ive tried that too

I get message saying “device” is not allowed?

Ah, I’m sorry, it’s different for the notification platform, though you’ve double mapped it.
What’s the error message when using

message: hello
data:
    device: "Living Room speaker"

When running that, it fires absolutely fine. The message is passed across, however its as if {{ device }} is empty.

I have tested this by changing my notify script to "command : “{{ device }}” and there is nothing broadcast. Changing it back to “command: " {{ message }}” broadcasts when ive put in the message.

Hm, weird.
And you’re absolutely sure that “Living Room speaker” - Two of the words capitalized, with spaces, is a valid device identifier?
Since I don’t know who’s receiving that data, I can only guess.
You can go to developer tools - events and listen for a “call_service” event, then look if the data is in there :thinking:

Yes, the capitalisation/spacing is correct. If I copy this into my nofiy script under "device: " it works perfectly.

I’d never used the listen to events before.

So with my notify service as

  - name: ga_broadcast_specific_device
    platform: rest
    resource: !secret assistant_relay_url
    method: POST_JSON
    data_template:
      user: "Home Assistant"
      broadcast: "true"
      talkback: "false"
      command: "{{ message }}" 
      device: "Living Room speaker"

Calling a service such as

message: hello

This works perfectly and sends to the Living Room speaker

However, changing my notify service to

  - name: ga_broadcast_specific_device
    platform: rest
    resource: !secret assistant_relay_url
    method: POST_JSON
    data_template:
      user: "Home Assistant"
      broadcast: "true"
      talkback: "false"
      command: "{{ message }}" 
      device: "{{ device }}"

And calling it as so

message: hello
data:
  device: Living Room speaker

Does not work. It runs the notify service and broadcasts “hello” but isnt picking up the device and just goes across all devices.

When listening to this, as you have directed me too I dont even get a message broadcast.

Im not sure im using it correctly though, I get the below output

 
Event 0 fired 16:19:
{
    "event_type": "notify.ga_broadcast_specific_device",
    "data": {
        "message": "hello"
    },
    "origin": "REMOTE",
    "time_fired": "2021-02-21T16:19:13.972671+00:00",
    "context": {
        "id": "11bef2xxxxxxxx65697",
        "parent_id": null,
        "user_id": "4f3eafbcxxxxxxxx58713ff3"
    }
}

From running this script

However, the script doesnt actually fire and I get a message saying its fired, regardless of what name of notify service i put in the event?

image

Hm, that’s weird.
I meant putting call_service in the “Listen to event” box at the bottom of the Event tab, clicking on “Listen” and then (in another browser tab maybe) calling the service from Developer Tools - Services

Sorry, my bad. Well doing it your (correct!! haha) way means that my notify correctly triggers. But it is still ignorning the device part

Long shot here, but change device: "{{ device }}" to device: "{{ target }}" and use target instead of device when calling the service :thinking:

Well, im not sure how you’ve done it. I had tried using target in a few different verions of this id written but not gotten anywhere.

Initially I just changed it to

message: hello
data:
  target: Kitchen Display

And I was still having the same issue.

However, ive taken target, out of the data and it now works

message: hello
target: Kitchen Display

I cant understand why, but im just so happy it works. Thank you so much for taking the time to respond back and forth today. Its very much appreciated.

1 Like