Variable values in a trigger

Can I somehow get the values in a trigger to be dynamic? Like this (which doesn’t work):

- alias: Downstairs lights off at no movement
  action:
  - service: light.turn_off
    data:
      entity_id: light.downstairs
  - service: light.turn_off
    data:
      entity_id: light.dining_room
#  - service: switch.turn_off
#    data:
#      entity_id: switch.jordglob
  condition: []
  trigger:
  - entity_id: binary_sensor.downstairs_motion
    platform: state
    to: 'off'
    for:
      minutes: >- 
        {% if now().hour >= 23 and now().hour < 6 %}
          1
        {% else %}
          20
        {% endif %}

I’m not sure that’s possible. Think you may have to create 2 automations, and move your variable bit inside a condition block

That is not possible for the for category. The only variables that can be introduced into triggers is with a value_template trigger. If you set it up properly, you could mimic a for x time duration but it takes alot of setup.

  trigger:
  - platform: template
    value_template: "{{ is_states('domain.device',value) }}

If you wanted to get a for duration you’d probably be best off creating a template sensor that returns true when a device has been a state for x amount of time. Then trigger off that.

The ideas suggested so far are probably easiest and therefore maybe best. But, if you do want to do this with one automation, then I believe it’s possible. The idea is to have two triggers (one for 1 min, and another for 20 min), then filter them (via a template condition) depending on when the motion sensor went off. Something like this:

- alias: Downstairs lights off at no movement
  trigger:
  - entity_id: binary_sensor.downstairs_motion
    platform: state
    to: 'off'
    for: '00:01'
  - entity_id: binary_sensor.downstairs_motion
    platform: state
    to: 'off'
    for: '00:20'
  condition:
    condition: template
    value_template: >
      {% set off_hour = trigger.to_state.last_changed.hour %}
      {% set off_at_night = off_hour >= 23 or off_hour < 6 %}
      {% set off_min = (trigger.for.total_seconds() / 60)|round %}
      {{ off_at_night and off_min == 1 or not off_at_night and off_min == 20 }}
  action:
  - service: homeassistant.turn_off
    entity_id:
      - light.downstairs
      - light.dining_room
      - switch.jordglob

Disclaimer: This is based on theory and some minimal testing. I haven’t actually tried all of this together, so the details may be off in places. But hopefully it gets the idea across and gives you at least a starting point.