YAMA - Yet Another Motion Automation (Scenes, Ambient Light and some Conditions )

Yes, that is one of the flaws of this YAMA blueprint, so for now my solution is next to every automation I have a YAMA extra automation:

alias: Hallway - YAMA lux block repair
description: |-
  ALS
    EN YAMA block on (high lux, genoeg licht) 
    EN lamp = aan
  DAN lamp uit
  ALS
    EN YAMA block off (niet meer genoeg licht)
    EN beweging gedetecteerd
  DAN lamp aan.
trigger:
  - platform: state
    entity_id:
      - binary_sensor.lux_high_hallway
    for:
      seconds: 10
condition: []
action:
  - if:
      - condition: and
        conditions:
          - condition: state
            entity_id: light.relais_hallway
            state: "on"
          - condition: state
            entity_id: binary_sensor.lux_high_hallway
            state: "on"
    then:
      - service: light.turn_off
        data: {}
        target:
          entity_id: light.relais_hallway
    else:
      - condition: and
        conditions:
          - condition: state
            entity_id: light.relais_hallway
            state: "off"
          - condition: state
            entity_id: binary_sensor.motion_hallway_occupancy
            state: "on"
      - service: light.turn_on
        data: {}
        target:
          entity_id: light.relais_hallway
mode: single

1 Like

Got an extremely simple motion detection trigger light to start, but it is not working.
This is the automation code:

mode: restart
max_exceeded: silent
variables:
  scene_ambient: scene.none
  scene_morning: scene.none
  scene_day: scene.none
  scene_evening: scene.none
  scene_night: scene.none
  automation_blocker: null
  automation_blocker_boolean: false
  no_motion_blocker: null
  no_motion_blocker_boolean: false
  elevation_check: none
  scene_no_motion: scene.none
  motion_entity: binary_sensor.motion_voordeur_motion_detection
trigger:
  - platform: state
    entity_id: binary_sensor.motion_voordeur_motion_detection
    from: 'off'
    to: 'on'
  - platform: state
    entity_id: binary_sensor.motion_voordeur_motion_detection
    from: 'on'
    to: 'off'
    for: 120
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: '00:00:00'
                    before: '00:00:00'
                sequence:
                  - scene: scene.none
              - conditions:
                  - '{{ scene_day != ''scene.none''}}'
                  - condition: time
                    after: '00:00:00'
                    before: '00:00:00'
                sequence:
                  - scene: scene.none
              - conditions:
                  - '{{ scene_evening != ''scene.none''}}'
                  - condition: time
                    after: '00:00:00'
                    before: '00:00:00'
                sequence:
                  - scene: scene.none
              - conditions:
                  - '{{ scene_night != ''scene.none''}}'
                  - condition: time
                    after: '00:00:00'
                    before: '00:00:00'
                sequence:
                  - scene: scene.none
            default:
              - service: light.turn_on
                target:
                  entity_id: light.hal_onder
      - 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: '00:00:00'
                    before: '00:00:00'
                sequence:
                  - scene: scene.none
              - conditions:
                  - '{{ scene_no_motion != ''scene.none'' }}'
                sequence:
                  - scene: scene.none
            default:
              - service: light.turn_off
                target:
                  entity_id: light.hal_onder
id: '1668437140894'
alias: 0 - Lamp Hal onder (motion)
description: ''

But it fails on the sun part of the automation, which i’m not using (see automation above)

Does anyone understand why this is going wrong?
I use Neo Coolcam (Z-wave) Motion sensors

Maybe elevation should be empty, 0 or false?

Easiest way: Install this blueprint according to the manual, restart HA and then create the following automation:

- id: '1668437140895'
  alias: 0 - Lamp Hal onder (motion)
  description: 'Automatisch schakelen licht in de hal obv voordeur detectie'
  use_blueprint:
    path: networkingcat/yet_another_motion_automation.yaml
    input:
      no_motion_wait: 120
        # This means: 120s after the sensors internal blocking mechanism, perhaps as long as 90s?
        # If you want 2 minutes after you left the room, lower to 30.
      motion_entity: binary_sensor.motion_voordeur_motion_detection
        # Check for correct sensor name, doesn't it end in "_occupancy" ?
      light_target:
        entity_id:
        - light.hal_onder

Automation reload() et voila, it should work.

(since you don’t use a blocker bool, no need to add the extra automation is wrote above)

I’m not sure what you mean exactly.
When i copied above yaml as a new automation, i get an error:

Message malformed: extra keys not allowed @ data['0']

Not sure what it means.

Probably it fails because of the “_occupancy”, remove all lines with # and try again. Or it cannot find the correct blueprint? Did you install the blueprint in the correct way, is it located in home-assistant config dir?
Otherwise you could install it using the HA mode: Create a link – My Home Assistant

Check afterwards if it is installed in folder home-assistant\config\blueprints\automation\networkingcat\yet_another_motion_automation.yaml

restart HA, reload the page in your browser (CTRL-F5)

Then go to automations, click “+ create automations”, choose the correct blueprint and fill in only the first three fields:

  • motion sensor entity (choose correct entity, iets met voordeur en occupancy, icon with moving person)
  • under light, click choose entity and choose the light for the hallway
  • wait time 120 (see remark above)

Click save and give it a name, reload automations (developer tools → click automations, wait for green mark) Now it should work…

Hey, thanks for this blueprint, I have moded it (actually mostly copy/pasted from another blueprint) to only switch on the light while a light sensor reports the lux level below a threshold.
I could share my fork, but dont know if its “allowed” to just hijack the thread?
Basically have added variables and a condition for the “on” state trigger.
Also saw someone mentioning that lights arent switching off after sunset, shouldnt the elevation check also move to only check inside the “on” trigger conditions to fix this?

How do I set this up to check if I am at home? Or, my presence is in that specific room?

I’ve been trying a simple fix for the issue whereby the blocker changes state during the wait time (ending up with the light staying on in my case and never being switched off).

I’ve added an additional condition, I think it’s a) logically correct, and b) the right prop to check.

The code is as simple as: - "{{ trigger.to_state.state == 'off' }}" so that the action can still trigger (ie bypass the blocker) if the trigger state was to “off” so that any “off” actions can happen

I use HiLook cameras for motion detection. They use pixel based motion detection. When someone walks into a room the camera detects motion and turns on the lights. Then I use a 2 minute timer to turn the lights off if there is not motion. Problem is, the camera detects the light turning off as motion and turns the light back on. Any idea how to stop this?

Hi, I have the same Problem. I use a helper switch as blocker. It goes on or off in dependece of the lux within the room. But if the blocker state is changed while the light is on, it doesn’t go out anymore. But as I am totally new to Home Assistant (or Linux or coding) I do not understand where to fill in the additional condition. My YAML look this way in the moment:

alias: BadNachtlicht
description: ""
use_blueprint:
  path: networkingcat/yet_another_motion_automation.yaml
  input:
    motion_entity: binary_sensor.bewegungssensor_bad_motion
    light_target:
      entity_id: light.usb_1
    automation_blocker: binary_sensor.baddunkel
    automation_blocker_boolean: true

I would be glad if someone could help me out.

1 Like

Hi just found this awesome blueprint. im trying to use ambiend scene for a light but it doesn’t start by itself on set time.- only if a motion is triggered and then it returns to ambient. also when ambient time period is up nothing happens until motion is triggered again. or am i missing something here?

Someone may have done this, but I changed the time inputs for schedule inputs. This way you can have the same schedules in multiple rooms, see them on a dashboard and adjust them, and also have different time settings for days of the week w/out using multiple automations.
Fork here: Homeassistant blueprint for motion-activated light scene ¡ GitHub

1 Like

I have the same issue, will look deeper i to it.
Do you have any updates since your answer?

Why do i have to schoose a light/room at the top in the blueprint?? I want the scenes to turn on! I must select a rooms for it to work.
Now i running the default action that is “Light”…

Hey guys, I experienced the following:

When I use the no motion blocker to prevent the lights from switching off, the automation still triggers when motion is detected. This is on purpose, I know. However, in my configuration it is a problem in case the lights are dimmed during the evening or night, and you want brighter light. When somebody hits the dimmer to activate a bright scene or just increases the brightness as soon as motion is detected the light switches to the scene defined in my YAMA automation. When I use the same blocket in “no motion” and “automation blocker”, the light will not switch off when nobody hits the dimmer again to deactivate the “manual mode”.

Any ideas how I can improve this?

I have the problem that the automation works great as soon as it is dark. But as soon as the brightness increases while the light is on, e.g. light from outside, my lamp is no longer switched off and stays on forever. does anyone have any ideas?

Do you maybe have an input Boolean which changes the status of the automation or no motion blocker? I had this and as soon as I changed it, the lights switched off again.

yeah
i delete the boolean, ill test it :wink:

edit:
i need the Boolean.
so my inputs are only switch on is smaller then 10 lux

The sensor works at night.
but in the morning when it is slowly getting light, it switches on when there is movement but no longer switches off.

I noticed two issues with this otherwise great blueprint:

  1. The light will not turn off, if the sun elevation changes out of range after turning the light on.
  2. The motion sensor is only detected when sensing a change from “off” to “on”, not from “not available” to “on”. (Sometimes Ikea tradfri sensors show this behavior)

Are there any efforts to fix this?