Visual Editor not capable of doing what I need - Simple YAML

I’m fine if yall want to “teach this man to fish” rather than “give him a fish.” I’ve looked around for a couple of hours and can’t find a concise solution to my question. I have no doubt that the majority here can answer this after you get done rolling your eyes at the newbie! :wink: Feel free just to post a link or suggest a search term that I can use to find what I’m looking for.

I have a parking laser assist setup on a smart plug. These lasers are particularly prone to going dim if they are left on a lot. I have a driveway motion sensor at the end of my mailbox, and my garage door opener has an obstruction detection sensor, both integrated into HA. Currently the trigger is the obstruction sensor, and the condition is the driveway sensor is detecting motion. This won’t work obviously, because both sensors would have to be detecting simultaneously for the automation to run.

I’d like to add a condition that the driveway motion sensor must have detected movement in the last 30 seconds for the automation to run. That way, a car pulling in gives a 30 second window where the obstruction sensor can trigger the automation.

I setup the automation in Visual Editor then copy/pasted the YAML it generated below. I don’t even know how to copy paste with the YAML line numbers. I’m kind of shaking my head at myself.

EDIT: well when I tried to post the thread, the forum even told me I had no idea what I was doing and told me how to do it. So wahlah!

alias: Parking Sensor ON
description: ""
trigger:
  - type: problem
    platform: device
    device_id: 89023c15f1853a5a76823a2b10533f3f
    entity_id: f8757e78b491ca75440673cf2c0f564c
    domain: binary_sensor
condition:
  - type: is_motion
    condition: device
    device_id: 9566d75bd1a5c03ce1f7667f187bc0c4
    entity_id: 2968cf73b8b10e14be0e3f8856e383ed
    domain: binary_sensor
action:
  - type: turn_on
    device_id: b264bcbff5891d9f52d32d4a087a9a85
    entity_id: 63b3b11200be485d611f8108d5410ed6
    domain: switch
mode: single

It sounds like what you really want is a series of triggers… this can be accomplished by using the Wait for Trigger action.

Your main trigger would be the driveway detector, then you wait for the obstruction sensor to change.

alias: Parking Sensor ON
description: ""
trigger:
  - type: is_motion
    condition: device
    device_id: 9566d75bd1a5c03ce1f7667f187bc0c4
    entity_id: 2968cf73b8b10e14be0e3f8856e383ed
    domain: binary_sensor
condition: []
action:
  - alias: "Wait for MY_EVENT or light on"
    wait_for_trigger: 
      - type: problem
        platform: device
        device_id: 89023c15f1853a5a76823a2b10533f3f
        entity_id: f8757e78b491ca75440673cf2c0f564c
        domain: binary_sensor
    timeout: "00:00:30"
    continue_on_timeout: false
  - type: turn_on
    device_id: b264bcbff5891d9f52d32d4a087a9a85
    entity_id: 63b3b11200be485d611f8108d5410ed6
    domain: switch
mode: single

Also, you may want to take a look at the following:

Why and How to avoid Device triggers, conditions, and actions

1 Like

@Didgeridrew i sincerely appreciate it! Will move through this and let you know.

Alternatively, as you described it:

trigger:
  - platform: state
    entity_id: binary_sensor.OBSTRUCTION
    to: 'on'
condition:
  - or:
    - "{{ is_state('binary_sensor.DRIVEWAY', 'on') }}"
    - "{{ (now() - states['binary_sensor.DRIVEWAY']['last_changed']).total_seconds() <= 30 }}"
action:
  - service: switch.turn_on
    target:
      entity_id: switch.LASER

Fill in the entity IDs in capitals with the IDs of your sensors and switch: as per Drew’s link, we don’t like device notation here :roll_eyes: .

I’m using two shorthand template conditions to proceed only if the driveway sensor is currently detecting motion or has changed state within the last 30 seconds.

Shorthand or:

Shorthand template condition:

1 Like

Guys, can’t thank you both enough. The 2nd trigger code worked as it should, but I plan to study through both methods just for the understanding aspect of it. In the meantime, the laser doesn’t activate every time the dog walks through the garage door opening.