Can't get REST to work for LMS control

Hi! I’ve been reading and trying for days to get RESTful to work…

Logitech Media Server (192.168.1.127:9000)

Using the favorites list I can, for example type the following address to play a favorite;

http://192.168.1.127:9000/plugins/Favorites/index.html?action=play&index=0`

When the command is send, it replies in the browser with

anyurl processed

I used this in Domoticz to list my radio stations and Spotify playlists. When I create a switch or script in HA, the radio stations change every 10 seconds as HA assumes that the command was not received.
I tried Node-Red too, but the same issue arises.

Any help is much appreciated, I feel like a total noob

use this example

You need to post your HA YAML code. There are just too many RESTful components for us to guess which you used and how you used it. Given your comment it sounds like you’re using a RESTful sensor where maybe you should be using a RESTful command.

Understood. Currently, there are no sensors or switches related to the function that I am trying to use. Unfortunately I couldn’t make much sense from the example posted before

What I am trying to achieve is to create an execute button or script, which sends the URL listed below.

config.yaml

# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:

# Uncomment this if you are using SSL/TLS, running in Docker container, etc.
# http:
#   base_url: example.duckdns.org:8123

# Text to speech
tts:
  - platform: google_translate

group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

# Example configuration.yaml entry for USB/serial connected Smartmeter
sensor:
  - platform: dsmr
    port: /dev/serial/by-id/usb-FTDI_FT232R_USB_UART_AC2F1ATY-if00-port0
    dsmr_version: 5
    
# Example configuration.yaml entry
discovery:

remote:
    platform: harmony
    name: N&N
    host: 192.168.1.200

media_player:
  - platform: squeezebox
    host: 192.168.1.127

shelly:

input_text:
  rest_cmd_url: 
    name: Q-Music

rest_command:
    rest_cmd:
        url: http://192.168.1.127:9000/plugins/Favorites/index.html?action=play&index=0

So you just “call” it by using the rest_command.rest_cmd service.

Have you tried running it, e.g., from the SERVICES tab of the Developer Tools page to see if it does what you expect?

Are you asking how to invoke that service from the UI?

Previously you said, “When I create a switch or script in HA, the radio stations change every 10 seconds.” Is that not a problem anymore? (I.e., did you remove the switch/script???)

When calling the service with rest_command.rest_cmd and the http address: I receive the following error:

Error handling message: expected dict for dictionary value @ data['service_data']. Got 'http://192.168.1.127:9000/plugins/Favorites/index.html?action=play&index=0' 

I removed the script as it didn’t work

What do you mean by that? Specifically, what do you mean by “and the http address”? To call the service it’s just rest_command.rst_cmd (based on the config you shared above.) I have no idea what you mean by what you said. You need to be more explicit. There are several ways to “call a service.”

What script? You didn’t show any script.

This is what I used in my config.yaml file but the receiving device (logitech media server) does not respond.

switch:
  - platform: command_line
    switches:
      lms_radio538:
        command_on: curl -s http://192.168.1.127:9000/plugins/Favorites/index.html?action=play&index=0
        command_off: curl -s http://192.168.1.127:9000/status.html?p0=button&p1=STOP

With ‘calling the service’ I meant from the developer tab
image

I indeed removed the script as it didn’t function and I wanted to avoid confusion

But previously you said, “When I create a switch or script in HA, the radio stations change every 10 seconds.” Which is it?

Sorry, it’s kind of hard to follow you when you seem to contradict yourself on subsequent replies. Of course, I might just be me misunderstanding you.

Again, you didn’t show a script. The term “script” means something specific in HA, so it gets confusing when you use the term incorrectly. It seems you’re new to HA, so I’m just pointing this out to make helping you easier in the future.

So, back to basics. You invoked your rest_command.rst_cmd service, but I think you said there was no response from the device. Did you check HA’s logs to see if there were any warnings or errors?

Phil, I’m sorry, I have tried so many different options, that I can totally understand that my replies cause confusion.

At the moment I have a blank setup, no switches or scripts. What I try to do is to have a button named after a radio station which, when pressed, fires http://192.168.1.127:9000/plugins/Favorites/index.html?action=play&index=0

Nothing else. Perhaps you could guide me in the right direction on how to achieve this.

No problem.

Using the rest_command you had defined earlier should be a part of a working solution. However, if it doesn’t work when you invoke it from the SERVICES tab of the Developer Tools page, then that needs to be addressed first.

You might try enabling debug for RESTful commands:

logger:
  default: info
  logs:
    homeassistant.components.rest_command: debug

Add that and your RESTful command back to your config and restart HA. Then try invoking it again. Then check home-assistant.log for any related messages. There should be at least one. If it “works” (from HA’s perspective), then there should be a DEBUG message saying so. If there was some problem sending the request then there should be a WARNING or ERROR message.

If HA thinks it works, but the device still doesn’t respond, then it has to be some sort of networking issue.

I’ve got it working!
When I was using the services tab, it didn’t list the rest_command, so I added

rest_command:

to the configuration.yaml and then it was now listed on the services tab. After some testing I have a fully working list of commands:

configuration.yaml

rest_command:
  stop_playing:
    url: http://192.168.1.70:9000/status.html?p0=button&p1=STOP
  next_track:
    url: http://192.168.1.70:9000/status.html?p0=button&p1=jump_fwd
    method: GET
  previous_track:
    url: http://192.168.1.70:9000/status.html?p0=button&p1=jump_rew
    method: GET
  radio_538:
    url: http://192.168.1.70:9000/plugins/Favorites/index.html?action=play&index=2
    method: GET
  kitchen:
    url: http://192.168.1.70:9000/plugins/Favorites/index.html?action=play&index=4
    method: GET
  multiroom_jazz:
    url: http://192.168.1.70:9000/plugins/Favorites/index.html?action=play&index=5
    method: GET
  q_music:
    url: http://192.168.1.70:9000/plugins/Favorites/index.html?action=play&index=8
    method: GET
  q_non_stop:
    url: http://192.168.1.70:9000/plugins/Favorites/index.html?action=play&index=9
    method: GET

Then, to make buttons for the frontend I used scripts;

scripts.yaml

'1583752481578':
  alias: Q-Music
  sequence:
  - data: {}
    service: rest_command.q_music
'1583829182385':
  alias: Stop playing
  sequence:
  - data: {}
    service: rest_command.stop_playing
'1583829938930':
  alias: next track
  sequence:
  - data: {}
    service: rest_command.next_track
'1583829958559':
  alias: previous track
  sequence:
  - data: {}
    service: rest_command.previous_track
'1583830038728':
  alias: Radio 538
  sequence:
  - data: {}
    service: rest_command.radio_538
'1583830075547':
  alias: S_Kitchen
  sequence:
  - data: {}
    service: rest_command.kitchen
'1583830094996':
  alias: S_Multiroom Jazz
  sequence:
  - data: {}
    service: rest_command.multiroom_jazz
'1583830150948':
  alias: Q-Music
  sequence:
  - data: {}
    service: rest_command.q_music
'1583830166749':
  alias: Q-Music Non-Stop
  sequence:
  - data: {}
    service: rest_command.q_non_stop

I’ve got the same problem, running the commands thru my browser and everything works. Trying it via HA and nothing :-(. Do you have some more tips for me?

Please forget it, found it, forgot one ‘&’.