Setting a timer after a trigger action

Trying to modify an active automation. Have a half bath near the kitchen, light and fan triggered by a motion sensor. However, after about a minute of no motion during the motion :slight_smile: the light shuts off. Would like to extend the time to a few minutes. Any way to do this?

entity_id: switch.caseta_r_wireless_in_wall_neutral_switch_24
service_template: |
  {% if trigger.to_state.state == 'on' %}
    switch.turn_on
  {% else %}
    switch.turn_off
  {% endif %}

Not with the service template written like that.

You’ll have to split the on and off services up into different steps.

The easiest way to do it with one automation is to use a “choose” action and make the conditions for each sequnce being the trigger state. Then in the turn off sequence add a delay.

To do what you have typed, it would just be

- service: "switch.turn_{{trigger.to_state.state}}"
  entity_id: switch.caseta_r_wireless_in_wall_neutral_switch_24

service_template and data_template are depricated as of 0.115 and completely invalid as of 0.118.

But this will trigger as soon as the motion turns on/off.

Just do a single on automation with a wait-for-trigger.

trigger:
  platform: state
  entity_id: binary_sensor.bathroom_motion
  to: 'on'
action:
  - service: switch.turn_on
    entity_id: switch.caseta_r_wireless_in_wall_neutral_switch_24
  - wait_for_trigger:
    - platform: state
      entity_id: binary_sensor.bathroom_motion
      to: 'off'
      for: "00:05:00"
  - service: switch.turn_off
    entity_id: switch.caseta_r_wireless_in_wall_neutral_switch_24

This will turn on the light, then wait until the motion sensor has been off for 5 minutes…then turn the light off.