Trying to create switch that sends REST command, but not working

I am trying the send a rest-command with a switch, the command is just a web-adress, it starts playing a file. I Tred with a command line switch and curl. That doesn’t work at all.

- platform: command_line
  switches:
    ringeklokke:
      command_on: "/usr/bin/curl -X GET http://192.168.1.25:52199/MCWS/v1/Playback/PlayByKey?Key=1414819&Zone=10012&ZoneType=ID"
      command_off: "/usr/bin/curl -X GET http://192.168.1.25:52199/MCWS/v1/Playback/Pause?State=-1&Zone=10012&ZoneType=ID"
      friendly_name: JRMC

So then i tried with a REST-switch. That semi-works but its behavior is baffling to me. When i turn it on, it plays 3 times. Turning it off makes it play once. And it also seems to just play every 15 seconds or so for no reason.

- platform: rest

resource: http://192.168.1.25:52199/MCWS/v1/Playback/PlayByKey?Key=1414819&Zone=10012&ZoneType=ID
name: jrmc2

I find it weird that the second semi-works, but the first does not, even though they are the same command. Just putting the adress in the browser and pressing enter works fine. Any suggestions? What am i doing wrong in creating the command line switch?

A RESTful Switch does a POST to the resource to turn the light on, sending true in the body by default, and sends a POST to the resource to turn the light off, sending false in the body by default. And it periodically does a GET from the resource to get the state of the switch. So basically, a RESTful Switch will not do what you want.

For the Command Line Switch, do you see any errors (on the Info page, or in home-assistant.log)? Did you try setting logger to debug?

For the curl command you shouldn’t need -X GET; that’s the default. Also I usually use curl’s -s (silent) switch.

Thanks, guess the RESTful switch isn’t the way to go. I tried the CURL command directly in the terminal on the server HA is running on. It still doesn’t work (in the sense that the file isn’t playing), but it does return the source of the webpage as if it did ( xml version=“1.0” encoding=“UTF-8” standalone=“yes” Response Status=“OK”, this is the same as the source of the webpage that pops up if i just input it in a browser).

When you do it in a browser, does it ask for a username & password, or maybe did it do that once and remember the credentials? Maybe the device you’re sending this to requires login info???

And what exactly is playing the audio? The device you’re sending this command to? Or does it play in the browser?

It actually requires login, i have just redacted it, the actual command i send begins with http://user@pass, i just removed the user/pass part of the command, as I didn’t want to post it online, so i think it should be correct. (especially since it works in a sense as a REST-switch)

It is a regular media player, that plays a file when it receives the command.
https://wiki.jriver.com/index.php/Web_Service_Interface

Ok, thanks for the clarification. Well, then I’m stumped. Any chance you have a network sniffer that can see the HTTP traffic between the browser and the media player? Maybe there’s something the browser is putting in headers that you don’t have when you do it via curl? Does the media player have an HTTP API doc that explains how to interact with it? Maybe it will point out what you’re missing.

Thanks after you feedback i got on the right track, i tried some different REST-commands directly in the terminal, and it didn’t work, but i found out the url have to be in quotes, (maybe because of some special chars?), so i put the url in quotes, and the total command in quotes outside of that. Like this:

command_on: ‘/usr/bin/curl -X GET “http://192.168.1.25:52199/MCWS/v1/Playback/PlayByKey?Key=1414819&Zone=10012&ZoneType=ID”’

And that works, thanks for your help.

1 Like