Newbie - Denon "off to bed" script help please

I have no doubt whatsoever this could be streamlined, and that will be the very next question after getting the source to switch over to HEOS Music. Seems to fail due to the space in the command, tried single & double quotes in various places. Any hints for this?

Thanks for reading.

Here’s the source list:

source_list:
  - AUX
  - Alexa
  - Blu-ray
  - Bluetooth
  - DVD
  - Game
  - HEOS Music
  - Media Player
  - TV Audio
  - Tuner

And here’s my script I’ve attached to a button my HA dashboard.

sequence:
  - if:
      - condition: state
        entity_id: media_player.master_bedroom_2
        state: "off"
    then:
      - action: denonavr.get_command
        metadata: {}
        data:
          command: /goform/formiPhoneAppDirect.xml?ZMON
        target:
          entity_id: media_player.master_bedroom_2
  - delay:
      hours: 0
      minutes: 0
      seconds: 3
      milliseconds: 0
  - action: denonavr.get_command
    metadata: {}
    data:
      command: /goform/formiPhoneAppDirect.xml?SIDVD
    target:
      entity_id: media_player.master_bedroom_2
  - action: denonavr.get_command
    metadata: {}
    data:
      command: /goform/formiPhoneAppDirect.xml?SLP090
    target:
      entity_id: media_player.master_bedroom_2
  - action: denonavr.get_command
    metadata: {}
    data:
      command: /goform/formiPhoneAppDirect.xml?MV20
    target:
      entity_id: media_player.master_bedroom_2
alias: Master Bedroom sleep timer
description: ""

What is the error you are getting? Your commands look similar to mine, except I don’t have the metadata line when using get_command.

alias: AVR 95.1 FM
sequence:
  - service: denonavr.get_command
    target:
      entity_id: media_player.denon_avr_x1800h
    data:
      command: /goform/formiPhoneAppDirect.xml?TFAN009510
mode: single
icon: mdi:radio-fm

I normally use media_player commands for controlling the AVR.
For example, to run Heos I use:

alias: Recv heos music
sequence:
  - service: media_player.select_source
    metadata: {}
    data:
      source: HEOS Music
    target:
      entity_id: media_player.denon_avr_x1800h
mode: single
icon: mdi:cast-audio

Hi. No error, just doesn’t do it.

If I use SIDVD for example, it switches the channel.

I lifted these commands from here and have only the vaguest use what I’m doing tbh, however I’ve seen the version of commands you’re using littered about the place here, just didn’t know how to input them.

On the scripts tab. Look at the traces for your script to see what it’s doing.

Also, in your script if the avr is off you are using get_command to turn on the main zone. Use the media_player service to turn on the avr instead.


  - service: media_player.turn_on
    metadata: {}
    data: {}
    target:
      entity_id: media_player.denon_avr_x1800h

Yeah, sorry, probably wasn’t clear.

It all works perfectly.

If the amp is off, it turns it on, waits, changes the channel, sets the timer. If the amp is already on, it changes the channel and sets the timer.

This is by design.

It just doesn’t work (or give any error) when there’s a space in the source. Nothing abnormal was showing in trace.

Back at a computer now. Will see if I can figure out how to add this method of changing the channel instead of the get command.

Yes, I am fairly sure this works in my quick test then. Cheers for that. Now I can also make sure the correct “HEOS radio station” is playing using that too I suppose.

sequence:
  - if:
      - condition: state
        entity_id: media_player.master_bedroom_2
        state: "off"
    then:
      - action: denonavr.get_command
        metadata: {}
        data:
          command: /goform/formiPhoneAppDirect.xml?ZMON
        target:
          entity_id: media_player.master_bedroom_2
  - delay:
      hours: 0
      minutes: 0
      seconds: 3
      milliseconds: 0
  - action: media_player.select_source
    metadata: {}
    data:
      source: HEOS Music
    target:
      entity_id: media_player.master_bedroom_2
  - action: denonavr.get_command
    metadata: {}
    data:
      command: /goform/formiPhoneAppDirect.xml?SLP090
    target:
      entity_id: media_player.master_bedroom_2
  - action: denonavr.get_command
    metadata: {}
    data:
      command: /goform/formiPhoneAppDirect.xml?MV20
    target:
      entity_id: media_player.master_bedroom_2
alias: Master Bedroom sleep timer
description: ""

The other zone is in the bathroom, so I’m specifying the zone2 amp control for a reason, but do tell me if that’s incorrect. Seems to work.

I don’t use zones so can’t help with that, but sounds like it’s working.

The only way I have found to select a HEOS radio station is to create a favorite for it with the HEOS app. Then I use
media_player to play the favorite.


  - service: media_player.play_media
    data:
      media_content_type: favorite
      announce: true
      media_content_id: "2"
    target:
      entity_id: media_player.denon_avr_x1800h_2

Edit: Since favorites are added to the source list, you could also use media_player.select_source to play the station

Yessiree, I’m on it that way, thank you.

It’s literally a spare Denon amp used in a master suite, so it’s zone 1 bedroom, zone 2 bathroom and a physical DPDT switch for a roof terrace from zone 1, which is all extremely confusing in Denon’s HA entities because the names are confusing.

Me again. Sorry.

Is there a way to query the favourites list do you know? They don’t show up in the source list I posted in my first post.

Cheers.

I don’t know of a way to query the favorites. However, they will only show up in the source list of the media_player that is associated with the HEOS integration. They are not in the source list of the media_player of the Denon AVR integration.

If you go to the developer tools states tab you should see both media players and the HEOS one should have the favorites in the source list.

Lol yeah, I’m an idiot. Sorry. And thanks :smiling_face::grinning:

No problem. It’s definitely confusing having two media players associated withe the receiver. I actually have three media players associated with mine. :flushed:

I added a universal media player for my Denon which combines the other two.

I added the following to my configuration.yaml to create the media player.


media_player:
  - platform: universal
    name: denon_avr
    unique_id: denon_avr
    device_class: receiver
    children:
      - media_player.denon_avr_x1800h
      - media_player.denon_avr_x1800h_2
    browse_media_entity: media_player.denon_avr_x1800h_2
# state_template required because otherwise when you leave it on HEOS it shows wrong status
    state_template: >
      {% if is_state_attr('media_player.denon_avr_x1800h', 'source', 'HEOS Music') %}
        {{states('media_player.denon_avr_x1800h_2')}}
      {% else %}
        {{states('media_player.denon_avr_x1800h')}}
      {% endif %}  
# active_child_template required because otherwise you can't start/stop properly with HEOS
    active_child_template: > 
      {% if is_state_attr('media_player.denon_avr_x1800h', 'source', 'HEOS Music') %}
          media_player.denon_avr_x1800h_2
      {% else %}
          media_player.denon_avr_x1800h
      {% endif %}
    commands:
      turn_off:
        service: media_player.turn_off
        data:
          entity_id: media_player.denon_avr_x1800h
      turn_on:
        service: media_player.turn_on
        data:
          entity_id: media_player.denon_avr_x1800h
      volume_up:
        service: media_player.volume_up
        data:
          entity_id: media_player.denon_avr_x1800h
      volume_down:
        service: media_player.volume_down
        data:
          entity_id: media_player.denon_avr_x1800h
      select_sound_mode:
        service: media_player.select_sound_mode
        target:
          entity_id: media_player.denon_avr_x1800h
        data:
          sound_mode: "{{ sound_mode }}"
    attributes:
      sound_mode: media_player.denon_avr_x1800h|sound_mode
      sound_mode_raw: media_player.denon_avr_x1800h|sound_mode_raw
      sound_mode_list: media_player.denon_avr_x1800h|sound_mode_list
# source_list required because otherwise HEOS Music source does not show up when AVR is active child
      source_list: media_player.denon_avr_x1800h_2|source_list

Add some zones in too, just to really mess things up.

I don’t think I have my sources listed as favourites, so unless I do that, I’ll have to figure out the syntax for calling one of these.

source_list:
  - BBC Radio 6 Music (Indie Music)
  - Radio X UK (Indie Rock)
  - Smooth Chill (Chill)
  - BBC Radio 2
  - BBC Radio 1

Looks like there are 5 favorites. Favorite 1 should be BBC Radio 6 Music (Indie Music)

Or you can select the source

  - service: media_player.select_source
    metadata: {}
    data:
      source: BBC Radio 6 Music (Indie Music)
    target:
      entity_id: media_player.denon_avr

Oh ok, sorry, yours was calling it by favourite number so figured I had to assign numbers to them first.

I shall try that.

Ideal world I guess a prompt asking which one you’d like from a compiled list of favourites, but that’s for another time when I understand things more.

Selecting the favourite by source doesn’t actually seem to work unfortunately.

I may try it via the number method and see - hardest part of this is running up the stairs to see if it works IRL.

You probably need to first change the source to Heos Music and then select the radio source.

You can test the service calls from the developer tools services tab.

Add the Denon media players to a dashboard page and you will be able to see if it changed stations. You should also be able to select different sources using the dashboard.

I figured it out - I’ve done two buttons for two scripts giving different stations.

sequence:
  - if:
      - condition: state
        entity_id: media_player.master_bedroom_2
        state: "off"
    then:
      - action: denonavr.get_command
        metadata: {}
        data:
          command: /goform/formiPhoneAppDirect.xml?ZMON
        target:
          entity_id: media_player.master_bedroom_2
  - delay:
      hours: 0
      minutes: 0
      seconds: 1
      milliseconds: 0
  - action: media_player.select_source
    metadata: {}
    data:
      source: HEOS Music
    target:
      entity_id: media_player.master_bedroom_2
  - action: denonavr.get_command
    metadata: {}
    data:
      command: /goform/formiPhoneAppDirect.xml?SLP090
    target:
      entity_id: media_player.master_bedroom_2
  - action: denonavr.get_command
    metadata: {}
    data:
      command: /goform/formiPhoneAppDirect.xml?MV20
    target:
      entity_id: media_player.master_bedroom_2
  - action: media_player.play_media
    metadata: {}
    data:
      media_content_type: favorite
      media_content_id: Smooth Chill (Chill)
    target:
      entity_id: media_player.master_bedroom
alias: Master Bedroom sleep timer Chill
description: ""