Turning on different sets of lights based on last motion

When turning on backyard light I want to always turn on my light.backyard_light on, and light.backyard_light_2 only if the was motion in the backyard in the last 30 minutes. I tried to achieve that with the following action in my automation. But, I’m doing something wrong here. Can anyone point me out what’s the correct way to achieve this? This is my code:

    action:
      service: light.turn_on
      data_template:
        entity_id: >
          {% if (as_timestamp(now()) as_timestamp(states.binary_sensor.backyard_motion.last_changed)) > 1800 %}
            light.backyard_light
          {% else %}
            light.backyard_light
            light.backyard_light_2
          {% endif %}

Looks like you’re missing a - in the first part of the template:

{% if (as_timestamp(now()) - as_timestamp(states.binary_sensor.backyard_motion.last_changed)) > 1800 %}

Also, to list multiple entity IDs in this case you need to do

light.backyard_light, light.backyard_light_2

Many thanks Tediore, that did the trick! :ok_hand: