[Harmony Hub] Please help, I'm stuck trying to get input select to work

Hello, I’ve tried a couple of different examples on setting how to select a Harmony Activity from an input select. I feel like I copied everything and changed it correctly but it’s not working. I’m not getting any errors in the log but it’s never successfully switched to the input after I select it from the drop down. If you have any ideas I would greatly appreciate it!

configuration.yaml:

script:
  input_select_harmony:
    alias: 'Start activity from input select'
    sequence:
      - service: remote.turn_on
        data_template:
          entity_id: remote.harmony_hub
          activity: >
              {% if is_state("input_select.harmony_hub", "Chromecast (Living Room)") %}
                27373448
              {% elif is_state("input_select.harmony_hub", "LGTV") %}
                26485360
              {% elif is_state("input_select.harmony_hub", "Pandora (Both Rooms)") %}
                24749177
              {% elif is_state("input_select.harmony_hub", "Chromecast (Bedroom)") %}
                27019625
              {% elif is_state("input_select.harmony_hub", "Radio") %}
                22156022
              {% elif is_state("input_select.harmony_hub", "TV (Living Room)") %}
                22122950
              {% elif is_state("input_select.harmony_hub", "Pandora (Living Room)") %}
                22122546
              {% elif is_state("input_select.harmony_hub", "Xbox 360 (Bedroom)") %}
                27019330
              {% elif is_state("input_select.harmony_hub", "Sleep") %}
                24432945
              {  % elif is_state("input_select.harmony_hub", "Netflix") %}
                22726467
              {% elif is_state("input_select.harmony_hub", "Xbox One (Living Room)") %}
                22152858
              {% elif is_state("input_select.harmony_hub", "TV (Bedroom)") %}
                23209137
              {% elif is_state("input_select.harmony_hub", "Spotify (Living Room)") %}
                27373516
              {% elif is_state("input_select.harmony_hub", "TV (Living Room)") %}
                22122950
              {% elif is_state("input_select.harmony_hub", "HTPC") %}
                27663465
              {% elif is_state("input_select.harmony_hub", "Receiver / USB") %}
                24433259
              {% elif is_state("input_select.harmony_hub", "Spotify (Bedroom)") %}
                27373548
              {% elif is_state("input_select.harmony_hub", "Amazon FireTV") %}
                22122797
              {% elif is_state("input_select.harmony_hub", "PowerOff") %}
                -1
              {% else %}
              {% endif %}
# Input Select
input_select:
  harmony_hub:
    name: Harmony Activity
    options:
      - Select input
      - LGTV
      - HTPC
      - TV (Living Room)
      - TV (Bedroom)
      - Netflix
      - Radio
      - Spotify (Living Room)
      - Spotify (Bedroom)
      - Chromecast (Living Room)
      - Chromecast (Bedroom)
      - Pandora (Both Rooms)
      - Pandora (Living Room)
      - Xbox One (Living Room)
      - Xbox 360 (Bedroom)
      - Receiver / USB
      - Amazon FireTV
      - Sleep
      - PowerOff
    initial: Select input

and I’ve tried it with both auto discovery on and off in config:

# Harmony Hub
remote:
  - platform: harmony
    name: Harmony Hub
    host: 192.168.1.123
    port: 5222

automation.yaml:

- id: Remote Update Harmony Hub
  alias: 'Remote update Harmony Hub'
  trigger:
    platform: state
    entity_id: remote.harmony_hub
  action:
    service: input_select.select_option
    data_template:
      entity_id: input_select.harmony_hub
      option: >
        {{ states.remote.harmony_hub.attributes.current_activity }}

and:

- id: Start Selected Activity
  alias: 'Remote start activity from input select living room tv'
  trigger:
    platform: state
    entity_id: input_select.harmony_hub
  action:
    service: script.turn_on
    entity_id: script.input_select_harmony

Thank you to anyone who has any ideas!

I think the documentation is wrong, I found that rather than…

          {% if is_state("input_select.harmony_hub", "Chromecast (Living Room)") %}
            27373448

…I needed to remove the spaces before the activity code to get it to work, like this…

          {% if is_state("input_select.harmony_hub", "Chromecast (Living Room)") %}
          27373448

but generally you seem to have added loads of unnecessary spaces in many places too, you should only have two spaces to step in a level, check the documentation and compare to what you’ve done as this is a fundamental to yaml as a whole.

Some troubleshooting questions:

First lets test to see if your Harmony hub is connected

  • Go to the Services Developer tool. Select “Remote” for the domain, “Turn_on” for the service, and service data is {“entity_id”:“remote.harmony_hub”,“activity”:22122950} This should turn on your living room TV.

Next See if the automation works

  • Does the input_select update to the correct activity when you manually change it with the actual remote?
  • What do your HA logs show when you change the input_select? Does it try to run the automation?

Let me know the outcome of the above tests and we can go from there.

Hello and thank you for your ideas.

It’s amazing how many things fix themselves overnight lately. I did not change any of my code and this morning it is working. Which makes me think it’s taking HA a long time to implement changes.

I am very curious to learn how to use the Services Developer tool like you mentioned though. I tried setting domain to remote, service to turn_on and {“entity_id”:“remote.harmony_hub”,“activity”:22122950} for the service data but it says:

Error parsing JSON: SyntaxError: Unexpected token “ in JSON at position 1

Any idea what I’ve done wrong with the tool?

Forgot to put my code in a code block. It must have chaged the double quote to a different character. Do your same steps as before, but use this instead:

{"entity_id": "remote.harmony_hub","activity": 22122950}

Thank you that worked. To test my understanding (since I don’t know JSON), am I able to figure out what it wants in the service data field?

For example, if I did this:

Domain > Remote:
and then Command

it gives me:
Valid Parameters

Parameter Description Example
entity_id
Name(s) of entities to send command from remote.family_room
device
Device ID to send command to 32756745
command
A single command or a list of commands to send. Play
num_repeats
An optional value that specifies the number of times you want to repeat the command(s). If not specified, the command(s) will not be repeated 5
delay_secs
An optional value that specifies that number of seconds you want to wait in between repeated commands. If not specified, the default of 0.4 seconds will be used 0.75

I’m wondering what to put in Service Data? Is it always this?

{<Parameter> : <value>} Do I have to do all parameters? or can I pick and choose? I noticed the 1 above had 2

So in my example:

 {"entity_id": "remote.harmony_hub","device": 39925136,"command": "PowerOff"} 

That one just worked for me but wondering about all others.

Why is the number for device number not in quotes and the others are? Is it only numbers that aren’t in quotes? Anything else I need to know to test pretty much every command?

Last question:
How would I go about turning those test commands into actual automation? Is there an easy way?

Thanks for your time

I’m no professional, but I can try to answer your questions with my limited experience.

You always want to enter it in the format {“parameter”:“value”,“parameter2”:“value2”} and you are correct that numbers do not need to be in quotes. You can use the site https://jsonlint.com to test your code to make sure it is in a valid format. It will provide hints at where there are errors in your code if there are any.

The valid parameters section is a good place to start to see all the valid options to use. You can also go to the component’s page (example https://home-assistant.io/components/light ) to get a more detailed description of each parameter.

You can enter as much or as little as you want in the service data. Typically you want to include a specific entity_id or it will apply the command to all entities of that type. I will use lights as an example as many people have them and there are many different commands. If you select light.turn_on and put nothing in the service data, all of your lights will turn on. You can specify a certain entity_id to only apply it to that light and also set the brightness, temperature, fade, etc.

JSON and YAML are different languages so there is some differences between how they need to be written. There is no easy way to convert that I am aware of. Maybe someone else can point you in the right direction. Below is an example in both JSON and YAML (the “action” part of one of my automations) to do the same thing to serve as a starting point for you. It turns on my living room light to 50% brightness over the course of 5 seconds and sets the color temperature to 200 (bright white). Note that not all bulbs support all these settings.

JSON:

{"entity_id":"light.living_room", "brightness": 125, "transition": 5, "color_temp": 200}

YAML:

action:
  service: light.turn_on
  data:
    entity_id: light.living_room
    brightness: 125
    transition: 5
    color_temp: 200

That is very helpful, thank you. Probably dumb question but can the JSON code be pasted into a .yaml file and work? Or is it just for testing? Because in a lot of ways I see that being easier than yaml what with the formatting and all.

It cannot be straight pasted in. It needs to be converted. A quick Google gave me this, but never tested it myself.

https://www.json2yaml.com/

Woo hoo will give this all a try thanks a lot

I have a working input select and also have switches for Homekit.
Everything is update correctly but not the input_select.
When i start the activity “Radio” with Homekit or a switch in HA the input select is not changing.

My remote entity is remote.harmony.

Here is my automation:

- alias: Set Harmony activity using input_select
  hide_entity: True
  trigger:
    platform: state
    entity_id: input_select.harmony
  action:
    service: remote.turn_on
    entity_id: remote.harmony
    data_template:
      activity: >
        {% if is_state("input_select.harmony", "Televisie") %}
          12570272
        {% elif is_state("input_select.harmony", "Apple TV") %}
          15279888
        {% elif is_state("input_select.harmony", "Playstation") %}
          12570336
        {% elif is_state("input_select.harmony", "Nintendo") %}
          35752558
        {% elif is_state("input_select.harmony", "Radio") %}
          12570387
        {% elif is_state("input_select.harmony", "Apple TV Muziek") %}
          19166797
        {% elif is_state("input_select.harmony", "Internet Radio") %}
          23487453
        {% else %}
            -1
        {% endif %}

- alias: Update Harmony input_select
  hide_entity: True
  trigger:
    platform: state
    entity_id: remote.harmony
  action:
    service: input_select.select_option
    data_template:
      entity_id: input_select.harmony
      option: "{{ states.remote.harmony.attributes.current_activity }}" 

There must be something wrong with the automation “Update Harmony input_select” but i can’t find it.

Thanks for the help!

1 Like

You may need to map the option the opposite way. Also, there usually is a 1 to 10 second feedback delay with harmony.

I have this now:

  action:
    service: input_select.select_option
    data_template:
      entity_id: input_select.harmony
      option: >
        {{ states.remote.harmony.attributes.current_activity }}

It is changing when i change activities but nog when i turn it off. Then it is showing the last activity…

What do you mean with change it the opposite way?
Can i fix it with another automation to change the input select to off?

Does your input_select contain the “PowerOff” option? If not, that’s your problem.

### Harmony input ###

input_select:
  harmony:
    name: Harmony
    options:
      - Uit
      - Televisie
      - Apple TV
      - Playstation
      - Nintendo
      - Radio
      - Apple TV Muziek
      - Internet Radio
    icon: mdi:monitor

Yes “Uit” is PowerOff

But harmony does not report Uit when it’s powered off. It reports PowerOff. So you need to capture that.

  action:
    service: input_select.select_option
    data_template:
      entity_id: input_select.harmony
      option: >
        {%- set activity = state_attr('remote.harmony','current_activity') %}
        {%- if activity in state_attr('input_select.harmony','options') %}
          {{ activity }}
        {%- else %}
          Uit
        {%- endif %}
1 Like

You are the best. Thanks is working!

1 Like

Figured I’d reply here since it’s related…

I’m using (for now) the Custom Roku Remote card for Lovelace for my house audio system which I control via my Harmony Hub. I’ve got all but one of the buttons to work - the power button. All other buttons work great via remote.send_command, choose the device, and choose the command to send, but I need the power button to start an activity and cannot figure out the syntax.

Here’s my Lovelace code:

type: 'custom:roku-card'
entity: remote.harmony_hub
tv: true
apps:
  - image: /local/Spotify_icon.png
    app: Spotify
  - image: /local/YouTube_icon.png
    app: YouTube
    hold_action:
      action: call-service
      service: remote.send_command
      service_data:
        source: ESPN
        entity_id: remote.harmony_hub
power:
  tap_action:
    action: call-service
    service: remote.turn_on
    service_data:
      activity: 47459974
      entity_id: remote.harmony_hub
back:
  tap_action:
    action: call-service
    service: remote.send_command
    service_data:
      entity_id: remote.harmony_hub
      device: PS4
      command: Back
info:
  tap_action:
    action: call-service
    service: remote.send_command
    service_data:
      entity_id: remote.harmony_hub
      device: PS4
      command: Options

And my available activities in the Harmony folder:

{
    "Activities": {
        "-1": "PowerOff",
        "47459974": "Watch TV"
    },
    "Devices": {
        "Harman Kardon AV Receiver": {
            "commands": [
                "PowerOff",
                "PowerOn",
                "0",
                "1",
                "2",
                "3",

Thoughts?

Not sure if i can help. i do not use that card. But this is how i turn on an activity

- platform: template
  switches:
    # TV Activitet
    watch_tv:
      value_template: "{{ is_state_attr('remote.stua', 'current_activity', 'Watch TV') }}"
      turn_on:
        service: remote.turn_on
        data:
          entity_id: remote.stua
          activity: "Watch TV"
      turn_off:
        service: remote.turn_on
        data:
          entity_id: remote.stua
          activity: "PowerOff"

And in Lovelace

  - entity: switch.watch_tv
    icon: 'mdi:television'
    tap_action:
      action: toggle
  - entity: remote.stua

can someone please help me undserstand what to do.

Ive installed harmony through hacs, and i can turn my two activities on and off, change channel, and sound. But nothing more, like changing inputs.
And i dont understand why.

Ive only installed it, done nothing else.

someone who can use there time to help a a little?