[SOLVED] Help with camera automation

I’m trying to create an automation that allows me to toggle the motion detection on my blink cameras using a couple input_boolean switches. I’m having trouble with the templating and I’m not sure my syntax is entirely correct. Maybe someone here can pick out what the issue is.

  trigger:
    - platform: state
      entity_id: input_boolean.blink_cam1_toggle
    - platform: state
      entity_id: input_boolean.blink_cam2_toggle
  action:
    - service_template: >
        camera.{% if is_state( '{{ trigger.entity_id }}', 'on' ) %}disable{% else %}enable{% endif %}_motion_detection
      data_template:
        entity_id: >
          {% if '{{ trigger.entity_id }}' == 'input_boolean.blink_cam1_toggle' %}
            camera.blink_blink_xt_001
          {% else %}
            camera.blink_blink_xt_002
          {% endif %}

What I see happening is that the first test (that generates the service) always fails, so it will only try to enable motion detection. Then the 2nd test that figures out which of the two switches was clicked also fails so it only affects camera 2 no matter what.

It looks like to me either trigger.entity_id is coming back invalid, or I’m not quoting something correctly, but it seems like I’ve tried every combination. If I take away the quotes around '{{ trigger.entity_id }}', it won’t pass the config validation checker. I’m successfully using {{ trigger.entity_id }} in another automation action when sending a notification and that works just fine.

Any ideas?

  trigger:
    - platform: state
      entity_id: input_boolean.blink_cam1_toggle
    - platform: state
      entity_id: input_boolean.blink_cam2_toggle
  action:
    - service_template: >
        camera.{% if is_state(trigger.entity_id, 'on' ) %}disable{% else %}enable{% endif %}_motion_detection
      data_template:
        entity_id: >
          {% if trigger.entity_id == 'input_boolean.blink_cam1_toggle' %}
            camera.blink_blink_xt_001
          {% else %}
            camera.blink_blink_xt_002
          {% endif %}

Thanks pnbruckner! That was exactly the problem.

1 Like