Jump to content

Send a message to a client


fizzyade

Recommended Posts

fizzyade

I’m searching but can’t find anything (I am in pain and taken morphine, so apologies if I missed the obvious), I’d like to know how to send a message to a user using a HTTP request.

 

I’ve done a whole load of automation using node-red, I have a raspberry pi zero w with a touch phat which I have buttons set up on, so one of them puts the sonos beam in the bedroom into night mode without me having to fire up the sonos app, it also creates an even which fires in the morning to take the beam out of night mode automatically and so forth.

 

I suffer with painsomnia (unable to sleep due to chronic pain) and often spend most of the night away watching films, I very often set the timer on the TV to go off, but it’s a bit of a pain to do, especially as I can do everything else from the shield remote apart from that.

 

So I have a button set up on the pi which resets a counter for 2 hours after which it turns off the bedroom TV, what I want to achieve is that when I get to a minute I’d like to send a message to my emby (that’s all we use) to say “TV will turn off in 1 minute” and then also repeat this at 15 seconds, this means if I’m still watching I can hit the button again to reset the timer to 2 hours again, if I’ve fallen asleep then I won’t see it and the TV will go off.

 

So TLDR, can I use the api endpoint to send a message to a given client?

 

Thanks

@@chef

Link to comment
Share on other sites

rechigo

If you send a POST to /Sessions/{SessionID}/Message with a JSON body containing a property of "Text", it will pop up a regular dialog on the device that session is tied to.

POST: /Sessions/ID/Message

{

    "Text": "Hello world!"

}

0jh.png

 

Additionally, if you add another property of "TimeoutMs", it'll turn it into a toast notification in the bottom left that will auto dismiss:

POST: /Sessions/ID/Message

{

    "Text": "Hello world!",

    "TimeoutMs": 2500

}

3y0.png

 

Keep in mind this isn't supported on every client, but I believe most Emby clients support it now

Link to comment
Share on other sites

fizzyade

Cool, awesome.  I will have a play, I only need it to work on the shield as that’s all we use.

 

Although I realised that I can send s command to the LG TV (WebOS) I was wanting to primarily doing this on to show a message and that’s working perfectly.

 

The system is working, I touch the button and it starts the timer, if I press it again it restarts again from 2 hours.  When you are in the final 60 seconds, it shows a message at 60, 30, and 10 seconds.  If you touch the sleep timer button, it cancels the tv off, stops the timer and then restarts the 2 hour timer again.

Link to comment
Share on other sites

fizzyade

Humn, subtly this isn't what I want.  This is assuming there's a playback session active, it may have ended.

 

What I want to do is send a message to a specific device, not a playback session.

 

@@Luke this is something that is useful for various automation things, like maybe putting a nessage up "somebody at the door" or in my case, the TV is about to go off unless I reset the timer.

Link to comment
Share on other sites

fizzyade

Each session should have a device ID associated with it.

 

@@Luke this is something that is useful for various automation things, like maybe putting a nessage up "somebody at the door" or in my case, the TV is about to go off unless I reset the time

 

Does that mean that regardless of whether a stream not being played I can get a session ID for a device and then send a message to it?

 

In the GUI you can only send a message by clicking on the icon on the item being played, I was assuming that a given playback is a session.

 

Edit: duh.

 

I think it does.  I just realised there's an API browser/tester.

Edited by fizzyade
Link to comment
Share on other sites

fizzyade

And here's the flow:

 

you need to pass a payload object in with the following fields:

 

msg.payload.url = "http://myembyserver.com<:port>"

msg.payload.apikey = "<api key>"

msg.payload.device = "<name of device>" // i.e "Lounge SHIELD"

msg.payload.message "Hello World"

msg.payload.title "You Have Mail"

msg.payload.timeout = 1000

 

It will then display the message on that device.

 

I'm tempted to actually make a node for node-red.

[{"id":"cbc8fa28.7eac28","type":"tab","label":"Emby","disabled":false,"info":"\n<p>Displays a message on an emby device.</p>\n\n<h3>Inputs</h3>\n    <dl class=\"message-properties\">\n        <dt>payload.apikey\n            <span class=\"property-type\">string</span>\n        </dt>\n        <dd> the emby api key. </dd> \n        <dt>payload.url\n            <span class=\"property-type\">string</span>\n        </dt>\n        <dd> the url of the emby server. </dd>\n        <dt>payload.message\n            <span class=\"property-type\">string</span>\n        </dt>\n        <dd> the url of the emby server. </dd>\n        <dt>payload.title\n            <span class=\"property-type\">string</span>\n        </dt>\n        <dd> the title of the message. </dd>\n        <dt>payload.timeout\n            <span class=\"property-type\">number</span>\n        </dt>\n        <dd> the message timeout in milliseconds. </dd>\n    </dl>\n\n\n\n\n"},{"id":"4b9f5297.26e08c","type":"http request","z":"cbc8fa28.7eac28","name":"","method":"GET","ret":"obj","paytoqs":false,"url":"{{{emby.url}}}/emby/Devices?api_key={{{emby.apikey}}}","tls":"","persist":false,"proxy":"","authType":"","x":430,"y":440,"wires":[["5b1f87.64b9a078"]]},{"id":"5b1f87.64b9a078","type":"function","z":"cbc8fa28.7eac28","name":"find device","func":"for(i=0;i<msg.payload.Items.length;i++) {\n    if (msg.payload.Items[i].Name==msg.emby.device) {\n        msg.emby.deviceId = msg.payload.Items[i].Id\n\n        node.send(msg)\n    }\n}\n","outputs":1,"noerr":0,"x":430,"y":480,"wires":[["7b967440.b9d40c"]]},{"id":"7b967440.b9d40c","type":"http request","z":"cbc8fa28.7eac28","name":"","method":"GET","ret":"obj","paytoqs":false,"url":"{{{emby.url}}}/emby/Sessions?api_key={{{emby.apikey}}}","tls":"","persist":false,"proxy":"","authType":"","x":430,"y":520,"wires":[["48497bf8.de1894"]]},{"id":"48497bf8.de1894","type":"function","z":"cbc8fa28.7eac28","name":"find session","func":"for(i=0;i<msg.payload.length;i++) {\n    if (msg.payload[i].DeviceId==msg.emby.deviceId) {\n\n        msg.url = msg.emby.url+\"/emby/Sessions/\"+msg.payload[i].Id+\"/Message?Text=\"+msg.emby.message+\"&Header=\"+msg.emby.title+\"&TimeoutMs=\"+msg.emby.timeout.toString()+\"&api_key=\"+msg.emby.apikey\n        msg.payload = ''\n        \n        node.send(msg)\n    }\n}\n","outputs":1,"noerr":0,"x":430,"y":560,"wires":[["6e735c0c.7e3244"]]},{"id":"6e735c0c.7e3244","type":"http request","z":"cbc8fa28.7eac28","name":"","method":"POST","ret":"txt","paytoqs":false,"url":"","tls":"","persist":false,"proxy":"","authType":"","x":430,"y":600,"wires":[[]]},{"id":"bd9186e3.1a0278","type":"function","z":"cbc8fa28.7eac28","name":"initialise","func":"msg.emby = {}\n\nmsg.emby.url = msg.payload.url\nmsg.emby.apikey = msg.payload.apikey\nmsg.emby.device = msg.payload.device\nmsg.emby.message = msg.payload.message\nmsg.emby.title = msg.payload.title\nmsg.emby.timeout = msg.payload.timeout\n\nreturn msg;","outputs":1,"noerr":0,"x":420,"y":400,"wires":[["4b9f5297.26e08c"]]},{"id":"393be42d.c2179c","type":"link in","z":"cbc8fa28.7eac28","name":"sendEmbyMessage","links":["f3c60bc3.f788f8"],"x":215,"y":400,"wires":[["bd9186e3.1a0278"]]}]
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...