Pass multiple items to command in automation

Howdy,

Trying to create automation with a list of commands to be passed to a harmony hub Device. Can get it working using JSON using the frontend and it also works fine with just one command. Please see below for more detail.

Have tried formats like:

["PowerToggle", "Oscillate"]

- "PowerToggle"
- "Oscillate"

"PowerToggle"
"Oscillate"

This one works fine with just “PowerToggle”
—start snippet—

- id: dyson_heater_bedroom_power
  alias: Dyson heater bedroom
#  initial_state: 'on'
  trigger:
    platform: state
    entity_id: input_boolean.dyson_heater_bedroom_power   #### Triggered by
either turning on or off the input_boolen
  action:
    service: remote.send_command
    data_template:
      entity_id: remote.bedroom
      device: 63913510
      command: >
        {% if is_state(trigger.entity_id, 'on') %}
          PowerToggle
        {% else %}
          PowerToggle
        {% endif %}

—end snippet—

This doesn’t do anything at all. Doesn’t blow chunks either.
—end snippet—

- id: dyson_heater_bedroom_power
  alias: Dyson heater bedroom
#  initial_state: 'on'
  trigger:
    platform: state
    entity_id: input_boolean.dyson_heater_bedroom_power   #### Triggered by
either turning on or off the input_boolen
  action:
    service: remote.send_command
    data_template:
      entity_id: remote.bedroom
      device: 63913510
      command: >
        {% if is_state(trigger.entity_id, 'on') %}
          ["PowerToggle", "Oscillate"]
        {% else %}
          PowerToggle
        {% endif %}

—end snippet—

Why cant I use a list with [“PowerToggle”, “Oscillate”]. Tried formatting on
separate lines like cdnflip did also.
e.g.

[
  "PowerToggle", "Oscillate"
]

The below JSON works as expected… but I cant use that ecept for raw
communication…

{
  "entity_id": "remote.bedroom",
  "device": "63913510",
  "command": [
    "PowerToggle", "Oscillate"
  ]
}

Thanks

You should use the tag, for your script. You will find on the editor as </> icon.

I don’t know if you can activate multiple commands in templates, maybe that’s the problem Been facing this issue myself as well.

Why not just put another service in to keep it simple

  action:
    - service: remote.send_command
      data_template:
        entity_id: remote.bedroom
        device: 63913510
        command: >
          {% if is_state(trigger.entity_id, 'on') %}
            PowerToggle
          {% else %}
            PowerToggle
          {% endif %}
    - service: remote.send_command
      data_template:
        entity_id: remote.bedroom
        device: 63913510
        command: >
          {% if is_state(trigger.entity_id, 'on') %}
            Oscillate
          {% else %}
            Oscillate #or whatever you want here
          {% endif %}

Thanks Infineghost for replying.

I guess the reason is inefficiency, duplicatoin, if it’s available to figure out in the frontend using json i was wondering why we couldn’t implement in the .yaml file.

Please note I am a newcomer to HA and hassio and yaml so no disrepsect in this PC age. I’m pc brah…and a little bit drunk.

I’ll go with your solution for now, works like a champ, thanks again. :slight_smile:

rock on.

Because it may look like a list but the template engine will pass it as a string. So your script will receive a string instead of a list.

I started testing and didn’t take to mind that the heater was in the bedroom. Wife came out a bit upset. {% is_state(profanity), ‘nosex_again’ %}

What happened with the above code was becuase there is no “power on” and power off" and “oscillate” also turns the unit on and it went Disco. lol

So the solution is to just send Oscillate to the hub which will turn it on and oscillate, but i dont know apart from adding more service if you wanted to send more via the hub i.e. temp increase, fan speed lalala.

Alternatively you can just create an activity but i dont want to resync everytime to test etc and also i have all harmony hubs blocked from the internet because of the the tracking server it tries to connect to which causes huge retarded delays with remotes connected to the hub.

Cheers

Hey Taras,

So is there a way at this point to pass that as a list to the template parser ? I coudn’t see anything in the doco and ye olde google but i’m looking at packages now to make it more managable.

There is only 1 solution that might work with a list:

- id: dyson_heater_bedroom_power
  alias: Dyson heater bedroom
  trigger:
    platform: state
    entity_id: input_boolean.dyson_heater_bedroom_power
  action:
    service: remote.send_command
    data_template:
      entity_id: remote.bedroom
      device: 63913510
      command: >
        {% if is_state(trigger.entity_id, 'on') %}
          PowerToggle, Oscillate
        {% else %}
          PowerToggle
        {% endif %}

If that does not work, then the component doesn’t have shorthand list abilities and then your only Other solution would be this, but you’ll get warnings or errors when the state is off.

- id: dyson_heater_bedroom_power
  alias: Dyson heater bedroom
  trigger:
    platform: state
    entity_id: input_boolean.dyson_heater_bedroom_power
  action:
    service: remote.send_command
    data_template:
      entity_id: remote.bedroom
      device: 63913510
      command:
        - PowerToggle
        - >
          {% if is_state(trigger.entity_id, 'on') %}
            Oscillate
          {% endif%}

I guess the last solution would be this, which will definitely work.

- id: dyson_heater_bedroom_power
  alias: Dyson heater bedroom
  trigger:
    platform: state
    entity_id: input_boolean.dyson_heater_bedroom_power
  action:
    - service: remote.send_command
      data_template:
        entity_id: remote.bedroom
        device: 63913510
        command: PowerToggle
    - condition: template
      value_template: "{{ is_state(trigger.entity_id, 'on') }}"
    - service: remote.send_command
      data_template:
        entity_id: remote.bedroom
        device: 63913510
        command: Oscillate

Home Assistant Automations do not endorse the ideals of non-duplication. They are very verbose. Consider this example (that I just whipped up, so there may be typos) of the only real way to do a “if, elseif, else” statement.

automation:
  - alias: living_occupied
    trigger:
      - platform: state
        entity_id: binary_sensor.living_occupied
        to: "on"
        from: "off"
    action:
      - service: script.living_occupied_guest
      - service: script.living_occupied_sleep
      - service: script.living_occupied_normal

script:
  living_occupied_guest:
    sequence:
      - condition: state
        entity_id: input_boolean.guest
        state: "on"
      - service: do.something

  living_occupied_sleep:
    sequence:
      - condition: template
        value_template: "{{ not is_state('input_boolean.guest', 'on')}}"
      - condition: state
        entity_id: input_select.house_mode
        state: 'sleep'
      - service: do.adifferentthing

  living_occupied_normal:
    sequence:
      - condition: template
        value_template: "{{ not is_state('input_boolean.guest', 'on')}}"
      - condition: template
        value_template: "{{ not is_state('input_select.house_mode', 'sleep')}}"
      - service: do.thedefaultthing

versus a more compact version that doesn’t work but maybe should (or something like it):

automation:
  - alias: living_occupied
    trigger:
      - platform: state
        entity_id: binary_sensor.living_occupied
        to: "on"
        from: "off"
    action:
      - condition: state
        entity_id: input_boolean.guest
        state: "on"
        sequence:
          - service: do.something
          - end
      - condition: state
        entity_id: input_select.house_mode
        state: 'sleep'
        sequence:
          - service: do.adifferentthing
          - end
      - service: do.thedefaultthing

ok cool dude, i’ll go in to enemy territory and borrow the harmony hub and dyson and ry the 1st. Then report back.

hang 15

 - PowerToggle
        - >
          {% if is_state(trigger.entity_id, 'on') %}
            Oscillate
          {% endif%}

Doesn’t like it.

even though the gui dev-service says: command A single command or a list of commands to send.

anyways, it’s resolved i guess, it works. thanks guys.

damn now the cats awake after tip toeing with that stuff. No matter what I do i’m always in trouble with the pussy :slight_smile:

If you even want a chance of something like that working, you need to make sure the list item (or service call or whatever) isn’t empty. Sometimes that means you need to make a script/action/thing that does nothing to use in these cases.

action: 
  service: remote.send_command 
  data_template: 
    entity_id: remote.bedroom 
    device: 63913510 
    command: 
      - PowerToggle 
      - "{% if is_state(trigger.entity_id, 'on') %} Oscillate {% else %}DoNothing{% endif%}"

I don’t have a Harmony Hub, so I don’t know what’s involved in making that work. But, I do a lot of this:

action: 
  service_template: >-
    {% if is_state('something','on') %}
      script.something
    {% else %}
      script.donothing
    {% endif %}

Which of course means I need a script that does nothing to exist in Home Assistant.

That’s why I said

The point was efficiency…

Thanks guys.

A summary of experience:

Some weeks ago i started researching. We implemented aeotec-zwave/lifx lights /tp link plugs in to various test environments and it’s been flawless.

zwave-plus is great just deploy where you want the sensor or if you do the zwave pull usb and pair the zwave nodes wont update unless you go to each node pressing buttons 3 times, this makes the zwave+ node mesh. Make sure to set all sensors as Binary.

OZW_Log.txt is fanatasic for zwave.
notably “EVENT”

All the automations/sensors/trigger templates have been clearly documented for all needs and are readily accessible here.

If you use a VM make sure your VM has an IDE controller.

Cheers and keep yer dick in a vice :slight_smile:

Edit updated for international.

Thank you.

The international audience that uses Google Translate to read this forum may encounter difficulties with some translated portions of your post … :thinking:

I recommend you move to appdaemon if you want efficiency. You write all your automations in python and you can get very complicated without all these ‘weird’ gotchas that the built-in automations have.

1 Like

ok i’ll check that out. or openhab that’s supposed to be alright ?
i’ve looked at node red and IDE. although HA seems to be the most stable…Using vim editing the files i mean…or have i got that wrong

Absolutely… I didn’t mean to imply you were incorrect in any way. I was just adding to the conversation for completeness.

AppDaemon/NodeRed (AppDaemon is my preferred route) work along side Home Assistant. OpenHAB (unless I’m mistaken as I don’t use it) doesn’t work with Home Assistant, but, instead, replaces it entirely.

appdaemon looks like the schitz.

Thanks again guys :+1::vulcan_salute::metal:

1 Like