Harmony send_command

Hi

What is the right syntax to send a command to a device?
I can only se examples to send an activity not a command.

I think this would be useful in the documentation.

Should i use a script or is it possible to send directly from the automation?
Is someone having a working example to share?

Grabbed from another thread:

  service: remote.send_command
    data_template:
      command: Mute
      device: 29753204
      entity_id: remote.living_room

Is this a script or automation?

So you tried and got an error?

Both.

- alias: 'Turn on LED Candles'
  trigger:
    - platform: state
      entity_id: light.candles
      to: 'on'
  action:
    service: remote.send_command
    data_template:
      command: PowerOn
      device: 39544037
      entity_id: remote.livingroom

This dont work. Gives no errors.

1 Like

Have you ruled out an issue with the trigger? What happens when you trigger it manually?

According to the logbook the automation is triggerd so there must be something with the action.

There are a lot of things to debug here.

  • Do you have the right entity_id and device #?
  • Are other remote.turn_on activities working correctly?
  • Do you see the light blink on your hub?

also, have you taken a look at the harmonyhub thread? Lots of examples there.

I have confirmed that the entity_id and device is right.
The remote.turn_on is working fine with my activities.
The led on the hub is not blinking when i trigger the action.

I think the config examples in this forum is very confusing. Some are using quotes around the device and command values and some use data: instead of data_template:. I have also seen examples where the entity_id is directly under the service line and not under data:

So an working example in the documentation would be helpful for all of us using the remote.

The variations you mention are all valid syntax. There are many ways to do the same thing and HA is flexible in places. “data_template” would be required if you were passing any templated data, which you’re not, but it’ll still work.

I’d experiment with the services dev tab to see if you can get things working. The service will want JSON, so you’ll send it something like:

{“entity_id”:“remote.livingroom”,“device”:“39544037”,“command”:“PowerOn”}

Yes, this is doing the same thing as your action, but it’ll let you test settings combinations. If it’s not working in the dev tool, it definitely won’t work in an action.

I found the source to my problems.
When i added the device in myHarmony i manualy teached the remote the on and off command.
I named the commands “Power On” and “Power Off”. That worked when i used the remote, but not from the API.
I removed the device and added it again but now i named the comands “PowerOn” and “PowerOff”. Now everything work fine.
So naming the commands without spacing is required.

1 Like

Weird. I don’t have any, but I’ve seen examples where someone has spaces in their command names.

That is activities and that is working fine with spaces even for me.
When i had spaces in my commands they show upp without spaces in the .conf file.
I guess that messed up everything.

I am having an issue where my pioneer receiver will not respond to PowerOn and both PowerOff and PowerToggle only turn the device off.

Anyone run into this before?

Edit: turns out that things get out of sync, I have to have the scripts send the power command twice to have it jive with harmony. Testing now…

Hi,
Just in case anyone else has similar struggles with send_command.
I’ve just spent hours trying to find out why I could not get this to work, and
turns out my problem was also with how I named the command when I taught it to Harmony.
I called the harmony command ON and also tried On.
This command would work through the dev interface
{“entity_id”:“remote.living_room”,“device”:“42178528”,“command”:“On”}
But I could never get it to work as an action no matter what I tried
Changed it to PowerOn vola it works.

1 Like

You have to fetch the command names and the device ids from harmony_[name].conf file created by HASS. Also don’t put the command name in additional quotes.

wrong: ‘PowerOn’
right: PowerOn

I am only here to post a working example for an automation (configured via GUI), even if it is an old thread. ^^
Was locking for an example and found this thread.

1st you have to open the harmony conf file in the File editor like

/homeassistant/harmony_12345678.conf
to get all the information for your device.

It will look like this (snipped)

...
    "Devices": {
        "LG-Monitor": {
            "commands": [
                "PowerToggle",
                "Mute",
                "VolumeDown",
                "VolumeUp",
                "DirectionDown",
                "DirectionLeft",
                "DirectionRight",
                "DirectionUp",
                "OK",
                "Menu",
                "Audio",
                "PIP",
                "PictureMode",
                "Exit",
                "PictureMode",
                "AudioSelect",
                "FullScreen",
                "GameMode",
                "Input",
                "InputHdmi1",
                "InputHdmi2",
                "InputHdmi3",
                "InputHdmi4",
                "InputUsb",
                "PBP"
            ],
            "id": "87654321"
        },
...

here you can find the name of the device, in my case LG-Monitor and the available commands. As I created the automation, I put the name of the device in quotes, but HA removes the quotes after I saved the automation.

After this you have to find the ID of your Harmony Hub. This value will be needed for the entity_id

Go to Settings → Devices → search for Harmony → click on “X Devices” → click on your device (your Harmony Hub name)

click here
grafik

click here

click here
grafik
to copy the ID

alias: Harmony - PIP EIN
description: ""
triggers:
  - trigger: state
    entity_id:
      - input_button.pip_ein
actions:
  - data_template:
      command:
        - PIP
        - OK
      device: LG-Monitor
      entity_id: remote.sz_harmony_hub
      delay_secs: 1.6
    action: remote.send_command

2nd example

alias: Harmony - PIP AUS
description: ""
triggers:
  - trigger: state
    entity_id:
      - input_button.pip_aus
conditions: []
actions:
  - data_template:
      command:
        - FullScreen
        - OK
      device: LG-Monitor
      entity_id: remote.sz_harmony_hub
      delay_secs: 1.6
    action: remote.send_command
mode: single

delay_secs is for the delay in seconds between the commands.

Finally the link to the documentation: