Media control automation in HA revisited

Last Updated or created 2024-04-07

I was not happy with my old setup to control all media devices in my living room.

Controlling all devices using a single button and automations was not easy.

Problems encountered :

  1. Switching from one device to another toggled a device used by both.
  2. Switching from TV to Spotify (using my Onkyo), turned off the TV and cec turned off the Onkyo
  3. Using the Home Assistant Onkyo integration, I could select NET but not NET>Spotify
  4. The Harmony hub I’m using for Infrared Control didn’t expose all buttons.
  5. My Set-top box only power toggles. No way of reading the state.

Addressing problems:

Number 1 & 2 : Disable CEC, and manual add all that cec tried to do for me. (

Number 5 :
(See post :

Number 3 & 4 : Two options, integrate my web controller for onkyo.
Or give HA more functionality.

Lets add an Onkyo python script to HA.
Open a webterminal and enter following command

pip install onkyo-eiscp

This will give you:
(Hint: want to copy text from the web terminal? Hold shift while selecting text)

➜  ~ pip install onkyo-eiscp   
Looking in indexes:,
Collecting onkyo-eiscp
  Downloading (9.9 kB)
Collecting docopt>=0.4.1 (from onkyo-eiscp)
  Downloading (17 kB)
Collecting netifaces (from onkyo-eiscp)
  Downloading (8.9 kB)
Downloading (45 kB)
   ━━━━━━━━━ 45.7/45.7 27.8     eta 0:00:00
             kB        MB/s                
Downloading (13 kB)
Downloading (13 kB)
Installing collected packages: netifaces, docopt, onkyo-eiscp
Successfully installed docopt-0.6.2 netifaces-0.11.0 onkyo-eiscp-1.2.7
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead:
➜  ~ onkyo
  onkyo [--host <host>] [--port <port>]
        [--all] [--name <name>] [--id <identifier>]
        [--verbose | -v]... [--quiet | -q]... <command>...
  onkyo --discover
  onkyo --help-commands [<zone> <command>]
  onkyo -h | --help
➜  ~ which onkyo

Now we can integrate shell commands in HA!

NET > Spotify
onkyo --host NSV0A0

Spotify > track info
onkyo --host NTIQSTN

Spotify > Artist
onkyo --host NATQSTN

Turn Onkyo ON/OFF
onkyo --host PWR01
onkyo --host PWR00

Get Power state
onkyo --host PWRQSTN

Mute on/off
onkyo --host AMT01 or AMT00

Volume Level
onkyo --host MVLQSTN

Home Assistant Shell Command example

  - platform: command_line
        command_on: "/usr/bin/onkyo --host AMT00"
        command_off: "/usr/bin/onkyo --host AMT01"

Getting album art:

Get image from below url.
Note! .. its a static non refreshing image!

Note: This gives me a file which shows fine in a browser, but being a http feed you cannot embed this in a https site.
Another ‘problem’ with this image is that it includes headers, rendering this a invalid jpg when processing!
(remove first 3 lines programmatically)
I also want to have it updated, so I could make a mjpeg streamer for this.
Probably i’m going to use my reverse proxy which uses SSL offloading to access cover art over https.
(Then I can push this cover image on this webblog so you guys can see what we are listing to)

Another idea is to push this to an arduino display.

Not using https?

You can embed the album art in a dashboard. This won’t refresh, but the added time code will stop caching problems.

type: picture<br>image:{{now().timestamp()|int }}")


Make the automations foolproof.

Watching TV and want to listen to Spotify?

  1. Turn TV off
  2. Switch Onkyo to Net and Spotify
  3. (Adjust volume)
  4. Toggle TV set-top box off


Next todo:
Cover art embed in HA.
Maybe in embed in this blog.
Make a small cover art display.

PHP code to strip lines and put behind a reverse proxy

header('Content-type: image/jpg');
$lines = file_get_contents('', false);
$lines = explode("\n", $lines);
$content = implode("\n", array_slice($lines, 3));
print $content;

You can use Generic Camera to refesh!

Current Cover Art

Get cover art from Logitech Media Server<playerid>
Spread the love

Leave a Reply

Your email address will not be published. Required fields are marked *