#having an issue with an automation:

1 messages · Page 1 of 1 (latest)

novel vault
#

I have an automation that turns lights on and off after 2 min or after motion clears for 2 min. Works most of the time with no issue. However, occasionally, the lights will stay on indefinitely. Given it's in the garage, I don't always see it until hours later. I would appreciate any insights. Thank you

I am providing the yaml below:

id: '1730680757547'
alias: Garage - Main Lights On with motion or door opens
description: >-
Garage Main Light turns on with motion or when door opens, then turn off
after 2 minutes without motion.
triggers:

  • type: opened
    device_id: ba6affa2ae5303e3156af79b13cf6cdf
    entity_id: f6e1b2988199dacedb59dd9392524bc3
    domain: binary_sensor
    trigger: device
    id: Garage entry door opened
    alias: When garage entry door opens
  • trigger: state
    entity_id:
    • binary_sensor.garage_motion
      to: 'on'
      id: Garage motion detected
      alias: 'Garage Motion Detected '
  • device_id: 83a1ebf3a582832293ec8868f69029ca
    domain: zwave_js
    type: event.value_notification.central_scene
    property: scene
    property_key: '001'
    endpoint: 0
    command_class: 91
    subtype: Endpoint 0 Scene 001
    trigger: device
    value: 0
    id: Manually pressed
    alias: 'Light turned on manually '
    conditions:
  • condition: numeric_state
    entity_id: sensor.garage_motion_sensor_illuminance
    below: 100
    actions:
zinc folio
#

Can you format your code with 3x ` on the line before and after
Cos this is unreadable with discord's formatting

novel vault
#

Thank you very much for your reply. I am Sorry. I'm unsure what you mean; I am relatively new to this. Can you elaborate? I would happily do so. What is 3x '?

jolly edgeBOT
#

To format your text as code, enter three backticks on the first line, press Enter for a new line, paste your code, press Enter again for another new line, and lastly three more backticks.
```yaml
example: here
```
Don't forget you can edit your post rather than repeatedly posting the same thing.

mortal girder
#

that

#

it's unreadable as it is

novel vault
#
id: '1730680757547'
alias: Garage - Main Lights On with motion or door opens
description: >-
  Garage Main Light turns on with motion or when door opens, then turn off
  after 2 minutes without motion. 
triggers:
  - type: opened
    device_id: ba6affa2ae5303e3156af79b13cf6cdf
    entity_id: f6e1b2988199dacedb59dd9392524bc3
    domain: binary_sensor
    trigger: device
    id: Garage entry door opened
    alias: When garage entry door opens
  - trigger: state
    entity_id:
      - binary_sensor.garage_motion
    to: 'on'
    id: Garage motion detected
    alias: 'Garage Motion Detected '
  - device_id: 83a1ebf3a582832293ec8868f69029ca
    domain: zwave_js
    type: event.value_notification.central_scene
    property: scene
    property_key: '001'
    endpoint: 0
    command_class: 91
    subtype: Endpoint 0 Scene 001
    trigger: device
    value: 0
    id: Manually pressed
    alias: 'Light turned on manually '
conditions:
  - condition: numeric_state
    entity_id: sensor.garage_motion_sensor_illuminance
    below: 100
actions:
#

Is this better. Sorry, I was unable to edit the original.

mortal girder
#

It's missing the actions

novel vault
#

Thanks. Trying again,, sorry.

charred yacht
#

So there are several issues with this logic:

  1. Under the choose branch, switch.turn_off is only called if binary_sensor.garage_motion is off 2min after the switch is turned on. If it so happens that at that moment, the sensor is on, then switch.turn_off will not run.
  2. The switch.turn_off in the if action also may not run, if the conditions are not true at the moment that the automation is triggered.
  3. If it so happens that HA is restarted while the automation is waiting 2min, the automation will be reset and switch.turn_off will not run.
#

Would you consider splitting the automation into 2, one for turning on the light given certain triggers, and the other to turn it off given a different set of triggers (eg. binary_sensor.garage_motion has been off for: 120?

frosty sail
#

You can keep it all in one automation if you’d like, but I agree that more triggers should be added and delays should be removed.

In general: use lots of triggers. Think of all the possible events that could kick off the action you want to happen. Each one should be its own trigger.

I didn’t error-check this, but this is the general idea
https://dpaste.org/RNDkC