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

The turn-off blocking entity only works when this entity’s state is ‘on’.
Probably your TV state is not ’ on’ , but ‘playing’ when it is on. That’s why it is not working.
Tou could work around that by setting a binary sensor based on your TV’s state.

Turn-off enity will turn off the defined entity. Turning off a script has no meaning here.

1 Like

Thanks freakshock. That makes sense I will give that a go. :+1:

Yup. Looks like you ran into the same issue that I did. I could not get the times to span midnight. Other than that, it’s a good blueprint.

Hey @freakshock,

first of all, thanks for this well working blueprint! I have a scenario where I’m just wondering if I should request and additional feature from you. Or maybe you can suggest another way using the existing features?

My scenario: I have a night mode (on/off). The brightness of the lights should be controlled depending on whether the night mode is on or off. In addition, it would make sense to define a value (e.g. using input_number) for the brightness in each mode.

Which way would you suggest?

Cheers, red

The blueprint works very well. Thanks @freakshock. Is it possible to add a feature that if a light switch is turned on manually, the off will be blocked so that it will only be turned off manually too?

You should take a look at adaptive lighting (https://github.com/basnijholt/adaptive-lighting) which also offers a sleep mode. Might fit your needs way better.

I’ve read the adaptive light but not sure how it meets my requirements. Basically I need auto turn on/off lights by motion as this blueprint perfectly serves. In additional, if the user manually turns on the light, they should manually turns off the light afterwards (no auto motion on/off). After the light was turned off manually, the auto mode is re-activated again.

This scenario should be possible witth the current blueprint. It requires some creative workarounds though.

Create two automations with this blueprint:

  • One has a blocker entity for your night mode, which should then only run during the day.
    In this automation you define a scene as a trigger entity with the required brightness values for the light.

  • The other should use a blocker entity with a binary template sensor which has the opposite value of the night mode one. So when night mode is on, this sensor is off and the reverse.
    You then use this sensor as your blocker entity for the second automation. This means that this automation runs during the night. Here again define a specific night scene with required values.

This might be more effort than just writing an automation from scratch, but I thought I would answer you question about how it would be possible witth this blueprint.

1 Like

Thanks. I tried to think of a way to incorporate your request, but can’t really think of a way to integrate this in the blueprint itself without requiring any other logic.

Perhaps there is a another way though:
I don’t know how you normally ‘manually’ turn on your light. But for instance if you turn it on using a physical switch, perhaps you could have this switch trigger a script which does two things:

  • Turn on the light
  • Set an input_boolean

This input boolean could then be used as a blocker entity for the automation generated from this blueprint.

You would also need another automation that set’s this input_boolean to ‘off’ whenever you want the blueprint automation to be used again.

Then the automation will be ‘disabled’ whenever you used your physical switch.

You are right. Before this blueprint, I have 4 automations to make this work. With this blueprint I still need another 2 as you said. I wish to have all in one blueprint but I can see it’s difficult. Thanks for the very helpful blueprint.

I got problem with before and after times as someone mentioned above. My setup is as enclosed screenshot but the automation will not fire. It’s now 20:00.


image

@freakshock This looks really nice!. Just what i was looking for. I’m only running into a 2 problems:

  • The ‘Turn off wait time’ isn’t working for me. When the motion sensor stops detecting it turns the light off immidiatly. The value was set to: 5

  • Illuminance cutoff is set to 40. At the moment my kitchen sensor is showing 2,0lx but somehow it is not triggered. If i remove the value 40 the light turns on.

Can you pls explain me what i’m doing wrong here?

I have the same issue.

Have you created helper entities that hold the value and refered to it in the automation? It is not possible to enter a number directly into the automation.

1 Like

Thanks for the reply!.

Yeah. I’ve created 2 seperate input_numbers. I’ve done this withing the helpers section and gave it values from 0 to 14 for light illuminance. But nothing happens


Alright; so i found out it has to be something else.
I’ve changed the LX from 0-14 to 14-250 and now it’s working.

I was thinking the value for turning it on needed to be in that range but it needs to be outside. So if you want to turn it on at 0-14 lx you need to exclude that from the range… Oops…

Great Blueprint, thank you for this! I have one issue here: as soon as I enter any value in the “Illuminance cutoff value” field inside the blueprint it stops working regardless how low I set the cutoff value.
Maybe I misunderstood how to configure it?

Please read the first post again, you need to define some helper input_number entities to use in the blueprint instead of entering values directly in the blueprint for the illuminance cutoff value.

2 Likes

I can confirm that this fixed my issues. Works really well now that the helpers are added. Sorry am new to HA. Thanks for your help.

1 Like

Hello all, I have this automation running fine for about 2 months but 2 nights ago I noticed it was not working anymore.
Bellow is the log I see every time the sensor detects anything\

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 359, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 559, in _async_call_service_step
    await service_task
  File "/usr/src/homeassistant/homeassistant/core.py", line 1480, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1515, in _execute_service
    await handler.job.target(service_call)
  File "/usr/src/homeassistant/homeassistant/components/homeassistant/__init__.py", line 112, in async_handle_turn_service
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/core.py", line 1480, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1515, in _execute_service
    await handler.job.target(service_call)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 206, in handle_service
    await self.hass.helpers.service.entity_service_call(
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 649, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 692, in async_request_call
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 686, in _handle_entity_call
    await result
  File "/usr/src/homeassistant/homeassistant/components/light/__init__.py", line 272, in async_handle_light_on_service
    supported_color_modes = light.supported_color_modes
AttributeError: 'EWeLinkToggle' object has no attribute 'supported_color_modes'

any help please?

I think your issue is not with this blueprint, but with your specific light integration.

I googled a bit and found this.