Why is this automation turning light on when entering, but not off after 10 minutes inactivity?

I’m at a loss. Trace is beyond my scope. Let me make a comment and tell me I’m wrong. When new people here ask how to do an automation to make lights go on with motion, and off with absense of motion, they get comments like “there are a hundred of these, do a search”. Well, I’ve tried about 5 that were posed, did the modifications as necessary, and none of them worked. When I get good people trying to help me, none of their solutions work. And these are experienced people (like you reading this) with an automation that would seem to be very very common.

I’m aware that HA is a work in progress, but for new people, this is really, really hard. I’m going to have to give up on this.

1 Like

Rick, I would love it if you would provide those for me.

Turn on Automation:

- id: '1628660691232'
  alias: Lights-Turn On Front Porch Light When Front Door Cam Detects Motion
  description: ''
  trigger:
  - platform: state
    entity_id:
    - binary_sensor.ds_hd1_motion_alarm
    from: 'off'
    to: 'on'
  action:
  - service: switch.turn_on
    data: {}
    target:
      entity_id: switch.front_porch

Turn Off Automation:

- id: '1628661743315'
  alias: Lights-Turn Off Front Porch Light When Front Door Cam Motion Stops for 5
    Minutes
  description: ''
  trigger:
  - platform: state
    entity_id:
    - binary_sensor.ds_hd1_motion_alarm
    from: 'on'
    to: 'off'
    for:
      hours: 0
      minutes: 5
      seconds: 0
  action:
  - service: switch.turn_off
    target:
      entity_id:
      - switch.front_porch

By the way, have you tried to use the Blueprint already available with your Home Assistant?
When creating a new automation, you are offered to create your automation from an existing blueprint and some are offered, including one named “Motion-activated Light”. That is tested by a lot of users and it is quite good and simple.

1 Like

Maybe I’m misunderstanding something fundamental. Rick are you saying with this automation, I can go into Services → Automation → Create Automation → Create New Automation → 3 dots Edit in YAML, then paste it in exactly save for the name of my sensor and switch, and that should work.

Because every time I do that, I get errors and it won’t save. Specifically: Message malformed: extra keys not allowed @ data[‘0’]

My automation looks like this:

- id: '1628660691232'
  alias: Lights-Turn On Front Porch Light When Front Door Cam Detects Motion
  description: ''
  trigger:
  - platform: state
    entity_id:
    - binary_sensor.birch_neolink_1_motion
    from: 'off'
    to: 'on'
  action:
  - service: switch.turn_on
    data: {}
    target:
      entity_id: light.jasco_products_43080_light

Can you tell me where I would find that?

The blueprint @EdwardTFN is suggesting can be found on the list that is shown when you click the button to create a new automation.

Used the automation from the blueprint, and that did turn the light off after I left for seconds, but immediately turned it back on. In other words, the light will not stay off.

Would this still happen if I was using a motion detector instead of a camera? Is that the issue? Does the camera see the light off as motion?

Picture of automation attached.

Are you sure you don’t have any other automation turning on your lights?

If you go to your light under Settings > Devices and Services, you will find a box showing the last entries in the Logbook related to that device. There you can see what is turning on your light right after your automation turns it off.

Great tip. Attached two screenshots but you can see camera motion turning off then on at the same second.


Your camera is detecting the lights going off as a movement…

So any solution? And is that normal?

Well first yes, but you kept my automation ID. Remove that and it should work.

In addition, I’d do it in the GUI not in YAML since you a newbie as it will catch little issues.

Sounds like you have another issue as ur camera is catching the light going off as motion.

Is it automatically generated, the ID and if I understand it correctly it’s only purpose is so that you can edit it in the visual editor?

I wouldn’t expect any motion sensor to capture a light turning off as a motion, but if your camera is doing that, maybe you have to find a work around.
I always like more real motion sensors, even having cameras in some of the areas where I monitor for motion. :wink:

There’s always a solution, but that will require a bit more thinking for a new automation which would take in account this behavior from your camera, as some test so you discover the unknown behaviors.

Let’s try this… delete all your automations used to control this light, then go to Settings > Automations & Scenes > Create new automation > Click on the 3-dots menu at the top right and select “Edit YAML”, then paste this and save:

description: ""
mode: single
trigger:
  - id: Motion detected
    platform: state
    entity_id:
      - binary_sensor.birch_neolink_1_motion
    to: "on"
  - id: Motion stopped
    platform: state
    entity_id:
      - binary_sensor.birch_neolink_1_motion
    to: "off"
    for:
      minutes: 1
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: Motion detected
          - condition: state
            entity_id: light.jasco_products_43080_light
            state: "off"
            for:
              seconds: 3
        sequence:
          - service: light.turn_on
            data: {}
            target:
              entity_id: light.jasco_products_43080_light
      - conditions:
          - condition: trigger
            id: Motion stopped
        sequence:
          - service: light.turn_off
            data: {}
            target:
              entity_id: light.jasco_products_43080_light

Basically I’m repeating your original automation (just trying to put in an easier to understand format) and adding a condition to not turn on the light until it is off for at least 3 seconds.

Please let me know how this one works.

That seems to have fixed it. Thanks so much. No I’m going to study it to make sure I understand it all.

1 Like

I am not sure what the ID does, but I do know when I was first starting, I copied someone else’s automation ID and my system basically said nice try and have a nice day.

The ID simply needs to be unique in your system. If you’re using the UI editor it’ll create one behind the scenes for you.

Thank you.

Take a look at this post about unique_id and entity_id: