Automation with motion + door sensors and timer problems

Hi
What wrong with this automation?
Even motion state on. The light and media player turn off after 1:30 minute

I want the media player and light turn off only if no any motion and door close. after 1:30 minute.

timer:
  bathroom:
    duration: '00:01:30'
- id: '1576684838552'
  alias: Bathroom on Motion Timed
  description: ''
  trigger:
  - entity_id: binary_sensor.motion_sensor_158d0002f07f28
    from: 'off'
    platform: state
    to: 'on'
  condition: []
  action:
  - data:
      entity_id: timer.bathroom
    service: timer.start
- id: '1576685072616'
  alias: End of Timer in Bathroom
  description: ''
  trigger:
  - event_data:
      entity_id: timer.bathroom
    event_type: timer.finished
    platform: event
  condition:
  - condition: and
    conditions:
    - condition: state
      entity_id: binary_sensor.door_window_sensor_158d00035ac62a
      state: 'off'
  action:
  - data:
      entity_id: media_player.googlehome4082
    service: media_player.turn_off
  - data:
      entity_id: light.64341605b4e62d5e979e
    service: light.turn_off

I think maybe this might work better for you:

- id: '1576684838552'
  alias: Bathroom on Motion Timed
  description: ''
  trigger:
  - entity_id: binary_sensor.motion_sensor_158d0002f07f28
    for: '00:01:30'
    platform: state
    to: 'off'
  condition:
  - condition: state
    entity_id: binary_sensor.door_window_sensor_158d00035ac62a
    state: 'off'
  action:
  - data:
      entity_id:
      - media_player.googlehome4082
      - light.64341605b4e62d5e979e
    service: homeassistant.turn_off

This will turn off the media player and light when the motion sensor goes to on and then to off and then stays off for 1:30, if after the 1:30 the door is closed.

The door was open 5-6-7 minutes
after i close the door. the music and light not turn off

you know maybe why ?

Yes, I do. Because you didn’t say you wanted the music and light to turn off when the door gets closed. You said you wanted them to turn off 1:30 after the sensor stops detecting motion, if at that time the door is closed. Those are two different things.

So maybe you want this:

- id: '1576684838552'
  alias: Bathroom on Motion Timed
  description: ''
  trigger:
  - platform: template
    value_template: >
      {{ is_state('binary_sensor.motion_sensor_158d0002f07f28', 'off') and
         is_state('binary_sensor.door_window_sensor_158d00035ac62a', 'off') }}
    for: '00:01:30'
  action:
  - data:
      entity_id:
      - media_player.googlehome4082
      - light.64341605b4e62d5e979e
    service: homeassistant.turn_off

This will turn them off when both the sensor is not detecting motion AND the door is closed, and it’s been that way for 1:30.

1 Like

Thanks its works really good (:grinning:

1 Like