Hi, I don’t know why I am having so much trouble with this, but I am trying to build an automation that when my Aqara motion sensor is triggered and it is dark, it turns an Aqara smart switch on. Then, once the sensor hasn’t sensed motion for 5 minutes, it turns the smart switch back off.
I have tried several different setups, but nothing seems to work. Does anyone have one built like this yet that you would be willing to share?
One question - instead of using the sun below horizon condition, I would prefer to use the light sensor and set the condition for when the LUX level is 0. That way, the night light only comes on when all other lights are off. Just not sure how to correctly implement this - everything I have tried doesn’t work.
Can I ask you one other question? I have another automation set that when my front porch lights are on (they come on at dusk through my Caseta hub) and I unlock the front door lock, the entryway lights turn on. I would like to put a condition that only turns the front entry lights on when the porch lights are on AND all downstairs lights are off. I don’t have any idea how to use all downstairs lights off as a condition. Do I just have to list each one with an AND?
alias: Front Entry Light on when door unlocked
description: ''
trigger:
- platform: device
device_id: 8f42afe329a0f0739acba765f6ddd1f2
domain: lock
entity_id: lock.front_door
type: unlocked
condition:
- condition: device
type: is_on
device_id: c08e0f19918bf4d855c35a74e46416eb
entity_id: switch.exterior_porch_lights
domain: switch
action:
- type: turn_on
device_id: 4bf2dbcce8d891b846ef60cee5e5328e
entity_id: switch.front_entryway_main_lights
domain: switch
mode: single
In YAML, a list is denoted by a leading -. Look at @tom_l’s first example: the two separate automations are items in the list, both starting with - alias:.
You need to add - alias: some description at the start of your second automation, in the line before the trigger.
As it stands, you have one automation with two triggers, which is causing the error.
That also applies if you want multiple conditions. Your request for all lights to be off can be written like this (docs), and I’ve added the sun condition back in as an example to show the format:
condition:
- condition: state
entity_id:
- light.first
- light.second
state: 'off'
- condition: state
entity_id: sun.sun
state: "below_horizon"
The automation documentation is extensive and high-quality. Please take some time to read it carefully.
@Troon - yup, that did it! When I was modifying, I accidentally got rid of that second alias. Thank you!!!
@tom_l - ah, yeah - that makes the most sense. I will give that a try and will let you know if I run into any issues.
Thank you so much - this was extremely helpful. I am trying to get comfortable with building these automations…then I think I will need to go through and assign better entity names to my devices and start to break off my automation YAML to make it a bit easier to nagivate.
Ah, ok, that makes sense now. And that is good to know for the switch I am using as a nightlight in the bathroom. I will go and add all those to the config.
Last question for the night, I promise!!
Adding the group as a condition - not exactly sure of the syntax. Am I close here?
- condition: group
type: is_off
entity_id: group.downstairs_lights
domain: group
Invalid config for [light.group]: Entity ID 'switch.playroom_light' does not belong to domain 'light' for dictionary value @ data['entities']. Got ['light.dining_room_ceiling_lights', 'light.family_room_main_lights', 'switch.playroom_light', 'switch.kitchen_main_lights']. (See ?, line ?).
I assume I’m just doing something wrong, but I don’t know what.
- platform: group
name: Downstairs Lights
entities:
- light.dining_room_ceiling_lights
- light.family_room_main_lights
- switch.playroom_light ## These two need to be lights. You made the lights above.
- switch.kitchen_main_lights ##
Hey @tom_l - I am adapting this automation (turning on the entryway lights when the front door is unlocked) to turning on my kitchen light when the MyQ garage door is open.
The part I am not clear on is how to determine which device to use (in this case, the garage door is cover.garage_door and the MyQ Gateway is a binary sensor. So in this case, how would you know which entity is the correct one to use?
And once you do figure out which entity, how do you find the states (or type) the entity uses to know which to use?
That makes sense. Thank you! I will give it a try.
If I am looking up states in the Dev Tools states menu, if I want to check the other states, do I just have to put the device in another state and see how it is being reported in the States menu?