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.

Thanks for the replies. Tried it, doesn’t work, throws an error in the config file. So what I’ve looked at is device configuration and there is a setting:

I can change it to 300 (5 minutes), hit the set configuration parameter button, and restart the network…but it doesn’t take. This is what I get in my logfile:

2020-12-16 17:52:53.685 Info, Node032, Value::Set - COMMAND_CLASS_CONFIGURATION - On/Off Duration - 2 - 1 - 300
2020-12-16 17:52:53.685 Info, Node032, Configuration::Set - Parameter=2, Value=300 Size=2
2020-12-16 17:52:53.685 Detail,
2020-12-16 17:52:53.685 Detail, Node032, Queuing (WakeUp) ConfigurationCmd_Set (Node=32): 0x01, 0x0d, 0x00, 0x13, 0x20, 0x06, 0x70, 0x04, 0x02, 0x02, 0x01, 0x2c, 0x25, 0x6c, 0xd7
2020-12-16 17:52:53.685 Detail,
2020-12-16 17:52:53.685 Detail, Node032, Queuing (WakeUp) ConfigurationCmd_Get (Node=32): 0x01, 0x0a, 0x00, 0x13, 0x20, 0x03, 0x70, 0x05, 0x02, 0x25, 0x6d, 0xfa
2020-12-16 17:52:56.988 Detail, Node052, Received: 0x01, 0x18, 0x00, 0x04, 0x00, 0x34, 0x12, 0x56, 0x01, 0x32, 0x02, 0x21, 0x74, 0x00, 0x0f, 0x72, 0x02, 0x00, 0x05, 0x00, 0x0f, 0x53, 0x31, 0x91, 0x17, 0x66

Am I doing something wrong?

I think I had the indentation wrong. Otherwise, not sure…

  - wait_for_trigger:
      - platform: state
        entity_id: binary_sensor.bathroom_motion
        to: 'off'
        for: "00:05:00"