Create own version of blueprint "motion-activated light"?

Tags: #<Tag:0x00007f325b662af8>


Just got back into tinkering with my HA-installation and of course there’s questions. I want to use the blueprint “motion-activated light” but also add a criteria for the lux level of the room - would the easiest way to add this to be creating own automations?

If I try to create something similar to the blueprint, I end up with two automations - one for turning on the lights and one for turning off again after x number of minutes. But the automation does both in one automation… Am I missing something when I create my own automations?

Thank you,

Yes, and it’s quite tricky (or elegant). The blueprint uses mode “restart”, meaning everytime motion is triggered the delay to turn off is cancelled and automation’s action sequence starts again. This works because it doesn’t harm to turn an already “on” light on again.

mode: restart
max_exceeded: silent

but wouldn’t I need two automations if I’m trying to recreate the blueprint? One for turning on and one for off?


check the blueprint’s automation part at Github (or your local drive).

It triggers only if motion is detected (off to on), turns the lights on and starts the delay to turn them off. If during that time motion is detected again, the script part is started again, effectively restarting the delay again.

Only thing that isn’t matched by this is continuous motion (trigger alwas on).

Okay, I think I’ll have to do a lot more reading on blueprints vs. automations, because I don’t understand the sequence of the blueprint. Thank you for the assist!

Actually it’s quite easy:

  • lines 31 to 50 is the actual automation, but instead of fixed values or entities, it uses variables (declared by !input)
  • lines 1 to 30 is the actual blueprint “overhead”, some metadata and the declaration of the supported !input variables.

When you create an automation based on a blueprint, that automation references the blueprint and defines values for the given variables. If you change the blueprint afterwards (and don’t break it), all automations created from that blueprint will be using the new logic.

so I could just create an automation based on the blueprint and afterwards insert the lux-criteria in the created automation?

No. An automation created from a blueprint does not support trigger, condition or action sequence. It looks like this (automation.yaml):

- id: 'xzy'
  alias: My Alias
  description: ''
    path: m0wlheld/control_nightlight.yaml
      transition_var: '5'
      darkness_entity: input_boolean.outdoor_darkness
      cover_entity: cover.my_cover_entity
      light_entity: light.my_light

So it’s just a link to the blueprint and the values for the variables.

Show me the ‘lux’ condition of your automation and I will show you the blueprint to create.

Thanks - my lux condition is just:

  - condition: numeric_state
    entity_id: sensor.light
    below: '200'

Copy this to config/blueprints/automation/[custom_subdir]/[custom filename].yaml and reload.

  name: Motion-activated Light
  description: Turn on a light when motion is detected.
  domain: automation
      name: Motion Sensor
          domain: binary_sensor
          device_class: motion
      name: Light
            domain: light
      name: Wait time
      description: Time to leave the light on after last motion is detected.
      default: 120
          min: 0
          max: 3600
          unit_of_measurement: seconds
      name: Light sensor
      description: Light sensor to read from
            domain: sensor
      name: Light threshold 
      description: Light sensor‘s lower threshold 
      default: 200
          min: 0
          max: 255

# If motion is detected within the delay,
# we restart the script.
mode: restart
max_exceeded: silent

  platform: state
  entity_id: !input motion_entity
  from: "off"
  to: "on"

  - condition: numeric_state
    entity_id: !input light_sensor
    below: !input light_threshold

  - service: light.turn_on
    target: !input light_target
  - wait_for_trigger:
      platform: state
      entity_id: !input motion_entity
      from: "on"
      to: "off"
  - delay: !input no_motion_wait
  - service: light.turn_off
    target: !input light_target

Thought it worked, but apparently not. Getting this error message:

unknown tag !<!input> at line 50, column 34:
      entity_id: !input motion_entity

Did you put the file into the correct location? There are no errors in it, with respect to being a blueprint, but it will fail miserable if being used as an automation’s source …

I created a new folder and placed it there. Still getting an unknown tag error :thinking:

I copied the code 1:1 from my post into a file at /config/blueprints/automation/m0wlheld/motion_lights.yaml and is does not trigger an error. Also created an automation from that blueprint (yet, didn’t save it), and it appeared okay.

That‘s all I can say …

Looks like the issue is somewhere in my HA. Current error message points to my configuration.yaml file, stating that it “failed to load blueprint”.

Probably have to do some forensics to try and find the issue.

Edit: No longer getting an error message in the log, but still no luck in creating the lux-blueprint. The blueprint shows up, I can enter the data and then press create automation without issue, but it doesn’t result in any automation in the automation list. The weird thing is that when I go to automations.yaml, I can see the just created automation.

Don’t really understand where the issue might be. Using the original blueprint works fine.