Use a command_line cover to control TV Volume or Channel?

Hi everyone,

I’m interested in using a cover to control my TV volume (via Broadlink RM Pro IR blaster) so that the GUI is easy to use…

For example, I would like to have something like this (for TV Volume not Garage door)…

instead of what I currently have which is this…

Here’s the code I have so far but it’s not working because I don’t think you can call a Home Assistant script from a command_line cover.

Would anyone have any insight on how I can achieve this? Or is there a different approach I should be considering?

tv_volup:
  sequence:
    service: broadlink.send_packet_192_168_1_202
    data:
      packet: 
        - "JgBQAAABJZMSExITERMSExISEhMSExETEjcSNxI4ETgROBI3EhMROBETEhMSNxITERMSExI3EhMROBE4EhISOBE4ETgSExxxxxAAAAA="

tv_voldown:
  sequence:
    service: broadlink.send_packet_192_168_1_202
    data:
      packet: 
        - "JgBQAAABJ5ITERQRExEUERMRFBEUERMRFDUUNRQ2EzYTNhQ1FBETNhM2FDUUERMRFBEUERM2ExEUERMSEzYTNhM2FDUUccccBJ0gUAA0FAAAAAAAAAAA="

cover:
  - platform: command_line
    covers:
      tv_volume:
        command_open: script.tv_volup
        command_close: script.tv_volmute
        command_stop: script.tv_voldown
        friendly_name: TV Volume

Thanks in advance…

You can use curl to make an API call to the script service.

I updated Light.Template so it handles 'brightness" and it’ll be released in .46. The video shows use via Google Home. It’s running HA scripts behind the scenes

Thanks so much for replying @treno
I got it working using the RESTful API as you recommended :grin:
I had a lot of trouble with the formatting of the command, due to the single and double quotes.

I don’t suppose you know how I can refer to a password and ip address stored in my secrets.yaml rather than writing it directly in the command? Due to the single and double quotes, I’m not sure how I can embed the !secret parameter…

The other problem is that when I click the button repeatedly, i got the below error;

2017-06-01 18:43:46 WARNING (MainThread) [homeassistant.components.script] Script script.tv_voldown already running.
2017-06-01 18:43:47 WARNING (MainThread) [homeassistant.components.script] Script script.tv_voldown already running.
2017-06-01 18:43:48 WARNING (MainThread) [homeassistant.components.script] Script script.tv_voldown already running.
2017-06-01 18:43:48 WARNING (MainThread) [homeassistant.components.script] Script script.tv_voldown already running.
2017-06-01 18:43:49 WARNING (MainThread) [homeassistant.components.script] Script script.tv_voldown already running.

Any idea how I can prevent that error?

Below is the final script I’m using…

script:
  tv_volup:
    sequence:
      service: broadlink.send_packet_192_168_1_###
      data:
        packet:
        - "JgxxxxFAAAAAAAAAAA="
  tv_voldown:
    sequence:
      service: broadlink.send_packet_192_168_1_###
      data:
        packet:
        - "JgxxxxFAAAAAAAAAAA="
  tv_volmute:
    sequence:
      service: broadlink.send_packet_192_168_1_###
      data:
        packet:
        - "JgxxxxFAAAAAAAAAAA="

cover:
  - platform: command_line
    covers:
      tv_volume:
        command_open: >-
          curl -X POST -H "x-ha-access: MyPassword" \-H "Content-Type: application/json" \-d '{"entity_id": "script.tv_volup"}' \http://192.168.1.###:8123/api/services/script/turn_on
        command_close: >-
          curl -X POST -H "x-ha-access: MyPassword" \-H "Content-Type: application/json" \-d '{"entity_id": "script.tv_voldown"}' \http://192.168.1.###:8123/api/services/script/turn_on
        command_stop: >-
          curl -X POST -H "x-ha-access: MyPassword" \-H "Content-Type: application/json" \-d '{"entity_id": "script.tv_volmute"}' \http://192.168.1.###:8123/api/services/script/turn_on
        friendly_name: TV Volume

I don’t think you can.
I handle this by making my commands calls to shell scripts that aren’t included in the confit path.

My PR that’ll be released in 4.6 allows for light.template so you can do this with a light. You can set “brightness” that’ll be passed through to the underlying object and you can pass that through to your script.

Here’s the PR:

Whenever the docs go live my home theater example is in there.