Play internet radio on Onkyo

Do anyone know if its possible to do this?

My script

‘1519681048826’:
alias: onkyo_test
sequence:

  • data:
    entity_id: media_player.onkyo_nrtx646
    service: media_player.turn_on
  • data:
    entity_id: media_player.onkyo_nrtx646
    source: network
    service: media_player.select_source
  • data:
    entity_id: media_player.onkyo_nrtx646
    volume_level: ‘0.1’
    service: media_player.volume_set
  • data:
    entity_id: media_player.onkyo_nrtx646
    media_content_id: http://listen.181fm.com/181-kickincountry_128k.mp3
    service: media_player.play_media

Ever figured this out?

Yes I have.
I’m currently using 0.97.1 but it has worked as far dated as 0.67-ish.
in configuration.yaml

# MediaPlayers
media_player:
#  - platform: plex
#    show_all_controls: true
  - platform: onkyo
    host: 192.168.0.116
    name: Onkyo NRTX646
    sources:
      video2: 'CBL/SAT'
      video3: 'GAME'
      video4: 'AUX'
      video6: 'HTPC'
      dvd: 'BD/DVD'
      phono: 'PHONO'
      cd: 'CD'
      fm: 'FM'
      usb: 'USB'
      network: 'INTERNET'
      strm-box: 'STRMBOX'

I also have the following code in configuration.yaml (edit as you like)

#Define a list of values that can be selected via the
#frontend and can be used within conditions of automation
input_select:
  radio_station:
    name: FM radio
    options:
      - Välj radio
      - RixFM
      - Megapol
      - NRJ
      - Rockklassiker
      - Retro FM
      - FunRadio
      - Guld
      - SR P3
      - Din Gata
      - myRock
      - POP FM
      - Radio Nova
    initial: Välj radio
    icon: mdi:radio
  iradio_station:
    name: Internet radio
    options:
      - Välj radio
      - A State of Trance [Trance]
      - Bandit Rock [Rock/Metal]
      - Nashville FM [Country]
      #- P3 Star [Hits] ###Sänder inte längre
      - HirsMilsch Progressive [Trance]
      - HirsMilsch PsyTrance [Trance]
      - Plasm [Hits]
      - 1291 Alternative Rock [Rock]
      - GuitarMe [Punk]
      - Deep House Lounge [Electronic]
    initial: Välj radio
    icon: mdi:radio-tower

Note that for the FM radio stations you have to set a number of preset stations on your receiver. For the internet radio stations I have found it easier to log into the receiver from the web UI (192.168.1.116 in my case). Set your router to always have that specific adress. Sometimes the web UI becomes unresponsive. To fix it, unplug the power for ten seconds and it will work again.

in automations.yaml I have

- id: '11'
  alias: Vakna till FM Radio
  trigger:
  - at: 06:30:00
    platform: time
  action:
  - data:
      entity_id: script.rixfm
    service: script.turn_on
  condition:
  - condition: state
    entity_id: binary_sensor.workday_sensor
    state: 'on'
- id: '12'
  alias: FM_Radio
  trigger:
  - entity_id: input_select.radio_station
    platform: state
  action:
  - service: script.radio_script
- id: '13'
  alias: Internet_Radio
  trigger:
  - entity_id: input_select.iradio_station
    platform: state
  action:
  - service: script.iradio_script
- id: '1542754609736'
  alias: Stäng av Onkyo på morgonen
  trigger:
  - at: 08:00:00
    platform: time
  condition:
  - condition: state
    entity_id: binary_sensor.workday_sensor
    state: 'on'
  action:
  - data:
      entity_id: media_player.onkyo_nrtx646
    service: media_player.turn_off

In groups.yaml I have

vardagsrum_vy:
  view: yes
  name: Vardagsrum
  entities:
    - group.music_spotify
    - media_player.onkyo_nrtx646

music_spotify:
  name: Music
  entities:
  - input_select.spotify_playlist
  - script.spotify_music
  - input_number.spotify_volume
  - input_select.radio_station
  - input_select.iradio_station

In scripts.yaml I have

rixfm:
  alias: FM_radio_RixFM
  sequence:
  - data:
      entity_id: media_player.onkyo_nrtx646
    service: media_player.turn_on
  - data:
      entity_id: media_player.onkyo_nrtx646
      source: fm
    service: media_player.select_source
  - data:
      entity_id: media_player.onkyo_nrtx646
      volume_level: '0.2'
    service: media_player.volume_set
  - alias: ''
    data: {}
    service: shell_command.all_ch_stereo
  - alias: ''
    data: {}
    service: shell_command.radio_rixfm
radio_script:
  alias: Set_Radio_on_Onkyo
  sequence:
  - data:
      entity_id: media_player.onkyo_nrtx646
    service: media_player.turn_on
  - data:
      entity_id: media_player.onkyo_nrtx646
      source: fm
    service: media_player.select_source
  - data:
      entity_id: media_player.onkyo_nrtx646
      volume_level: '0.2'
    service: media_player.volume_set
  - alias: ''
    data: {}
    service: shell_command.all_ch_stereo
  - data: {}
    service_template: 'shell_command.{% if is_state("input_select.radio_station",
      "RixFM") %}radio_rixfm {%-elif is_state("input_select.radio_station", "Megapol")
      %}radio_megapol {%-elif is_state("input_select.radio_station", "NRJ") %}radio_nrj
      {%-elif is_state("input_select.radio_station", "Rockklassiker") %}radio_rockklassiker
      {%-elif is_state("input_select.radio_station", "Retro FM") %}radio_retrofm {%-elif
      is_state("input_select.radio_station", "FunRadio") %}radio_funradio {%-elif
      is_state("input_select.radio_station", "Guld") %}radio_guld {%-elif is_state("input_select.radio_station",
      "SR P3") %}radio_p3 {%-elif is_state("input_select.radio_station", "Din Gata")
      %}radio_dingata {%-elif is_state("input_select.radio_station", "myRock") %}radio_myrock
      {%-elif is_state("input_select.radio_station", "POP FM") %}radio_popfm {%-elif
      is_state("input_select.radio_station", "Radio Nova") %}radio_nova {% endif %}

      '
iradio_script:
  alias: Set_iRadio_on_Onkyo
  sequence:
  - data:
      entity_id: media_player.onkyo_nrtx646
    service: media_player.turn_on
  - data:
      entity_id: media_player.onkyo_nrtx646
      source: network
    service: media_player.select_source
  - data:
      entity_id: media_player.onkyo_nrtx646
      volume_level: '0.12'
    service: media_player.volume_set
  - alias: ''
    data: {}
    service: shell_command.all_ch_stereo
  - data: {}
    service_template: 'shell_command.{% if is_state("input_select.iradio_station",
      "A State of Trance [Trance]") %}iradio_asot {%-elif is_state("input_select.iradio_station",
      "Bandit Rock [Rock/Metal]") %}iradio_bandit {%-elif is_state("input_select.iradio_station",
      "Nashville FM [Country]") %}iradio_nashville {%-elif is_state("input_select.iradio_station",
      "P3 Star [Hits]") %}iradio_p3star {%-elif is_state("input_select.iradio_station",
      "HirsMilsch Progressive [Trance]") %}iradio_hmprogressive {%-elif is_state("input_select.iradio_station",
      "HirsMilsch PsyTrance [Trance]") %}iradio_hmpsytrance {%-elif is_state("input_select.iradio_station",
      "Plasm [Hits]") %}iradio_plasm {%-elif is_state("input_select.iradio_station",
      "1291 Alternative Rock [Rock]") %}iradio_1291 {%-elif is_state("input_select.iradio_station",
      "GuitarMe [Punk]") %}iradio_guitarme {%-elif is_state("input_select.iradio_station",
      "Deep House Lounge [Electronic]") %}iradio_deephouselounge {% endif %}

      '

In shell_commands.yaml

radio_rixfm: onkyo -t 192.168.0.116 preset=1
radio_nova: onkyo -t 192.168.0.116 preset=3
radio_retrofm: onkyo -t 192.168.0.116 preset=6
radio_funradio: onkyo -t 192.168.0.116 preset=7
radio_p3: onkyo -t 192.168.0.116 preset=8
radio_popfm: onkyo -t 192.168.0.116 preset=10
radio_dingata: onkyo -t 192.168.0.116 preset=11
radio_myrock: onkyo -t 192.168.0.116 preset=13
radio_megapol: onkyo -t 192.168.0.116 preset=14
radio_guld: onkyo -t 192.168.0.116 preset=15
radio_nrj: onkyo -t 192.168.0.116 preset=16
radio_rockklassiker: onkyo -t 192.168.0.116 preset=18
iradio_asot: onkyo -t 192.168.0.116 dock.internet-radio-preset=1
iradio_bandit: onkyo -t 192.168.0.116 dock.internet-radio-preset=2
iradio_nashville: onkyo -t 192.168.0.116 dock.internet-radio-preset=3
iradio_p3star: onkyo -t 192.168.0.116 dock.internet-radio-preset=4
iradio_hmprogressive: onkyo -t 192.168.0.116 dock.internet-radio-preset=5
iradio_hmpsytrance: onkyo -t 192.168.0.116 dock.internet-radio-preset=6
iradio_plasm: onkyo -t 192.168.0.116 dock.internet-radio-preset=7
iradio_1291: onkyo -t 192.168.0.116 dock.internet-radio-preset=8
iradio_guitarme: onkyo -t 192.168.0.116 dock.internet-radio-preset=9
iradio_deephouselounge: onkyo -t 192.168.0.116 dock.internet-radio-preset=10
all_ch_stereo: onkyo -t 192.168.0.116 listening-mode=all-ch-stereo

Thats about it to get the Onkyo working and be able to change music from the web UI

3 Likes

Ah , thnx for sharing… Those are indeed internal presets , that should work indeed… I was hoping you could stream like external links, like m3u files…
But the preset is indeed a nice idea, all though I am limited to the Denon serviced, I can only use their stations then… :wink:

Just 1 question, that shell command, is that onkyo a tool?

The internet stations are indeed .m3u files


The presets on the Onkyo web UI are corresponding to the presets in the shell_command.

When using Home Assistant on 0.67 I had to install an Onkyo script from Miracle2k on GitHub Onkyo EISCP to get it working. However I’m now using hassio and have not installed it to get it working

ok, thats different, on my denon receiver, i cant define m3u files as a favorite , i need to use the denon ones from the denon server, cant customize it :frowning:

thats why i was hoping to send a m3u link to my receiver , but it doesnt accept that like a chromecast for example
i need to setup another dlna server and configure some streams there, then i with my denon i can browse that dlna server and play the radio

aha ok, you put me on right track , seems on VTuner, thats the online portal for internet radio stations for denon receivers, i can add there manual m3u links , those will shop up on my favorites!!
yeah, solved!

although i am limited to 4 favorites as memory presets, but my actual favorites list is longer, like your presets
now i need to find a way to activate a preset… i will find that

thnx for your tips!

Your welcome. Hope you get it working

hi, i made a small python script to set any stream active on my onkyo tx-nr515. ( in this case: a fix stream… )
Don’t know if it works on any other types/brands.

this example set the net-streaming on the dutch station: radio538.
what is does is:

  1. get all favorite stations from the receiver.
  2. replace the first with the new stream,
  3. send new favorites-list back to receiver.
  4. the issue some commands to set receiver on, volume 11, source=net and select favorite 1.
  5. then send original favorite list back to receiver, so all your favorites are still the same.

the script uses the eiscp lib.
install it with:
pip install onkyo-eiscp

and it uses BeautifulSoap
install it with:
pip install beautifulsoup4

import eiscp
import requests
from bs4 import BeautifulSoup

onkyo_ip = '192.168.1.68'


onkyo_url = 'http://' + onkyo_ip + '/station.cgi'
#html_text = urllib2.urlopen(onkyo_url)
loRequest = requests.get(onkyo_url)
soup = BeautifulSoup(loRequest.content, 'html.parser')

form = soup.find('form', attrs={'name': 'station_list'});

myObject = {}


print('get current fovorites' );
for _input in form.find_all('input'):
  lsName = _input.get('name');
  myObject[ _input.get('name') ] = _input.get('value')
  
#  print(_input.get('name') + '=' + _input.get('value') )
  
lsName = myObject[ 'name00' ]
lrURL = myObject[ 'url00' ]
print('original name: ' + lsName );
print('original url: ' + lrURL );

print('replace first favorite with the new favorite')
myObject[ 'name00' ] = 'Radio 538'
myObject[ 'url00' ] = 'http://playerservices.streamtheworld.com/api/livestream-redirect/RADIO538.mp3'

myObject['save.x'] = '1'
myObject['save.y'] = '1'
#print( myObject )

print( 'send fovorite list to onkyo' );
x = requests.post( onkyo_url, data = myObject )

# turn onky on
# set volume 11
# set on source: net
# set channel on first favorite ( this is the new favorite )

#sometimes the call to recevier times-out, so try every call  max 3 times....
#

receiver = eiscp.eISCP( onkyo_ip )
i = 1
while i < 3:
  try:
    print( i )
    print( receiver.command('power on' ) )
    break;
  except:
    i+=1

  
i = 1
while i < 3:
  try:
    print( receiver.command('volume 11' ) )
    break;
  except:
    i+=1
    
i = 1
while i < 3:
  try:
    print( i )
    print( receiver.command('input-selector net' ) )
    break;
  except:
    i+=1
    
i = 1
while i < 3:
  try:
    print( i )
    print( receiver.command('dock.internet-radio-preset=1') )
    break;
  except:
    i+=1
 
receiver.disconnect()

print( 'restore original favorites' )
myObject[ 'name00' ] = lsName
myObject[ 'url00' ] = lrURL
print('and send the original list to onkyo' )
x = requests.post( onkyo_url, data = myObject )

Is this still working? I get an error installing Onkyo-eiscp during netiface portion of the pip3 install?

i think you also need to install python3-dev

1 Like

Hi,
how you update the “Stream” ? I use the same , but only with fix favorites.
You have any automation to update your favorite “1”?

thank you for sharing all this, it help me a lot.
I also share my solution :

for the internet radio :

I set a generic onkyo command into the shell_command (replace the IP)

onkyo_command: onkyo -v -t <IP> {{ cmd }}

then I created a input_select list (format ’ - ') :

            {
                "name": "Internet radio",
                "options": [
                    "01 - nrj",
                    "02 - nostalgie",
                    "03 - RTL",
                    "04 - Rire et chansons",
                    "05 - Chérie FM",
                    "06 - RTL 2",
                    "07 - Fun Radio",
                    "08 - Europe 1",
                    "09 - Virgin Radio",
                    "10 - Radio Gazelle",
                    "11 - RMC",
                    "12 - BFM Business",
                    "13 - France Info",
                    "14 - France Inter",
                    "15 - France Culture",
                    "16 - Mouv'",
                    "17 - Oui FM",
                    "18 - RFM"
                ],
                "icon": "mdi:radio-tower",
                "initial": "02 - nostalgie",
                "id": "iradio_station"
            }

finally, in the automation I parse the selected entry to extract the preset number :

alias: Onkyo_Internet_Radio
description: ''
trigger:
  - platform: state
    entity_id: input_select.internet_radio
condition: []
action:
  - service: media_player.select_source
    data:
      source: INTERNET
    entity_id: media_player.onkyo
  - service_template: shell_command.onkyo_command
    data:
      cmd: listening-mode=all-ch-stereo
  - service_template: shell_command.onkyo_command
    data:
      cmd: >-
        dock.internet-radio-preset={{
        states.input_select.internet_radio.state.split("-")[0] | int }}
mode: single

for the FM, this is almost the same :

don’t know why I the generic command above do not work, must be because there is more than one argument. anyway I have created an other command to get it work (replace the IP):

onkyo_command_freq: onkyo -v -t <IP> main.tuning=direct {%- for item in states.input_select.fm_radio_freq.state.split("-")[1] | replace ('.', '') | trim | list() %} main.tuning={{ item }}-in-direct-mode{% endfor %}

I set the frequency into the input_select (format ’ - '), don’t forget the ‘0’ at the end :

            {
                "name": "FM radio freq",
                "options": [
                    "NOSTALGIE - 98.30",
                    "MARITIMA - 93.80",
                    "RIRE ET CHANSONS - 95.50",
                    "BEUR FM - 92.60",
                    "CHERIE FM - 100.10",
                    "FRANCE INFO - 105.30",
                    "FUN RADIO - 99.70",
                    "LE MOUV' - 96.40",
                    "NRJ - 106.40",
                    "RADIO FG - 93.4",
                    "RADIO GAZELLE - 98.00",
                    "RADIO STAR - 92.30",
                    "RMC - 104.30",
                    "RTL - 101.40",
                    "SKYROCK - 90.00",
                    "SUD RADIO - 95.10",
                    "VIRGIN RADIO - 102.30",
                    "VITAMINE - 107.20"
                ],
                "icon": "mdi:radio",
                "initial": "NOSTALGIE - 98.30",
                "id": "radio_station_freq"
            },

finally, in the automation nothing special, the shell command is doing everything :

alias: Onkyo_fm_Radio_freq
description: ''
trigger:
  - platform: state
    entity_id: input_select.fm_radio_freq
condition: []
action:
  - service: media_player.select_source
    data:
      source: FM
    entity_id: media_player.onkyo
  - service_template: shell_command.onkyo_command_freq
mode: single

this allow me to manage the changes directly by the input_select

hope it help.

Do I have to have Onkyo script from Miracle2k installed to get shell commands working in newest HA with Onkyo platform?