Using input_select output in JSON payload

I’m at the bottom of a very steep learning curve… and perhaps i should have listened to Paul Hibbert and I really don’t have any business trying HA… but here we are. This time last week I didn’t know how to setup a virtual machine - so there is progress being made (I think?)

Having setup the Hue (x38), Sonos and Harmony (and Google cast instances, but those keep losing connection so I’m going to take the L on that one for awhile) - I’m getting more creative and looking at my nvidia Shield with Kodi and thinking I must be able to have some fun with that.

I’ve currently got a Google Home–IFTTT–webhooks–local server setup to control some of the inputs to Kodi - like changing the TV channel. (GoogleHomeKodi)

Using rest_command we can short circuit that and send JSON commands directly to my local server.
I’ve got most of it working. If I hard-code the name of the station into rest_command, everything works:

rest_command:
  channel_7_run:
    url: http://192.168.1.104:8099/playpvrchannelbyname?q=channel_7
    method: POST
    payload: '{"token":"blah"}'
    content_type: 'application/json; charset=utf-8'

Ultimately, I’d like to be able to have an input_select drop down list in lovelace where you choose the station you want and that fires the rest_command through an automation. But I can’t work out how to soft code the current state of the input_select into the JSON.

This is as far as I’ve got

rest_command:
  channel_7_run:
    url: http://localhost:8099/playpvrchannelbyname?q={{ state('input_select.channel_selector') }}
    method: POST
    payload: '{"token":"blah"}'
    content_type: 'application/json; charset=utf-8'

That’s clearly not right - and as I said I probably have no business trying. But thought I’d throw it out there in case anyone feels like giving me some pointers?

input_select:
  channel_select:
    name: Channel Selector
    options:
      - "channel_7"
      - "channel_9"
      - "ABC"
      - "SBS"
      - "Channel_10"
    initial: channel_7
    icon: mdi:remote-tv

Sorry - I’ve also got this too…

Close. You just need to change state to states, and put the whole string in quotes:

    url: "http://localhost:8099/playpvrchannelbyname?q={{ states('input_select.channel_selector') }}"
1 Like

Thanks very much for the reply. That’s one of the variants I’ve tried - which results in “unknown” being passed to the server and this error in the HA logs:

> 2020-06-25 23:18:35 WARNING (MainThread) [homeassistant.components.rest_command] Error. Url: http://localhost:8099/playpvrchannelbyname?q=unknown. Status code 500.

Any idea what else I’ve done wrong?

You had a typo I missed. Should be input_select.channel_select.

1 Like

Very kind of you not to just respond with a face slap emoji! That is incredibly frustrating.

Works perfectly without the typo…

1 Like