Motion Detector with YAMA (Yet Another Motion Automation)

Good Morning,
I have several motion detectors for turning on the lights in the house automatically for 2 minutes. Is working fine so far, but there is one challange:

Example:
On my staircase, I have two motions sensor, one on the grooundfloor, one on the 1. Level. When the first one in the groundfloor is triggered the two minutes are counted down and the light goes out, no matter what.

But what I want to archive is that the countdown starts again, two minutes, when triggering the light now in the first floor. Assuming there is 30 seconds rest and I’m passing the second motion detector on the first floor, it is supposed to setting the time to two minutes again because otherwise the light goes off while I walk down the stairs which is dangerous at night time.

Any Ideas how I may archive that?

This is how my simple automation looks like, using the blueprint “yet_another_motion_automation” and the parameter “no_motion_wait” - which I want to override when passing the second motion detector for the same light wihtin these two minutes:


alias: TRADFRI EG Treppe
description: Licht Treppe geht an
use_blueprint:
path: networkingcat/yet_another_motion_automation.yaml
input:
motion_entity: binary_sensor.tradfri_kellertuer_bewegung
light_target:
device_id:
- daf0b43b9170de0fad11c9f05478dde8
- e115a4d676918465f0580cefc90e85ed
- 7416fa470cf41d363a0a454ce2c28db4
- 2068d2987eac9b16f42fd3e6cab748f7
- 14b66ed3d10ba1d735c75301bb04e53d
- 1fc399e24b118e343a6a57c59fcfdce0
no_motion_wait: 120

Thanks

A couple of general tips for you:

  • Post your full automation and make sure to format it correctly.
  • Instead of creating your own thread, why didn’t you post in the blueprint topic?
  • That topic I linked to above clearly states you can use a “no motion blocker” to accomplish what you want, including a flowchart which explains how it works.

Have a read through that thread and try to use the information provided there. If something isn’t clear, posting there will increase your odds of getting an answer which is compatible with that particular blueprint

Have you tried a “wait for trigger” with the other motion detector? You would have to do two automations: One for someone going upstairs and another for someone going downstairs.

Hi,

I didn’t post it over there because I thought I maybe wrong to post it there.

But I believe I explained it maybe bad due to my english. So this is what I want to archieve:

I want the light to go out, but I want the first motion detector in the Ground Floor to be overwritten by the second motion detector in the Second Floor, so that the 2 Minutes to keep the lights on then counts down from the beginning again. If I goint to set the no_motion_blocker in both motion detectors - the light will never switch off - I’m I right or do I read the workflow in a wrong way?

Hi,

thanks for the answer - but this means 8 more automations… I try rather to find a way to solve it within the same automation. I’m loosing already track of things with 70 automations.

If that’s the only scenario, you would only set the no motion blocker on the ground floor sensor. The second floor sensor doesn’t need to block anything.

The previous suggestion to use wait for trigger would also work, and no, you wouldn’t need to set up more automations. You’d just edit your existing one or modify the blueprint.

Again, I suggest posting in the blueprint topic since people there will be more familiar with the most efficient way to handle this.

Hi,

I want it actually both ways.

Groundfloor > 1. Level

  1. Level > Groundfloor

Actually, it shouldn’t matter which motion detector I pass and trigger, the timer always should count from the beginning again (120 Seconds) and deactivate the ones that I triggered, for example, a minute before.

I moved the thread to the “Blueprint Exchange” Section.

Thanks

In that case, you’ll need to insert a wait_for_trigger with continue_on_timeout: true and a delay of 2 mins, as suggested.

PS- Blueprints Exchange is just what the name implies - it’s used to share blueprints, not to post new topics with individual issues.
Just add it as a reply in the YAMA topic I linked to earlier, since that is specific to your blueprint

Hard to understand, as in YAML, indents tell the story.
How to help us help you - or How to ask a good question.

That said without looking at your code, if you create an automation that triggers on the first sensor, has a wait-for-trigger #2 and then does your other thing. You have the flowchart in that paragraph already, just do all the things in an automation.

Hi,

Thanks a lot and also thanks for being patient with me since I have not much experience with this kind of material - never did automations before in yaml files.

therefore, may I kindly ask where I have to put what parameters and what syntax exactly in the yaml file?

Right now it looks like that:

alias: TRADFRI EG Treppe
description: Licht Treppe geht an
use_blueprint:
  path: networkingcat/yet_another_motion_automation.yaml
  input:
    motion_entity: binary_sensor.tradfri_kellertuer_bewegung
    light_target:
      device_id:
        - daf0b43b9170de0fad11c9f05478dde8
        - e115a4d676918465f0580cefc90e85ed
        - 7416fa470cf41d363a0a454ce2c28db4
        - 2068d2987eac9b16f42fd3e6cab748f7
        - 14b66ed3d10ba1d735c75301bb04e53d
        - 1fc399e24b118e343a6a57c59fcfdce0
    no_motion_wait: 180
    no_motion_blocker_boolean: false
    no_motion_blocker: binary_sensor.bewegungsmelder_1_og_bewegung

Thanks
Wolfgang

That seems to be only a tiny part of the automation.

Please include the entire automation with the trigger, conditions & actions showing

Hi,

that’s all I have +The BluePrint in the HA Directory:

/homeassistant/blueprints/automation/networkingcat/yet_another_motion_automation.yaml:

blueprint:
  name: Yet Another Motion Automation
  description: "# YAMA V10\n\nTurn on lights or scenes when motion is detected. \nFour
    different scenes can be defined depending on time of day.\n\nFor Details see this
    forum post:\nhttps://community.home-assistant.io/t/yama-yet-another-motion-automation-scenes-ambient-light-and-some-conditions/257062?u=networkingcat\n\nCapabilitys:\n\n
    - Trigger on motion (in fact can be triggered by anything that switches between
    “on” and off\")\n - Wait time for turning off\n - Only run if entity is in desired
    state (optional)\n - Sun elevation check (optional)\n - 4 Scenes for different
    times of day (optional)\n - Ambient support with time frame (optional)\n - Default
    scene when motion stops (optional)\n - “no motion blocker” with user choosable
    state (optional)\n"
  domain: automation
  source_url: https://gist.github.com/networkingcat/a1876d7e706e07c8bdcf974113940fb8
  input:
    motion_entity:
      name: Motion Sensor
      description: Motion Sensor or a group with Motion Sensors (But can be anything
        switching between "on" and "off")
      selector:
        entity: {}
    light_target:
      name: Light
      selector:
        target:
          entity:
          - domain:
            - light
    no_motion_wait:
      name: Wait time
      description: Time to leave the light on after last motion is detected.
      default: 120
      selector:
        number:
          min: 0.0
          max: 3600.0
          unit_of_measurement: seconds
          mode: slider
          step: 1.0
    automation_blocker:
      name: Automation Blocker (Optional)
      description: Only run if this boolean is in desired state (see next input)
      default:
      selector:
        entity: {}
    automation_blocker_boolean:
      name: Automation Blocker Chooser (Optional)
      description: Desired state of automation blocker, choose on for on and off for
        off
      default: false
      selector:
        boolean: {}
    no_motion_blocker:
      name: No Motion Blocker (Optional)
      description: No motion sequence is not run if this boolean is in desired state
        (see next input)
      default:
      selector:
        entity: {}
    no_motion_blocker_boolean:
      name: No Motion Chooser (Optional)
      description: Desired state of no motion blocker, choose on for on and off for
        off
      default: false
      selector:
        boolean: {}
    elevation_check:
      name: Sun elevation check (Optional)
      description: This is the angle between the sun and the horizon. Negative values
        mean the sun is BELOW the horizon.
      default: none
      selector:
        number:
          min: -90.0
          max: 90.0
          unit_of_measurement: degrees
          mode: slider
          step: 1.0
    scene_ambient:
      name: Ambient Scene (Optional)
      description: Scene for ambient state. Will be activated when no motion is detected.
      default: scene.none
      selector:
        entity:
          domain:
          - scene
          multiple: false
    time_scene_ambient_start:
      name: Ambient time frame start (Optional)
      description: Time from which on ambient scene will be activated
      default: 00:00:00
      selector:
        time: {}
    time_scene_ambient_end:
      name: Ambient time frame end (Optional)
      description: Time from which on ambient scene will be not activated
      default: 00:00:00
      selector:
        time: {}
    scene_morning:
      name: Scene for the morning (Optional)
      default: scene.none
      selector:
        entity:
          domain:
          - scene
          multiple: false
    time_scene_morning:
      name: Time for the morning scene (Optional)
      description: A time input which defines the time from which on the scene will
        be activated if motion is detected.
      default: 00:00:00
      selector:
        time: {}
    scene_day:
      name: Scene for the bright day (Optional)
      default: scene.none
      selector:
        entity:
          domain:
          - scene
          multiple: false
    time_scene_day:
      name: Time for the day scene (Optional)
      description: A time input which defines the time from which on the scene will
        be activated if motion is detected.
      default: 00:00:00
      selector:
        time: {}
    scene_evening:
      name: Scene for the evening (Optional)
      default: scene.none
      selector:
        entity:
          domain:
          - scene
          multiple: false
    time_scene_evening:
      name: Time for the evening scene (Optional)
      description: A time input which defines the time from which on the scene will
        be activated if motion is detected.
      default: 00:00:00
      selector:
        time: {}
    scene_night:
      name: Scene for the dark night (Optional)
      default: scene.none
      selector:
        entity:
          domain:
          - scene
          multiple: false
    time_scene_night:
      name: Time for the night scene (Optional)
      description: A time input which defines the time from which on the scene will
        be activated if motion is detectedd.
      default: 00:00:00
      selector:
        time: {}
    scene_no_motion:
      name: Default scene for no motion (Optional)
      description: Set this Scene if you want to activate a scene if motion stops
      default: scene.none
      selector:
        entity:
          domain:
          - scene
          multiple: false
mode: restart
max_exceeded: silent
variables:
  scene_ambient: !input scene_ambient
  scene_morning: !input scene_morning
  scene_day: !input scene_day
  scene_evening: !input scene_evening
  scene_night: !input scene_night
  automation_blocker: !input automation_blocker
  automation_blocker_boolean: !input automation_blocker_boolean
  no_motion_blocker: !input no_motion_blocker
  no_motion_blocker_boolean: !input no_motion_blocker_boolean
  elevation_check: !input elevation_check
  scene_no_motion: !input scene_no_motion
  motion_entity: !input motion_entity
trigger:
- platform: state
  entity_id: !input motion_entity
  from: 'off'
  to: 'on'
- platform: state
  entity_id: !input motion_entity
  from: 'on'
  to: 'off'
  for: !input no_motion_wait
condition:
- condition: or
  conditions:
  - '{{ automation_blocker == none }}'
  - '{{ automation_blocker_boolean and states[automation_blocker].state == ''on''
    }}'
  - '{{ not automation_blocker_boolean and states[automation_blocker].state == ''off''
    }}'
- condition: template
  value_template: '{{ (elevation_check == none) or (state_attr(''sun.sun'',''elevation'')
    <= elevation_check | float(90)) }}'
action:
- choose:
  - conditions:
    - condition: template
      value_template: '{{ trigger.to_state.state == ''on'' }}'
    sequence:
    - choose:
      - conditions:
        - '{{ scene_morning != ''scene.none''}}'
        - condition: time
          after: !input time_scene_morning
          before: !input time_scene_day
        sequence:
        - scene: !input scene_morning
      - conditions:
        - '{{ scene_day != ''scene.none''}}'
        - condition: time
          after: !input time_scene_day
          before: !input time_scene_evening
        sequence:
        - scene: !input scene_day
      - conditions:
        - '{{ scene_evening != ''scene.none''}}'
        - condition: time
          after: !input time_scene_evening
          before: !input time_scene_night
        sequence:
        - scene: !input scene_evening
      - conditions:
        - '{{ scene_night != ''scene.none''}}'
        - condition: time
          after: !input time_scene_night
          before: !input time_scene_morning
        sequence:
        - scene: !input scene_night
      default:
      - service: light.turn_on
        target: !input light_target
  - conditions:
    - condition: template
      value_template: '{{ trigger.to_state.state == ''off'' }}'
    - condition: or
      conditions:
      - '{{ no_motion_blocker == none }}'
      - '{{ no_motion_blocker_boolean and states[no_motion_blocker].state == ''on''
        }}'
      - '{{ not no_motion_blocker_boolean and states[no_motion_blocker].state == ''off''
        }}'
    sequence:
    - choose:
      - conditions:
        - '{{ scene_ambient != ''scene.none'' }}'
        - condition: time
          after: !input time_scene_ambient_start
          before: !input time_scene_ambient_end
        sequence:
        - scene: !input scene_ambient
      - conditions:
        - '{{ scene_no_motion != ''scene.none'' }}'
        sequence:
        - scene: !input scene_no_motion
      default:
      - service: light.turn_off
        target: !input light_target

You are using a blueprint, which is fine, but that also means that all of the actions are in the blueprint and it is the actions you have to change. I do not recommend a rookie take on changing a blueprint.

That means to do something custom you would need to draw out on paper what things you want to do and the order you want them to happen, and write the automation yourself.