Pass arguments to shell_command on event

When I try without any quotes in the shell_command I get an error saying mapping values are not allowed here

I replaced the echo & redirect with a script (which was the actual goal, anyway) and that worked. Something behaves differently when there is a template in the command.

this:

automation:
  - id: bulk_quad_detector
    alias: Bulk Quad Detector
    hide_entity: true
    trigger:
      platform: event
      event_type: zwave.scene_activated
      event_data:
	entity_id: zwave.quad1
    action:
      - service: shell_command.test_press_echo
        data_template:
          scene_id: "{{ trigger.event.data.scene_id }}"
      - service: shell_command.test_press_script
	data_template:
          scene_id: "{{ trigger.event.data.scene_id }}"
      - service: shell_command.test_press_date
        data_template:
          scene_id: "{{ trigger.event.data.scene_id }}"

shell_command:
  test_press_echo: 'echo test_press_echo sceneId: "{{ scene_id }}" >> /tmp/quad.log'
  test_press_script: '/home/homeassistant/homeassistant-config/grab.sh test_press_script sceneId: "{{ scene_id }}"'
  test_press_date: 'echo test_press_date $(date) >> /tmp/quad.log'

should spit out three lines in that file, but the first test_press_echo gets lost. it ends up with:

Wed 27 Dec 21:10:20 UTC 2017 test_press_script sceneId: 4
test_press_date Wed 27 Dec 21:10:20 UTC 2017

So I got it working - If someone else runs into this, don’t mix >> and {{ }}

Thanks!!

3 Likes