Please help me troubleshoot this light on/off with motion automation

I have a camera with motion detection. I have it at the entrance to the room. I want it to turn on the light when it detects motion, and then turn off the light when there is no motion for a minute.

I found this example in another post, people seemed happy with it, said it worked well. I modified to suit, and it does turn ON the light, but after I leave the room, it doesn’t turn it off.

Any help appreciated.

alias: Automatic office lights
description: Automatic office lights
trigger:
  - platform: state
    entity_id: binary_sensor.birch_neolink_1_motion
    from: "off"
    to: "on"
  - platform: state
    entity_id: binary_sensor.birch_neolink_1_motion
    to: "off"
    for: "00:01:00"
action:
  - choose:
      - conditions:
          - "{{ trigger.to_state.state == 'on' }}"
          - "{{ is_state('light.jasco_products_43080_light', 'off') }}"
        sequence:
          - service: homeassistant.turn_on
            target:
              entity_id:
                - light.jasco_products_43080_light
                - input_boolean.jasco_products_43080_light
            data: {}
      - conditions:
          - "{{ trigger.to_state.state == 'off' }}"
          - "{{ is_state('light.jasco_products_43080_light', 'on') }}"
          - "{{ is_state('input_boolean.jasco_products_43080_light', 'on') }}"
        sequence:
          - service: homeassistant.turn_off
            target:
              entity_id:
                - light.jasco_products_43080_light
                - input_boolean.jasco_products_43080_light
            data: {}

What does the trace tell you?

And why are you duplicating the light state with an input_boolean?

As far as the boolean, I’m not pretending to understand why, but I modified the automation in a post and the explanation was:

It requires that you create input_boolean.gym_patio_lights to serve as an indicator (to keep track of who turned on the light, namely you or the automation).

My understanding is that if you want a light or switch (or anything else Home Assistant can control) to turn off automatically, but only if it was turned on with an automation, you need to use the boolean.

The example I followed was here:

Link referenced for this automation

I tried using trace, and it was an interesting tool, but as I’ve never used it before, I’m not sure it helped me understand.

I’m not sure if this is a factor, but I’m using the motion detection from an IP camera, rather than a motion or presence sensor.

Tell us more about this camera-based motion sensor. For example, after you leave the room, how much time must pass before the motion sensor’s state changes from on to off. You can observe its state in Developer Tools > States.

Seems like you now have a perfect reason to learn how to use it.

It does not go to off, that’s the issue. No everyone is an IT expert. I’m doing my best for a 70 year old boomer.

Hi,

I use a timer to turn off a light after 10 minutes. This might be a better option. My yaml looks like this.

You first need to create the timer - Settings - Devices - Helpers, then refer to the timer as below, One automation switches on the light and starts the timer, the other switches off the light after 10 minutes.

- id: downtoiletmove001
  alias: Turn on Down Toilet when motion detected
  trigger:
  - platform: state
    entity_id: binary_sensor.sonoff_1_motion_occupancy
    to: 'on'
  action:
  - service: timer.start
    data:
      duration: '0'
    target:
      entity_id: timer.light_down_hall_toilet
  - service: switch.turn_on
    entity_id: switch.sonoff_t4_down_toilet
  mode: single
- id: downtoiletmove002
  alias: Turn off Down Toilet light 10 minutes after last movement
  trigger:
  - platform: event
    event_type: timer.finished
    event_data:
      entity_id: timer.light_down_hall_toilet
  action:
  - service: switch.turn_off
    entity_id: switch.sonoff_t4_down_toilet
  mode: single

Hope this helps.

Simon

If the camera-based motion sensor “does not go to off” it implies it’s permanently on.

If it’s permanently on it can’t be used in a State Trigger.

Yet you stated your automation does succeed to turn on the light which means the automation’s State Trigger did detect an off to on state-change for the motion sensor.

The two statements are contradictory; either the motion sensor is capable of reporting off or it isn’t. Which is it?

I will give it a shot, thanks. Wish I knew why the one I have didn’t work, I know there are a million automations for lights on and off with motion but they all have different twists. Certainly more than one way to do ANYTHING in HA.

Throwing an error, I think I did everything right. First created a timer called timer.office_off_timer, it is enabled. Then typed this, but got errors:

Message malformed: extra keys not allowed @ data['0']

- id: Office Light On and Off by Timer
  alias: Turn on office light when motion detected
  trigger:
  - platform: state
    entity_id: binary_sensor.birch_neolink_1_motion
    to: 'on'
  action:
  - service: timer.start
    data:
      duration: '0'
    target:
      entity_id: timer.office_off_timer
  - service: switch.turn_on
    entity_id: light.jasco_products_43080_light
  mode: single
- id: Office Light Off
  alias: Turn off office light 10 minutes after last movement
  trigger:
  - platform: event
    event_type: timer.finished
    event_data:
      entity_id: timer.office_off_timer
  action:
  - service: switch.turn_off
    entity_id: light.jasco_products_43080_light
  mode: single

Which question?