I am very new to HA and still learning. I have some kitchen cabinet lights which are controlled by a shelly rgbw switch. I also have an Aqara presense sensor. At the moment I have it set so if there is motion in front of the kitchen ( sensor can’t see into the kitchen so I can’t use it after the person is out of sight ) and it is between 8:30pm and 7:00am, then the lights turn on. After 30 seconds the lights automatically turn off.
What I am trying to do is have this automation not run if the light switch for the cabinet lights has been manually turned on. I have no clue how to go about doing it. Adding a conditional at the start of the YAML file does not work. Any help will be appreciated.
Here is my config right now.
alias: Kitchen Cabinets on/off with motion
description: ""
trigger:
- alias: When Kitchen Area Motion Is Detected
platform: state
entity_id:
- binary_sensor.lounge_presence_sensor_kitchen
to: "on"
id: Motion Detected in Kitchen
for:
hours: 0
minutes: 0
seconds: 0
- platform: state
entity_id:
- binary_sensor.lounge_presence_sensor_kitchen
to: "off"
for:
hours: 0
minutes: 0
seconds: 30
condition:
- condition: time
after: "20:30:00"
before: "07:00:00"
action:
- if:
- condition: trigger
id:
- Motion Detected in Kitchen
then:
- service: light.turn_on
target:
entity_id: light.kitchen_cabinets
data: {}
else:
- service: light.turn_off
target:
entity_id: light.kitchen_cabinets
data: {}
mode: single
I’m sure there are multiple solution for this but what I would do
1’st create a toggle off Setting → Device & Services → helpers. Then I’d split your automation to have one for when motion changes to on and one for when it changes to off.
In the automation for on, in the primary condition section, I would add a second condition and would be a requirement for the light to be off before the automation would run. In the event the automation ran I’d have two actions, first turn the light on and second turn the helper on.
Then in the second automation that triggered when the motion state was off for 30 seconds, the condition would check to see if the helper was on, thus only run if the helper was turned on my the motion on automation. In the event the helper was on, the automation would have two actions to turn both the light and the condition off.
You should detach the shelly switch from the light.
as well as create a binary helper
Then you create an automation with 3 triggers, mode restart.
One for switch on (trigger_id: switched_on)
Second one switch off (trigger_id: switched_off)
Third trigger for motion (trigger_id: motion)
This looks like it is about to work… but isn’t working for me. The light is turning on when I activate the sensor, but upon “clearing” it, the light continues to stay on.
Shelly is not hooked up to any switch, the switch was the shelly itself ( as you suggested). I added the helper as a toggle like you said with the correct name ( kitchenlight_manual_helper ). I assume the issue is due to the helper is not turning back to “off” after the detection goes from “detected” to “clear”. Does this mean a 4th option would be required?
Sorry, I think I need to reword this as I screwed up the wording the first time and it is not clear. Here is the setup.
Shelly is hardwired into the power. There is no physical “switch” to turn Shelly ( kitchen cabinet lights ) on/off. The only way Shelly ( the kitchen cabinet lights ) can be manually turned on/off is either by asking Alexa to switch them on/off, or by clicking a button in Home Assistant.
Shelly is hooked up to RGBW strips being powered by a 24v power supply.
I just tested again and can confirm, when the presense sensor is activated, the helper turns on and will not turn off. Here is the code from the YAML file.
Then there is no way to detect that the light was switched on manually…you need a detached switch from the shelly (or any other button; could also be a zigbee or rf433 switch)
We are talking about the ‘I’ input connected to the switch (shown on top here):
That may actually be okay, since I will eventually put a tablet to control HA things like switches, etc. But that won’t be for a while. If it’s not a lot of work for you, would you be able to post up the code for it? That way I can come back to this thread when I get the tablet. It may also be helpful to others in the same situation as me.
Perfect. This approach works really nicely for me. I added in a few more conditions (sunset → sunrise) but otherwise it’s pretty much exactly what I’m looking for.
Might have to try and turn it into a Blueprint as I’ll want to do the same thing in a few places. Only issue is some are lights and others are switches, which may make the blueprint harder as I’ve not written one before. Will give me an excuse to learn!