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

Just want to say thank you very much for this blueprint.
I have recently moved from Homebridge to Home Assistant, as I think the new HomeApp is ass on ios16, and want some more flexibility.

I came across a comment essentially saying to not reinvent the wheel when you are creating automation and use blueprints as they are tried and tested. I went to the repository where they all are, and sorted by top - and this seemed to be the winner for automating lights.

As a complete newbie it did take me a little time in setting up the helpers (I hadn’t set one of those up as of yet) and assigning them.

While your documentation at the top is correct, from a complete newbie stance, its hard to understand as it assumes some knowledge. But with a bit of bashing about I was able to get there - and now understand your documentation more. Its super important to understand what entities / helpers, and their different types are, and how to set them up.

In my use I am using a Philips Hue sensor to turn on 2 downlights in my ensuite. Your blueprint is working great, as i want different lux levels and colors based on time of day.

If we could request a possible option: Sunrise/Sunset as an option.

For example, i would like my lights to turn from cool white when they are triggered during the day, to warm white if they are triggered after sunset. It may not be possible, and that’s understandable, but would be a great improvement if possible.

Either way that’s enough of my rambling, i think its important for people to know that the community work they do is appreciated, so thank you for doing this and sharing it.

Dave

I’ve been using this blueprint extensively for managing my lights for some time now and it works great, thanks. However, I’ve come up against an issue with using the optional turn-off entity:

If defined, this entity will be turned off instead of the default target entity. This can be helpful when using target entities of type scene or script.

If I put the name of a scene in there, it does not work. Looking at the code it generates I see this:

        sequence:
          - delay:
              minutes: '{{ states(no_motion_wait) | int(0) }}'
          - service: homeassistant.turn_off
            entity_id: scene.tv_dining_area_lights_off_scene

So it’s using the homeassistant.turn_off service to cail the scene. This does not work, it should use the scene.turn_on service.

Have I misunderstood something or is this a bug?

You seem to have misunderstood indeed.
Since a scene cannot be turned off, when you use a scene as a target entity, you also must define a turn-off entity (most likely a light or light group), otherwise nothing will turn off.

Thanks for the kind words. When I have some free time I’ll try to add sun state as a condition for this blueprint.

The scene is being used to turn off some of the lights in the area and to dim others, I use it in other automations using the scene.turn_on service. Yes, I could create a light group but that will only turn off all the lights in the group, so no dimming.
Your blueprint mentions target entities of type scene or script. which I took to mean that I could put a scene entity in there and it would trigger it.

If you want to do more than just turn lights off after the wait period has ended, this blueprint does not support that. Unless you would use a hacky workaround, like turning off an input_boolean helper (set as the turn-off entity). That helper entity would then be a trigger for a separate automation that turns on the scene you want to be activated. The question however if it’s then worth the effort to use this blueprint, or write your own automation altogether. That’s up to you :wink:

Yes, that’s exactly what I ended up doing, and it works fine even if it’s a bit hacky as you say.It’s just that the text describing that option let me to believe that it supported scenes directly.
Thanks!

I now took some time to add sunrise/sunset as a possible condition.
Please update the blueprint and see if it works for you.

Would it take much to tweak the blueprint to trigger based on just illumination without using a motion sensor.

Hi,
would it be possible to add a condition check for Turn-off Blocking entity just before the turn-off?
The reason ist this:
I have a template turn-off blocking entity which is getting activated if I manually press my switch 2 times within 3 seconds. But the automation is already started and already checked the turn-off blocking entity. So, the light goes off and I have to manually switch it on again.

Thank you for the nice coding :slight_smile:

The automation works like a charm with one exception. Can you please have the turn-off blocking entity to check right before turn-off? It seems that this was solved in the past, but it does not work any more.

I have made a helper entity (switch) which can be changed with a remote, but the automation does not act accordingly when the turn-off blocking entity is changed to an “on” status when the automation is already started.

It looks like the automation does not check the turn-off blocking entity right before the turn off. I tried it by putting the entity in an “on” status before the automation starts, but then it works fine.

EDIT: Actually it seems that it is quite simpel.

It was solved in my case when I exchanged the “wait for motion sensor” (5 lines) and the “turn-off blocking entity” (4 lines) in the YAML. I do not know if you had bad experiences with this exchange?

@andisp @FlorisMark I see your points, I think I fixed the issue in a new version of the blueprint.
Please test the new version and let me know if it now works correctly.

I would appreciate this feature (using luminosity as trigger instead of motion) as well.

My use case:
when it’s getting dark outside (sunset, rain, …) I would like to switch on some lights.
and of course the opposite, when it gets lighter outside (rain is over) I would like to switch the lights off.
at midnight the lights should be switched off in any case.

That’s a good one, as I am running into the same issue. But then for “Turn off time”.

I use the blueprint for managing my bathroom lights. I want to increase the turn off time if somebody is using the shower. I have a script that will increase this helper (actually based on my humidity fan). But it seems this helper is not being updated if the blueprint already runs

@freakshock,

Thanx for the try, but it is not working in my case yet.

I checked the code, but it will work if you also put the 4 ‘alias blocker entity’ lines on line 227 and 238 :slight_smile:

@FlorisMark, looking at the line numbers you mention, it seems like you have not installed the latest version of the blueprint, since it does not make sense so add more conditions at those lines. Can you confirm you have reinstalled the latest version of the blueprint and reloaded you automations? I have tested with the following settings →

motion wait defined and turn of blocker defined and on → light does not turn off after wait time
motion wait defined and turn off blocker undefined → light turns off after wait time.

If it still does not work for you, please send a screenshot of the automation trace timeline.

As mentioned before thank you very much for this blueprint. Its working perfectly fine however a suggestion if I may.

I have 2 hue globes in my bedroom. Prior to home assistant I had these connected to the hue hub and a skill with alexa setup to control them as needed.

Previously, like what this blueprint does, I had the lights fade off over a period of time.

With this blueprint, once the lights start to fade off, the lights are represented as “OFF” as the state in the dashboards. So (now that I have alexa setup with home assistant), I can no longer say “Alexa turn the bedroom lights off” - because they already are (as far as its concerned) if i issue the voice command after the dimming has already started.

Is there a way to represent the lights at the current brightness level, and as it gets dimmer, slowly decrease this, so when using voice assistants to control them it can still turn them off even when the dimming process happens.

Again, nothing not working with the blueprint, its great and doing great! Thanks so much for all the effort thus far and hopefully maybe the above is a simple suggestion.

dave

Thanks very much for this blueprint. It’s great!

I wonder if it is possible to replicate the Hue functionality whereby the lights will fade slightly if no motion is detected 30 seconds before the motion detection period is due to expire and the lights turn off?

This is different to the lights fading off over a period of time, more a prompt to move slightly as the lights are about to go off?

Thanks

Why is it exactly this blueprint works with helper entities, instead of simple numbers that are inputted directly in the blueprint template? (eg, a duration selector, instead of a helper entity variable, for the delay time) Wouldn’t that greatly facilitate the use of this blueprint?

(asking because I genuinely want to know fyi, not being witty - new to HA)

I found the problem. I was using a Shelly switch to control the lights. I had changed my Shelly setup to make it a “light” appliance. This then changed my entity from a switch to a light. So the automation couldn’t find the entity.