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

Thank you for the info! now I have noticed that the automation has the entry elevation_check: ‘0’
but automatically adds again. I delete it from the .yaml, then the automation works once, the time runs out, the light goes out. then on the next attempt it does not work again because he has the entry elevation_check: ‘0’
adds back to .yaml.

Edit: then I have the switches twice in HA, once as a switch and as a light … I find it so confusing. then I have to work with scenes. is it possible to reactivate the blueprint V03? it worked without any problems for me.

so sadly you have the same bug :confused:

I tried to import a revision of a gist in HA but it takes the newest Version automatically.
So if you really want to use that version you need to do this yourself.

Either by forking or by copying the blueprint v03 on your ha server and using it from there.

the v08 works now so far. I am currently using the motion sensor with sun height for a time of 420 seconds, is it possible that from 10:00 p.m. - 6:00 a.m. the motion detection is only switched on for 120 seconds - so that from 10:00 p.m. the 420 seconds are deactivated and then the 120 seconds are active and then the other way around at 6 a.m.? if so, what do i have to do? Can somebody help me?

Hi,
btw, you can turn a “switch” into a light entity:

I include a “light.yaml” and in there:

  - platform: switch
    name: Kitchen Counter
    entity_id: switch.kitchenlamp

This creates the entity “light.kitchen_counter”

I´ve updated the blueprint where the elevation check bug should be fixed.

@Caligo
I did not forget you, but needed first to solve this bug.
Will be added soon.

@kallejoken
So you need two different wait times depending on time of day?
At the moment i think i will not build that in, but if more people need that i can have a look at this.

Ok, thank you for the information. then I have to implement this with various automations. because it makes no sense if the light is activated by a cat at night and then lights up for 420 seconds, so I only want 120 seconds at night.

As always there are several ways.

We too have cats and my way of doing this was to position the motion sensors in a way they rarely triggers on the cats.
But i have luck that they are cats which can go outside so the do not much stuff inside like climbing on things.
Sometimes they trigger the motion sensors (mostly on stairs) and the lights get on. But i do not really care cause the LED doesnt neet that much power and the wait time to turn off the lights a rather short here.

@Caligo
Your idea is now in the blueprint.

If you could build that in, it would be great for different waits for lights off during times of the day. +1 for Kallejoken suggestion, but not because of cats lol. I have a hallway light. During the day, want it to remain on for 5 minutes, (as sometimes sorting laundry in hall, etc, it will not always have motion). During the night, when someone is just passing through to the bathroom, would be great to have it only on for 1 minute and not shining into other bedrooms longer than needed. So, +1 for the suggestion. Always understand, not every suggestion can be added, but thank you for reading and consideration Networkingcat. Appreciate your blueprint!

Is there any way to get this blueprint to consider two different motion detectors and fire if either detector is triggered?

add both of them to a group

Is there someplace to do that in the GUI I am missing? Or is that another feature still stuck in the dark ages of yaml

1 Like

nop, yaml it is.

https://www.home-assistant.io/integrations/group/

There is a dedicated Restart Button for groups, i find it very helpfull when going that rout.

@ Jared_Heath

select your first motion sensor with the selector, the type ,binary_sensor.yoursecondsensor after the selection

It should look like this:
binary_sensor.your_first_sensor,binary_sensor.your_second_sensor

Did the trick overhere

I really like this, thank you for your hard work.

I have a scenario which I am not sure this can be configured for:

I’d like to only have the lights turned on automatically during the hours of darkness so I can use the very useful angle of the Sun, to be say <10 degrees. However if someone switches on the light during the day and leaves it on, I would still like the automation to turn it off if there is no movement after the set time.

Is that possible?

2 Likes

I am running into almost the same question but in reverse…as in I really want an automation to run during the evening only and after 11pm to not run again…leaving the lights as manually set

I don’t think this blueprint can do anything like that

I have an sensor that I uses in my automation to define (Morning, day, evening and night). Is it possible to use this instead of a spesific time? So if my sensor = Morning and motion is detected it run the morning scene?

Thanks all for your input.

@ShawWellPete

the blueprint could be changed to reflect this. So that basicly the condition is only considered if a motion sensor “turn on”.

I do not know which one is generally better or more intuitive. I could live with both.
For me this works this way because nobody is turning the lights on during the day and i use this for outside lights…

@Jared_Heath
if i understand correctly your needs you can use the automation blocker for this.
With that you can block this automation from running and lights of course stay as they are.

You basicly need to generate an input_boolean which is on when you want this automation to run (so turn in on on the evening and off at 11pm)
You can switch the “on” and “off” logic for this boolean with the automation blocker chooser.

If you need any help with that you can ask here for more help if you want.

@steinis
At the moment not.
I am thinking of adding scripts to execute but i do not when and how the logic would be at the moment.

Just that everybody knows. At the moment, when time allows, i am working on adding the feature to turn the ambient scene on and off at their times.
My usecase for this is my frond door lights. i want it on when it gets dark and not with the first motion.

1 Like

Hi there @networkingcat,

I added some features for using covers as blocker entities (open/closed) and added a “motion_blocker” if you want only to turn the lights off if e.g. the covers are open, but not turn them on…

Maybe you could take a look at it and it is useful for somebody:

blueprint:
  name: Yet Another Motion Automation
  description: "# YAMA V10\n\nTurn on lights or scenes when motion is detected. \n\
    Four 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” and/or “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/open and off for
        off/closed
      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/open and off for
        off/closed
      default: false
      selector:
        boolean: {}
    motion_blocker:
      name: Motion Blocker (Optional)
      description: Motion sequence is not run if this boolean is in desired state
        (see next input)
      default:
      selector:
        entity: {}
    motion_blocker_boolean:
      name: Motion Chooser (Optional)
      description: Desired state of motion blocker, choose on for on/open and off for
        off/closed
      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
    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
    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
    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
    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
    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
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'
  motion_blocker: !input 'motion_blocker'
  motion_blocker_boolean: !input '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''
    }}'
  - '{{ automation_blocker_boolean and states[automation_blocker].state == ''open''
    }}'
  - '{{ not automation_blocker_boolean and states[automation_blocker].state == ''closed''
    }}'
- 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'' }}'
    - condition: or
      conditions:
      - '{{ motion_blocker == none }}'
      - '{{ motion_blocker_boolean and states[motion_blocker].state == ''on''
        }}'
      - '{{ not motion_blocker_boolean and states[motion_blocker].state == ''off''
        }}'
      - '{{ motion_blocker_boolean and states[motion_blocker].state == ''open''
        }}'
      - '{{ not motion_blocker_boolean and states[motion_blocker].state == ''closed''
        }}'      
      
      
    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''
        }}'
      - '{{ no_motion_blocker_boolean and states[no_motion_blocker].state == ''open''
        }}'
      - '{{ not no_motion_blocker_boolean and states[no_motion_blocker].state == ''closed''
        }}'
    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'

Hi @networkingcat,

Thanks for creating this blueprint.

I cant seem to get it to work, could you help me with it?

Enhance the situation
On my driveway I got a foscam camera, it has motion detection capabilities. When someone enters the driveway after lets says 22:00 the lights on the garage should switch to on.

So I used your blueprint to create the following automation:

- id: 'Turnondrivewaylightswhensomeoneenters'
  alias: Turn on drive way lights when someone enters
  description: ''
  use_blueprint:
    path: networkingcat/yet_another_motion_automation.yaml
    input:
      time_scene_night: '22:00:00'
      motion_entity: sensor.foscammotion
      light_target:
        entity_id:
        - light.pilaar_5
        - light.pilaar_1
      no_motion_wait: '180'
      time_scene_evening: 00:00:00
      scene_night: scene.activatedrivewaylights
      time_scene_day: 09:00:00
      time_scene_morning: 00:00:00
      time_scene_ambient_end: 00:00:00
      time_scene_ambient_start: 00:00:00
      scene_day: scene.activatedrivewaylights

In the logbook I can see that the foscam motion switches from False to True and back to False again. But the automation Isn’t triggerd at that point…

While typing this I realise that switching from False -> True -> False maybe the issue is here. You state that switches should go from on to off, not with boolean values?

could this be the case?
If so how can we fix it :slight_smile:

Thanks in advance