Making a Switch template with Harmony hub

Hi Guys

I need some help using switch templates
my hub was detected and all the commands are listed in the conf file.
As a test,

Using the Developer Tools-> Services on Hass.io

I successfully managed to turn on and off my TV successfully

service:
remote.send_command
Entity:
remote.bed_room_hub

Service Data:
{
“entity_id”: “remote.bed_room_hub”,
“device”: “37167279”,
“command”: “PowerOn”
}

Service Data:
{
“entity_id”: “remote.bed_room_hub”,
“device”: “37167279”,
“command”: “PowerOff”
}

The above works, but how do I get it to be in a switch?

All the switch template examples I find online incorporates Harmony’s activities into a switch.
I’m looking to just call the device & command without using harmony’s activity with a switch template.

Anyone can help with what I should include in the configuration.yaml file?

Thank you

Oliver

1 Like

You use a switch template.

Because that is a good way to do it.

So you are now saying you don’t want a switch?

Do you want a switch or not?

I’m confused.

If you want a switch, use a switch template.

If you don’t want a switch you can use an input select, like this:

I do want a switch. just not to control my hub with a harmony activities. I want to control using a switch at the harmony device level. Harmony activities are restrictive as I can only use one activity at a time. All the switch template examples I can find, uses the harmony hub activities. The sample syntax is not applicable for what I want my switch to do.

Ah ok.

You can use this service: https://www.home-assistant.io/components/remote.harmony/#service-remotesend_command

You will have to set up input_booleans (to look like switches in the front end), and automations to call the services when the input_booleans are changed.

OK .I just read the document on input boolean but it mentions automation?

I want to manually turn on and off.

I did read up on the service call remote.send before opening a new thread. In my first post, I also tested it and it does work.
I guess I need to get that into a boolean switch? But the docs example is for automation. How do I do it manually?

You have to write an automation to trigger when the input_boolean is changed manually in the front end. The automation’s action is to call the remote.send service.

input_boolean:      ###    This is your switch in the front end
  name: TV Power
  icon: mdi:power

automation:
  id: tv_power
  alias: 'TV Power'
  trigger: 
    platform: state
    entity_id: input_boolean.tv_power   #### Triggered by either turning on or off the input_boolen
  action:
    service: remote.send_command
      data_template:
      entity_id: remote.tv_room
      device: 37167279
      command:
        {% if is_state(trigger.entity_id, 'on') %}
          PowerOn
        {% else %}
          PowerOff
        {% endif %}

As you can see this can get quite lengthy if you have a lot of functions. One input boolean (or input select if there are more than two states for the device) and an automation.

Hence the use of template switches.

Thank you for the code! however I seem to run into an error when Hass.io checked my configuration.yaml file

Error loading /config/configuration.yaml: mapping values are not allowed here
in "/config/configuration.yaml

I’ll try to troubleshoot it from my end…

My indentation is off in the data template. Try this:

  action:
    service: remote.send_command
    data_template:
      entity_id: remote.tv_room
      device: 37167279
      command:
        {% if is_state(trigger.entity_id, 'on') %}
          PowerOn
        {% else %}
          PowerOff
        {% endif %}

Edit: the input boolean is missing a bit too:

input_boolean:      ###    This is your switch in the front end
  tv_power:
    name: TV Power
    icon: mdi:power

Yes, I did pick that up too. :slight_smile:

There was an additional space after command:
Fixed it, but the error is still there…

the complete error is

Configuration invalid

CHECK CONFIG

Error loading /config/configuration.yaml: mapping values are not allowed here in “/config/configuration.yaml”, line 90, column 20

in my vi editor

I see line 90 is this line

action:
service: remote.send_command
data_template: <—This is line 90
entity_id: remote.tv_room
device: 37167279

Thanks Tom for helping me out

I did a sneaky edit, is this what you have?

  action:
    service: remote.send_command
    data_template:                            ######## <------ check this indentation
      entity_id: remote.tv_room
      device: 37167279
      command:
        {% if is_state(trigger.entity_id, 'on') %}
          PowerOn
        {% else %}
          PowerOff
        {% endif %}

When posting code snippets please use the </> button as shown in the blue banner at the top of the page.

Ok. Thanks. So that’s how you paste codes :slight_smile:

My code below

input_boolean:      ###    This is your switch in the front end
  tv_power:
    name: TV Power
    icon: mdi:power

automation:
  id: tv_power
  alias: 'TV Power'
  trigger:
    platform: state
    entity_id: input_boolean.tv_power   #### Triggered by either turning on or off the input_boolen
  action:
    service: remote.send_command
    data_template:
      entity_id: remote.tv_room
      device: 37167279
      command:
        {% if is_state(trigger.entity_id, 'on') %}
          PowerOn
        {% else %}
          PowerOff
        {% endif %}

New error.

Error loading /config/configuration.yaml: while scanning for the next token
found character ‘%’ that cannot start any token
in “/config/configuration.yaml”, line 95, column 10

Line 95 is this

  command:
    {% if is_state(trigger.entity_id, 'on') %}                        ### Line 95
      PowerOn
    {% else %}
      PowerOff
    {% endif %}

I forgot the multi line template symbol “>”, like this:

  action:
    service: remote.send_command
      data_template:
      entity_id: remote.tv_room
      device: 37167279
      command: >
        {% if is_state(trigger.entity_id, 'on') %}
          PowerOn
        {% else %}
          PowerOff
        {% endif %}

Also check the entity id of your remote. I think it should be this (from your first post). Not sure where I got TV from.

  action:
    service: remote.send_command
    data_template:
      entity_id: remote.bed_room_hub   #### <- here
      device: 37167279
      command: >
        {% if is_state(trigger.entity_id, 'on') %}
          PowerOn
        {% else %}
          PowerOff
        {% endif %}

We managed to get the automation button to appear, but it doesn’t turn on/off my tv. My full code below

input_boolean:      ###    This is your switch in the front end
  tv_power:
    name: TV Power
    icon: mdi:power

automation:
  id: tv_power
  alias: 'TV Power'
  trigger:
    platform: state
    entity_id: input_boolean.tv_power   #### Triggered by either turning on or off the input_boolen
  action:
    service: remote.send_command
    data_template:
      entity_id: remote.bed_room_hub
      device: 37167279
      command: >
        {% if is_state(trigger.entity_id, 'on') %}
          PowerOn
        {% else %}
          PowerOff
        {% endif %}

Are you turning the automation on and off (disabling / enabling the automation) instead of switching the input boolean on and off (triggering the automation).

Oh I seeeee! Yes! There was another section called input Boolean too. Didn’t notice it earlier as it was on the lower left of my control panel.
So I leave automation on and trigger the boolean section. It works!

Thank you!!! :slight_smile:

Now I can do the same for my other devices :slight_smile:

No problem. The example I posted earlier shows how to use an input_select (drop down list) for devices that have more than two states (e.g. TV channel select)

I am trying to make this work also but with no luck

this is my coniguration.yaml


# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:

# Text to speech
tts:
  - platform: google_translate

group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml



input_boolean:      ###    This is your switch in the front end
  tv_power:
    name: TV Power
    icon: mdi:power

automation:
  id: tv_power
  alias: 'TV Power'
  trigger:
    platform: state
    entity_id: input_boolean.tv_power   #### Triggered by either turning on or off the input_boolen
    action:
      service: remote.send_command
      data_template:
        entity_id: harmony_hub_studio
        device: 74755884
        command: >
          {% if is_state(trigger.entity_id, 'on') %}
            PowerOn
          {% else %}
            PowerOff
          {% endif %}


ssdp:



homeassistant:
  customize: !include customize.yaml


  
samsungtv:
  - host: 192.168.0.18
        
  

webostv:
  host: 192.168.0.30
  name: Kitchen TV
  turn_on_action:
    service: persistent_notification.create
    data:
      message: "Turn on action"
  customize:
    sources:
      - livetv
      - youtube
      - makotv
      - netflix


notify:

# MiLight integration
light:
  platform: limitlessled
  bridges:
    - host: 192.168.0.16
      groups:
      - number: 1
        name: Studio 1
        type: rgbww
        fade: true
      - number: 2
        name: Studio 2
        type: rgbww
        fade: true
      - number: 3
        name: Studio 3
        type: rgbww
        fade: true
      - number: 4
        name: Studio 4
        type: rgbww
        fade: true
    - host: 192.168.0.13
      groups:
      - number: 1
        name: Bedroom
        type: rgbww
        fade: true
      - number: 2
        name: Bedroom 2
        type: rgbww
        fade: true
      - number: 3
        name: Bathroom
        type: rgbww
        fade: true
      - number: 4
        name: Bathroom 2
        type: rgbww
        fade: true

the switch shows up but does not work
I am getting error in logs saying

Invalid config for [automation]: required key not provided @ data[‘action’]. Got None. (See /Users/simonslater/.homeassistant/configuration.yaml, line 21).

any help please thanks

action is indented way too far. It should be in line with the start of id, alias and trigger. Look at the examples in the topic above.

You may also have the issue that you are using default_config which includes automation and input_boolean already. So defining the automation and input boolean as you have may prevent you using the UI editors. Not really sure.

really confused
could someone please post correct codings and where they should go?