Turn on light, switch, scene, script or group based on motion, illuminance, sun (+ more conditions)

Hi, I just installed my conbee stick via ZHA and added my hue motion sensor. The first thing I tried was this blueprint and I like it very much. Good job! :slight_smile:

One suggestion for improvement: The official “Motion-activated Light” blueprint allows to pick an area as the target device. This is very convenient because it will trigger all lights in that area (room).
Would it be possible to add areas as possible target entities to this blueprint?

I was getting “Invalid domain name” and my automation didn’t work. It was not at all clear to me how from the example how to actually get values into the times. Example shows how to define the time entitles, but not how to set their values. If it’s possible to add the values in the automation’s YAML, show that in the example, and also mention that to use the optional features you MUST edit in YAML. I completely ignored that section because I want avoid YAML configs when possible, just an ideological thing with me.

What I did, based on the suggestion in one of the comments here, is to go to the Configuration->Helpers page and define the time and number entries, then click the slider icon thing in the upper right to set the value. I don’t know if this is the best way, but being new to HomeAssistant this is very unintuitive. I’d much rather just type the values in, but i can understand if the limitation of the language doesn’t support casting those string values.

Actually now I see that you do mention to create the helpers, in a single sentence, that I didn’t know what to do with since this is my first automation ever. Can that just be more clear that we need to go into Configuration->helpers? Now that I know what to do it’s clear, it’s just not clear to beginners.

I looked into it, but it does not seem compatible with how this blueprint is setup.
Blueprints can have entity selectors (like this one) or target selectors (which support area’s).
I cannot change this blueprint to have a target selector without breaking it for previous users.

A workaround is that instead of using area’s, you define a group for the lights you want to trigger.

1 Like

I’ve now updated the first post with info on how to do that.

It’s possible to set an initial value for helper entities in YAML, but I dont recommend using it because the value gets set to this value every time homeassistant starts. I want the value to be dynamically set and stay that way until the user changes it.

Like you yourself have found out later, using YAML is not required to use the optional features, or at all for this blueprint.

The reason for not being able to type in users is just a design choice on my part.
I wanted to use dynamic limits, not hardcoded ones.

I hope it’s more clear now, if not let me know !

perfect! now I just need to figure out how to allow multiple time frames and I’ll be completely off webcore and smartthings

I’m still pretty new to HA, so this might be obvious to most: is there a way to set the run before/after times based on sunrise and sunset? Possibly with an offset (like stop an hour after dawn, or an hour before sunset)? I know I can get Sun state, but unsure about daily datetime.

That should be possible by defining an input_datetime that is set by an automation when the sun state changes.
Some examples here.
I also see that there are already datetime values in the sun.sun entity attrributes that can be used for this.
I don’t have the exact code for this right now, but maybe someone else has something like that ready to share?

Hi
Thanks for this blueprint
As for some others here I am quite new with HA and not very good at yaml.
I was wondering if there is a reason that the time fields are somewhat “inverted” instead of having them say run from 07.00 - 18.00 ? Maybe just me but it seems more logical.

Also would it be possible to have what weekdays the automation should run, for example we have a combined office and playroom and on weekdays when it is used for office the time between motion needs to be longer 60-120 min whilst on weekends when it is used it needs to be shorter 15-20 min.

But great work with having a lot more possibilities than most motion blueprints!
Thanks

I wrote a blueprint which uses Sun elevation. I tried the sun rise/sun set time, somehow they do not work well in condition (but works perfectly if they are in trigger)

Feel free to try it: https://gist.github.com/kevinxw/abeffde9c4fac0fcc3544772a225bd60

1 Like

Hi,
I’ve been running an automation based on this blueprint for a week. It generally works very well, but there is one thing that is bugging me: During dusk, there is a time period, where the outsight light is below the cutoff, so the lights are triggered. But the lights also illuminate the sensor to a luminance higher than the cutoff value. So after the timeout, the lights go out and are not triggered immediately again by movement. Only after the illuminance sensor gets a new reading of the dark room a while later, movement will trigger this automation again. So I have to sit in the dark (rather dusk) for a while… Quite annoying.

Any tips on how get around this?

I had the same issue. My suggestion: use sun set time instead of illuminance sensor, or move your sensor to a place not under the light, or use my blueprint provided above.

Hi,

I’m rather new with HA.

I tried to use the “Only run after time” option without success. Input is for example: 10:00

The log registers the following: 2021-01-16 12:01:15 ERROR (MainThread) [homeassistant.helpers.condition] Error during template condition: TemplateError: str: Invalid domain name '11:20

No trigger at all happens. What could be the cause?

Besides this, I checked the Blue print code.2021-01-16_11-28-17 and a warning pops up (see attached file). I imported the latest version of this Blueprint.

I think I know what you mean but just to check, you think the input fields for ‘Only run before time’ and ‘Only run after time’ should be swapped? That makes sense to me;) I will change it in the blueprint.

That is hard to support with a good input field for this automation, because weekday inputs are not yet supported.
A workaround I can think of is creating 2 automations with this blueprint, and then turning the automations on and off based on the weekday.

Something a bit like:

  - alias: Turn off blueprint automation 1
    initial_state: true
    trigger:
      platform: time
      at: '00:00:00'
    condition:
      condition: time
      weekday:
        - mon
        - wed
        - fri
    action:
      - service: automation.turn_off
        entity_id: automation.generated_from_blueprint_1

It looks like the motion sensor trigger is looking for an on state.

trigger:
  platform: state
  entity_id: !input motion_sensor
  to: 'on'

My motion sensor has a few different values that it switches between.

  • Clear
  • Tampering - Cover Removed
  • Motion Detected at Unknown Location

It would be great if we could set the sensor value to as an input so this can support different types of motion sensors.

Hello,

I am quite new to HA.
I ran successfully the automation, but when I try to set before / after time I can’t have it running.

Here is my yaml:

alias: Turn on light in Bedroom
description: ''
use_blueprint:
  path: freakshock88/motion_illuminance_activated_entity.yaml
  input:
    motion_sensor: binary_sensor.motion_sensor_533b
    target_entity: switch.shelly1l_84cca8ace9c8
    time_limit_after: '19:00:00'

Any advice?

@Stephen_Tittel and @MapTo0
You both seem to use hardcoded time conditions.

Please read the first post, it explains you need to create input_datetime entities for specifying the time conditions.

I think motion sensors being ‘on’ when motion is detected is HA default behavior.

So your case is really an edgecase.
I don’t think modifying the blueprint for every edgecase that exists is a good idea for it’s maintainability.

To solve the problem I would suggest creating a binary template sensor based on your exising motion sensor that has state on when motion is detected.

Let me know if you need help with that.

Good evening, the script works perfectly, I would like to have the light switched on via a door contact and if no movement was detected for a period of 5 minutes, switch the light off again. Maybe someone can help me

Just use the door sensor as the motion sensor entity.
Otherwise just use the blueprint as described, it will work if the door sensor state = ‘on’ when the door is open :slight_smile:

1 Like

Hey, i use this automation to trigger two scripts that call rest commands. One as the turn on entity and one as the turn off entity.Any ideas how I can wrap these scripts in some entity so that the turn off wait time will work?