Turn of Light if PIR is absent for 5m

Im totally frustrated. I spend 8h for the easiest job and can’t find a solution.

how to set a automation to do something when PIR is absent for 5 minutes.
in my old home automation software I just have to type if PIR xy is absent for 5m; then do.. and it resets automatically after every presents/absents.

i have tried a lot and but nothing works 100%. sometimes it works and trigger for 3-4 times and then nothing happens and the light doesn’t turn off. the most curious thing is, if it doest trigger, there is no log inside the trace function.

there is no difference between device or state trigger. is this a home assistant bug? can’t belive. I think everyone turn lights off in rooms like corridors by absents of PIR.

BTW. could it be that automations doest work correct if I write other automations and save frequently?

Please share the automation code you wrote and the manufacture and model of the PIR.

alias: Light Paradies Balon
description: |-
  ON: PIR (mlx low)
  DIM: daytime change, turn ON
  AUS: PIR (6m), mlx high
trigger:
  - type: motion
    platform: device
    device_id: de60b156a679f5e373e189a42aacbaeb
    entity_id: binary_sensor.p_paradies
    domain: binary_sensor
    id: pir_1
  - platform: device
    type: turned_on
    device_id: 9c3011856ab39057880d8716cd45b7f6
    entity_id: light.balon
    domain: light
    id: light_1
    for:
      hours: 0
      minutes: 0
      seconds: 1
    enabled: true
  - platform: state
    entity_id:
      - input_number.dlv_balon
    id: dlv
  - type: no_motion
    platform: device
    device_id: de60b156a679f5e373e189a42aacbaeb
    entity_id: binary_sensor.p_paradies
    domain: binary_sensor
    id: pir_0
    for:
      hours: 0
      minutes: 4
      seconds: 0
  - platform: numeric_state
    entity_id: sensor.p_paradies
    above: 100
    for:
      minutes: 5
    id: lxtohigh
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: pir_1
          - condition: state
            entity_id: light.balon
            state: "off"
          - condition: template
            value_template: "{{ states('sensor.p_paradies')|int < 60}}"
            alias: LX < 60
        sequence:
          - type: turn_on
            device_id: 9c3011856ab39057880d8716cd45b7f6
            entity_id: light.balon
            domain: light
            enabled: true
      - conditions:
          - condition: or
            conditions:
              - condition: trigger
                id: light_1
              - condition: trigger
                id: dlv
          - condition: state
            entity_id: light.balon
            state: "on"
        sequence:
          - service: light.turn_on
            data:
              brightness_pct: "{{states.input_number.dlv_balon.state}}"
              color_temp: 366
              transition: 2
            target:
              entity_id: light.balon
            enabled: true
      - conditions:
          - condition: or
            conditions:
              - condition: trigger
                id: pir_0
              - condition: trigger
                id: lxtohigh
          - condition: state
            entity_id: light.balon
            state: "on"
        sequence:
          - type: turn_off
            device_id: 9c3011856ab39057880d8716cd45b7f6
            entity_id: light.balon
            domain: light
mode: single

AQARA / LUMI PIR 1st Gen.

here i remove the unnecessary stuff. this is the part where the automation doesn’t work as expected

alias: Light Paradies Balon
description: ""
trigger:
  - type: no_motion
    platform: device
    device_id: de60b156a679f5e373e189a42aacbaeb
    entity_id: binary_sensor.p_paradies
    domain: binary_sensor
    id: pir_0
    for:
      hours: 0
      minutes: 4
      seconds: 0
condition: []
action:
  - choose:
      - conditions:
          - condition: or
            conditions:
              - condition: trigger
                id: pir_0
          - condition: state
            entity_id: light.balon
            state: "on"
        sequence:
          - type: turn_off
            device_id: 9c3011856ab39057880d8716cd45b7f6
            entity_id: light.balon
            domain: light
mode: single
  1. it is recommended to check if a light is ON before turn it off? or do just fire OFF ?
  2. Does editing/saving automation affects the execution of other automation?
  3. does the recorder has any effect on the “for: time” function?
recorder:
  commit_interval: 60
  purge_keep_days: 1
  exclude:
      domains:
        - automation
        - updater
        - light
      entity_globs:
        - light*
        - binary_sensor.p_*
        - binary_sensor.c_*

I removed the recorder config 2 days ago until I resolve my problem.

For trigger, I’m using

trigger:
  - platform: state
    entity_id: binary_sensor.kitchen_motion_sensor_on_off
    from: "on"
    to: "off"
    for: " {{ (states ('input_number.helper_kitchen_light')|int)|multiply(60)|timestamp_custom('%H:%M:%S', false) }}"

As you can see, I use a helper to set the time. This will make it easier for you to change the value for eg. debuging.

  1. It is recommended to check if a light is ON before turn it off? or do just fire OFF ?
    Just turn it off.

  2. Does editing/saving automation affects the execution of other automation?
    Depends on what version of HA you are on. Pre 2022.11 will reload all automations.

  3. Does the recorder has any effect on the “for: time” function?
    No

Depends on what version of HA you are on. Pre 2022.11 will reload all automations.

where does this stand? can’t find that on Releases · home-assistant/core · GitHub

no shit!? :weary: :persevere: :tired_face: :rage:

i have an eye on HA since years. now I decide to migrate and run into a shitty behavior which is resolved with the version come out two week after I start. I hate murphy law. and really everything that can happen happens here. but at least i learn in the process.

I hope this is it. thank you

ha! and does deactivating/activating a automation via another automation reload all automations too?

yes, at now ha reloads all automations if you save one in the ui, so the for does not work if you reload.
This will be better in 2022.11, you can see the release notes here

great. thank you! I have to ask again because I don’t want to run into a similar problem and spent hours of time.

does deactivating/activating a automation via another automation reload all automations?
I decide to use this a lot. I have to set less conditions and maybe I save some processing power :rofl: :grimacing:

As far as i know not, only changing or adding automations reloads all (pre 2022.11).

1 Like