TubeSum ← Transcribe a video

Home Assistant 101: Creating Your First Automations

Transcribed Jun 13, 2026 Watch on YouTube ↗
Beginner 12 min read For: New Home Assistant users who have set up a dashboard and devices but want to start automating.
21.2K
Views
557
Likes
42
Comments
12
Dislikes
2.8%
📈 Moderate

AI Summary

This video covers Home Assistant automation basics, including the building blocks of an automation (triggers, conditions, actions) and step-by-step processes for creating, testing, editing, and troubleshooting automations. The presenter demonstrates creating a motion-activated light automation and shows how to improve it with delays, conditions, and timer helpers.

[00:00]
Introduction to Home Assistant Automation

The video covers automation basics: triggers, conditions, and actions. It compares Home Assistant to other platforms like Alexa (routines), IFTTT (applets), and Google Home (automations).

[01:30]
Parts of an Automation

All automations have a trigger (the 'if' part), optional conditions (additional criteria), and actions (the 'then' part). Conditions can be combined with AND/OR logic.

[03:00]
Why Home Assistant for Automations

Home Assistant supports over 1,300 integrations, local devices, and a powerful automation engine. It allows complex automations with multiple triggers, branching, and YAML mode.

[05:00]
Creating a Basic Motion-Activated Light Automation

Step-by-step: create a new blank automation, add a trigger (motion detected), add an action (turn on light). Save and test.

[07:30]
Creating a Second Automation to Turn Off Light

Create a second automation with trigger 'motion clears' and action 'turn off light'. Test shows light turns off immediately after motion clears.

[09:00]
Improving with Delay and Mode

Add a 'for' clause to the trigger to wait 10 seconds after motion clears. Change mode to 'restart' so the timer resets on each new motion detection.

[11:00]
Using a Timer Helper

Create a timer helper (10 seconds). Modify the 'turn on' automation to also start the timer. Modify the 'turn off' automation to trigger on timer finished event.

[13:00]
Adding Conditions (Sun and Light Level)

Add condition 'sun below horizon' to prevent daytime activation. Use a light level sensor with OR logic to allow activation when room is dark even during daytime.

[15:00]
YAML and Troubleshooting

View YAML of automations via the UI editor. Use traces to debug failed automations. Check entity states in Developer Tools.

Home Assistant provides a powerful and flexible automation engine. By understanding triggers, conditions, actions, and using tools like timers and traces, you can create reliable automations that improve your home's convenience and efficiency.

Clickbait Check

95% Legit

"Title accurately describes the content: a beginner's guide to creating first automations in Home Assistant."

Mentioned in this Video

Tutorial Checklist

1 05:00 Go to Settings > Automations & Scenes > Create Automation > Create New Blank Automation.
2 05:30 Add a trigger: select device or entity, choose motion sensor, set to 'detected'.
3 06:30 Add an action: select device or entity, choose light/switch, set to 'turn on'.
4 07:00 Save the automation and test by triggering motion.
5 07:30 Create a second automation with trigger 'motion clears' and action 'turn off'.
6 09:00 Edit the turn-off automation: add 'for' clause (e.g., 10 seconds) to the trigger.
7 10:00 Change automation mode to 'restart' via three-dot menu.
8 11:00 Create a timer helper: Settings > Devices & Services > Helpers > Create Helper > Timer. Set duration (e.g., 10 seconds).
9 11:30 Edit the turn-on automation: add action 'Start timer' with the created timer.
10 12:00 Edit the turn-off automation: change trigger to event 'timer.finished' with entity ID of the timer.
11 13:00 Add condition to turn-on automation: add condition 'Sun below horizon' or use light level sensor with OR logic.

Study Flashcards (8)

What are the three main parts of an automation in Home Assistant?

easy Click to reveal answer

Trigger, conditions, and actions.

01:30

What is the difference between 'single' and 'restart' mode in automations?

medium Click to reveal answer

In single mode, if triggered again while running, the second run is canceled. In restart mode, the first run is canceled and the second run continues.

10:00

How do you add a delay before an action executes after a trigger?

medium Click to reveal answer

Use the 'for' clause in the trigger settings to specify a duration that the trigger state must persist.

09:00

What is a timer helper and how can it be used in automations?

medium Click to reveal answer

A timer helper is a countdown timer that can be started, stopped, and used as a trigger. It can be used to delay actions and can be shared across multiple automations.

11:00

How do you combine multiple conditions with OR logic in Home Assistant?

hard Click to reveal answer

Add a building block (OR) and drag the conditions into it so that any one condition being true will allow the actions to run.

14:00

What is the default mode for new automations in Home Assistant?

easy Click to reveal answer

Single mode.

10:00

How can you view the YAML code of an automation created via the UI?

easy Click to reveal answer

Click the three dots on the automation and select 'Edit in YAML'.

15:00

What tool in Home Assistant helps debug why an automation failed?

medium Click to reveal answer

Traces, accessed from the three-dot menu on the automation.

16:00

💡 Key Takeaways

💡

Home Assistant's Power

The presenter states Home Assistant has the most powerful automation engine, setting high expectations for the platform.

03:00

Light Turns Off Too Quickly

Demonstrates a common real-world problem: motion sensor lights turning off when someone sits still.

08:00
💡

Using OR Logic for Conditions

Shows how to combine sun position and light level sensor with OR logic, solving a practical automation challenge.

14:00

✂️ Creator Tools: Viral Hooks

AI-generated clip ideas for Shorts based on the transcript

No viral clips found for this video, or they are still being generated.

You might already have a number of smart devices around your home. And maybe you control these devices via apps on your phone or by yelling different random commands at a smart speaker until something happens. But is your home automated? Can it take action on its own and respond to events or even anticipate your needs without any interaction on your part? Today, I'll cover Home Assistant automation basics, including the building blocks of an automation and the step-by-step

processes of creating, testing, editing, and troubleshooting automations in your own home. [Music] Hi, and welcome to Resin Chem Tech. If you're a new Home Assistant user, you might have gotten to the point where you've created a dashboard, maybe added a few devices so you can control them throughout your home. But maybe you'd like to automate some of these tasks, but don't know where to begin. In this video, I'm going to cover how to create your very

first Home Assistant automation, and then show you some troubleshooting steps and a few best practices along the way. As always, be sure to check the video description for links to additional information I just don't have time to cover in this video. But let's get started by taking a look at the primary parts of an automation. You might have created a few automations before, although different systems may use different terminology. Amazon Alexa calls automations routines. The online

service if this then that calls them applets and Google Home does refer to them as automations like Home Assistant. Now, even though these various systems use different terminology, there are many things that all automations have in common. First, all automations have a trigger. The trigger is the event or condition that occurs to start the automation process. They are kind of like the if or the when part and this can be practically anything that the system supports

and can monitor. It can be an event like sunset based on some value of a sensor or even something like another automation. Think of the trigger as the on switch that starts the automation, but that switch is turned on by some other action or event. The next part of an automation are the optional conditions. Now, not all systems offer conditions. And the type of conditions may be limited, but conditions are additional criteria that must be met

before the rest of the automation will execute. For example, if we have a trigger that says when motion is detected, additional criteria can be added saying and if the sun is set and or if it is after 9:00 p.m. and or if the overhead lights in the room are off. Now, I was saying and or because most advanced automation systems allow you to combine multiple conditions in various configurations. For example, I can combine two conditions with

and, where all conditions must be met. Two or more conditions can also be combined with or, meaning the automation will run if either of the conditions are true. And and or can even be mixed and matched. So you can build build very precise conditions. So the automation will only execute if those conditions are met. The final part of an automation are the actions. Now, actions are the steps or tasks that will be performed once the automation

has triggered and any conditions, if specified, are met. Some very simple examples of actions include things like turning on a light, sending a mobile notification to your phone, or maybe making a voice announcement over a smart speaker. The more advanced automation systems may not only allow you to specify multiple actions, but combine those in unique ways, like applying additional conditions to certain actions. So, those are the basic terms you'll encounter when creating automations using just about

any platform. But now, let's focus on Home Assistant and why it might be the best platform for building your own automated home. So, if you already have a smart speaker like one from Amazon or Google, why would you want to use Home Assistant for your automations? Well, in my opinion, Home Assistant arguably has the most powerful and flexible automation engine of any system currently available. Now, Node Red might be close, but if you prefer Node Red's

visual designer, you can also integrate Node Red with Home Assistant and still realize all of Home Assistant's advantages, some of which include the fact that Home Assistant currently supports over 1,300 different integrations with more added each month. This includes everything from cloud-based Wi-Fi devices to local Ziggby, Z-Wave, Matter devices, and more. Now, other platforms such as smart speakers can only integrate with approved devices and even then only certain devices or events are made available to use

in automations. And if you can't find an official integration for Home Assistant, there are hundreds if not thousands more available via the Home Assistant community store. And if you can integrate a device into Home Assistant, you can use it in your automations. other systems. Even if it allows an entity to be used as a trigger, it may not allow that same entity to be used in conditions or actions. Home Assistant also offers a number of local

helpers or entities like text or numeric fields, timers counters toggles buttons and more that can be used in various parts of your automation. Home Assistant also offers the ability to create very complex automations with multiple triggers, branching, action specific conditions, and more. And while you can do almost everything via the UI automation editor, even more complex automations can be created in YAML mode where you write your own code blocks for the automation. Now, since this is

a beginner video, I won't be going in depth of some of these advanced options, but just know that if you have an automation idea, it is highly likely there's a way to implement it in Home Assistant. But enough about the terms and parts of an automation. Let's take a look at how to actually create a basic automation in Home Assistant. As an example, let's create a simple common automation controlling a light based on motion. Now, as

a starting point, we'll need the following automations. One, when motion is detected, turn on a light. And two, when motion clears, turn off the light. So, let's create these two basic automations, test them, and see if we need to make any changes or improvements. Obviously, to control a light based on motion, we need a couple of devices that are integrated in a home assistant. Here I have an AAR motion detector which integrates into Home Assistant via

ZigGB. And I also have a simple light which is plugged into a BNL link smart plug which has been flashed with TAS mode and integrates into Home Assistant via MQTT. In my case, this is simply called BNLink01 in Home Assistant. This also means that both of my devices run locally on the network without any cloud service. Now, we can certainly use cloud-based devices as long as there is an integration for that cloud service and home assistant.

But I'll talk about local versus cloud devices in a bit and why the difference can be very important in some automation situations. But for this example, we simply want the light to turn on when motion is detected and turn back off again when motion clears. Create that first automation over here in Home Assistant. We're going to go to our settings. We're going to go to automations and scenes. Automations ought to be selected by default here at

the top. Now, obviously, I have a lot of automations already. You may or may not already have automations in your home assistant, but regardless, we're going to create a new automation by clicking this button in the bottom right hand corner. And first off, notice right here we have something called motion activated light. These are called blueprints, and they're pre-made automations where you just fill in the blanks. I could actually select this, just select my motion sensor

and my light, and be done. the blueprint would create the automation for me. We're not going to use the blueprints here because at some point in time you will need to create an automation that there isn't an available blueprint for. So you need to learn how to create it from scratch. So that's what we'll do here. So go back to create an automation and we're going to create a new blank automation. Follow that. The first part

of any automation is the trigger and that's what kicks off your automation. That's the win part. So remember we said for this first automation when motion is detected then turn on the light. So the when is when motion is detected. So we're going to go ahead and add a trigger. Now we have a couple of options here. We have device and entity. If you happen to have a device defined in Home Assistant, which is a well,

it's a device, but it might have multiple entities as being a standalone entity. I'm going to show both methods. Let's select device first. And now from this drop-own list, we can select a device. There's my Aara motion detector that's integrated again via Ziggby. So I can select that. Then for the actual trigger, it's going to show me all the available events for this particular device. And in this case, we want to say when it starts detecting

motion. So we will select that for the actual trigger. If we want, we could specify a duration here. Say that motion has to be detected for at least 30 seconds or 5 seconds. We want it to happen right away. So we will leave the duration blank. That would be using the device method. But let's go back. Let's go ahead and delete this trigger out. And let's go back and do it by entity. So in this case,

we're going to select entity instead of device. And we want to trigger when the state of this entity changes. So we'll select state. Now I can select my entity. Again, I can simply search. And there's my car motion detector. So we will select that. I can select multiple entities because like I mentioned earlier, you could have multiple triggers, but for this simple one, we're just going to have a single trigger. and we want to say when

that a car emo motion goes to detected. So that's all there is to creating our trigger. I'm going to go ahead and collapse this section to make it a little easier to see. But notice up here it does still tell me that my trigger is when a car emotion changes to detected. Do note that if you like you can actually come in here and you can give that trigger a different name. I'll just leave it as

the default. But our next section is our and if or our conditions. If we wanted to add conditions beyond when motion was detected, we could add those here. For now, we're not going to add any conditions, we will come back and take a look at these in a minute. But the last step is our then do or action. Remember from our when motion is detected, then turn on the light. So our action here is going to

be actually turn on that light. So we're going to add an action and it's going to give us a bunch of different things. Again, devices, buttons, cameras. Here is light. But in my particular case, remember that that light bulb is plugged into that BN link smart plug. Well, that smart plug is actually a switch. So, we're going to come down here to find our switches and we want to turn on that switch when our motion is

detected. So, again, I have device and entities, but in this case, that BN link is not its own device. It is only an entity. So, we're going to select that. And I can simply look up BN link. And there it is, our plug. That's our switch. So, we will turn that on. And that's really at this point the only thing we need for this automation. So, let's save this and give it a try. With that automation

saved, we're ready to give it a try. And I've created a a simple little dashboard here in Home Assistant, thrown it up there in the corner just so you can see the state of the entities. But here's my motion detector. I'm going to move in front of it. And you can see that it detected motion and the light came on. So, that worked great. But now you can see that when motion cleared, the light stayed on.

That's because our automation doesn't it's only going to turn the light on when motion is detected. That means we need to create a second automation to turn the light back off when that motion clears. So back over here in Home Assistant, we're going to create another new automation. And this is going to be almost identical to the last one. The only thing we're going to do is we're going to change the states of these entities. So

in this particular case, we're going to once again select our car motion sensor. In this case, we want it to change to clear. This means when it goes back to clear, and in fact, I can include a a detected in here as well. So now when it goes from detected to clear, and again, for right now, we're going to leave the time blank, but then no conditions. But we're going to go back down here and add

an action. We're going to go back to that switch and we're going to say turn off that switch. And that particular switch entity once again is our BN link plug. And again, all we've got to do is save that and it'll create our second automation. With that second automation saved, let's give this a shot now. So, someone walks into the room, motion is detected, the light comes back on. They leave the room, motion clears, the light

turns back off. All that looks good, but there might be a few issues with this automation as written. For one thing, if someone comes into the room and then they hold perfectly still or they don't move, I twist it a little bit there. But if I hold still, notice how that went back off again. Now, as soon as I move and it detects motion, the light's going to come back on. Now, this might be fine for

something like a pantry or a closet, but probably isn't going to work in a larger room. If someone goes into the room, sits down in a chair, and hold still, the lights are going to turn back off on them. In addition, it might be a large enough room that someone could come into the room, leave the motion sensor area, and the lights turn back off before they actually have a chance to exit the room. So, let's

see if we can make some improvements to this basic automation. Of course, one way to improve this automation would be to simply use a different device here. I could use something like a presence detector that would be able to detect someone even if they're sitting still. And of course, different motion detectors have different cooldown periods. If you watch this one, notice when I move away, it takes about 3 seconds a before the motion clears. And this

is configurable in this particular sensor. But we could use motion sensors that have longer cool down periods or before they switch back to cleared state after motion is detected. But we're going to go ahead and keep these same devices and see what kind of improvements we can make in the automations themselves. Before we take a look at ways to improve this automation, I mentioned cloud versus local devices. While not directly related to automations, a cloud-based device

means that at any point in time, the manufacturer could shut down their cloud service, reducing your device to a doors stop or e-waste, as was recently announced by all Belelcon and Weimo devices slated to end in January of 2026. And there's a long list of other cloud-based manufacturers that have either shut down their services or pulled a quick bait and switch and started charging a monthly subscription to continue to use those services when it was previously

free. When your device is local, it can never be shut down, modified, or changed by a third party. And they can never pull a bait and switch and suddenly start charging you for something that was free before. But even more importantly, local devices and automations will always be faster than anything that's cloud-based. In a previous video, I did a comparison of devices running locally in Home Assistant versus using the manufacturers app and their cloud component. Now,

I ran this test multiple times and also compared different devices from different manufacturers, which means different cloud services as well. But as you can see from my test results, the local method triggered in less than 1 second in every case, while the cloud services took anywhere from about 3 seconds to more than 6 seconds to respond. Now, for some automations, a few second delay might not be an issue. But for something like a motion controlled light,

walking into a room and then having to wait 3 to 5 seconds or even longer for the lights to come on probably won't be the best experience. Since most my devices are local, this won't be an issue. But there are still some improvements we can make to the original automations. First, let's try to improve upon the situation where those lights turn off too quickly after motion clears. And to do that, we're going to go back into

that second automation that we created, the one that turns the lights back off. And we're going to come in here and edit it. Up here in the actual trigger, remember this four clause? We can set a time in here that says that the motion detection must be clear for a certain amount of time before our actions, which are going to turn off the light, will trigger. I can put any time in here I want. For the

purpose of this demonstration, I'm just going to put in 10 seconds. And we will save our updated automation. Okay, with that modification made, let's try this again. We can see that motion is detected. But if you watch up there, if you remember before when motion cleared, the light turned off right away. Now the light is remaining on. It's going to remain on for that 10 seconds as long as motion isn't detected again before that light turns

off. Now again, you can make that length of time any amount that you want. It could be 1 minute, it could be 30 minutes, however long you want that to be. But there is one other thing to consider here. What happens if motion is detected and our motion clears? But while we're still waiting for that light to come off, if motion gets detected and gets cleared a second time, what happens the second time that same automation

tries to execute? Back over here in our automation editor, if we go back up to these three dots, we'll see an option to change mode. The mode determines what happens if multiple instances of the same automation try to run simultaneously. And if we look at that, we see we have four options. Single, restart, cued, and parallel. What exactly does that mean? In single mode, which is the default for all new automations, if we have an automation

that's running and maybe it's in a delay or a wait state, and then that trigger fires for a second run. Well, in this case for single, what happens is that second run is just canceled or doesn't run. It logs a warning and our first instance continues to run as normal. This is probably the most common for automations, which is why it is the default. But there are other situations where you might want a different mode. In

restart mode, we have the same situation. An automation has started, but it hasn't yet completed, and that same automation gets triggered again. But in the case of a restart, that first run is actually cancelled, and then the second run continues until it completes. So in the single mode, the second run got cancelled and the first run continued. In restart mode, the first run gets canceled and the second run continues. If the mode is cued, then what

happens is if we have an automation that's already running and a trigger fires again, in this case, it's simply going to ceue up that and wait for the first run to complete. And then after that completes, the second run will complete. And you can continue to queue these up for as many as you want or whatever queue length you specify over here. And in this case, it's only going to allow a maximum of 10 instances of

this automation to be queued up and run. And this makes no sense for something like a motion controlled light. But you may have certain automations where you want every trigger to be executed, but in this case, they'll execute one after the other as each prior automation completes. And the final option is parallel, which is similar to cued, but in ceued each subsequent run of the automation waits for the prior one to complete. In this particular case,

multiple instances actually run in parallel at the same time as each other. Using parallel is pretty rare and you can get some unexpected behavior if you don't use it carefully. But there are particular situations where parallel might make sense for your automation. Doesn't make any sense for again a motion controlled light. For this particular automation, I'm going to set it to restart because what I want to happen is every time motion is detected, I want to

restart this 10-second counter. So, as long as motion is still being detected, that light should remain on until no motion has been detected for at least 10 seconds. So, I've added a timer up here so we can see what happens with this restart method. So, in this particular case, if motion is detected, once again, the light comes on. You can see that the timer is currently active. But when that runs down at 10 seconds has elapsed,

well, that's when it turns the light off. But now, let's say that that light turns on and again, we're still in that delay period. Motion's not been detected and gets detected again. Well, look what happened to the timer. It's a little bit hard to see, but every time I do that, that timer goes back and restarts that 10 seconds. And as long as I keep maintaining motion, that light will never go off because that timer will

never hit zero. However, if I do let that timer go all the way down to zero with no additional motion, what's going to happen is the light then actually gets turned off. Now, in actuality, this particular automation would have worked the same way even if I had left the mode to single because of the way that that four clause works when it didn't maintain that state for at least 10 seconds. What really happened was that automation

failed, but it restarted. So really restarting that timer is going to work the same for single or restart in terms of the mode for this automation, but that won't be the case for every automation that you create. Now, an alternate method and probably a better way to add in delays like this, especially if they're longer delays, is to use a timer helper. And to be honest, that's kind of what I've did here to to cheat to

show those timers up there. But instead of turning the light off based on when motion clears, we will start a timer. And we'll turn that light off when that timer expires instead of when motion clears. It's pretty easy to do, but the first thing we need to do is we need to create a timer helper. Create a timer helper. We go back to our settings, but this time we go to devices and services, and we can

see helpers in a tab here at the top. Once again, we're going to go down here and create a new helper. You scroll down, see all the different types of helpers are available. In this case, we want a timer. I'm just going to call mine desk light timer. And I can set a default time here, but I can also override that when I actually use this in an automation or script. But since we're looking at 10

seconds, I'm going to go ahead and set the default to 10 seconds. This says whether I want this timer to be reset when Home Assistant starts. In this case, I don't. So, I'm just going to go ahead and create this timer. Make use of that timer, we have to tell it when to start. And to do that, we'll go back to our automation that turns our light on when motion is detected. We're simply going to add

an additional action to this. So, when motion is detected, it's going to turn on the light. And then we're going to come down here. We're going to find our timer option, which is right here at the bottom. And then we're going to actually start that timer. So, now I will choose my timer. There it is right there. And again, I do have an option to override the duration, but this already has a 10-second duration set on

it, which is what I want to keep for this video. So, I will go ahead and save this. Then, when our automation fires and it turns on the light, it will also start this 10-second timer. But, of course, I also need to modify the automation so that the light turns off based on the timer instead of when motion clears off of the sensor. And to do that, we're going to go back over to the automation and

actually turn the lights off when that motion changed from detected to clear for 10 seconds. But we want to use a different trigger here. We want to use the trigger for when that timer runs out. So I'm going to just come in here. I'm going to delete this trigger. And I'm going to add a new trigger. Now, in this particular case, timer when it expires is considered an event. So we're going to go ahead and put

that in there. And this is a little bit more advanced, but I'll leave a link down to the timer events down in the video description. But in this case, the event is going to be timer finished. And the actual entity ID is going to be that desk lamp. So that's all we've got to do to change this automation to use a timer to turn off the light instead of when motion clears off the motion sensor. Now

you can see this automation is going to work just like it did before. The only difference here is that the turnoff automation isn't being triggered by the motion detector going off, but instead of when that countdown timer runs out. And again, if the motion is triggered and that timer is counting down and motion gets triggered again, notice that that timer restarts. And the nice thing about using a timer as opposed to a four clause in your

automation is the fact I could use this timer in other automations as well. So, for example, maybe if someone opens a door, I could cancel or reset that timer and stop the light from being turned off. And speaking of alternate triggers, obviously you could control a light with things other than just a motion detector. For example, you could use something like a door or window sensor and turn that light on whenever the door is open and

turn it back off again when the door is closed. This is a great idea for things like closets or pantries where family members might tend to leave the light on. You could do something like use a distance sensor and you could turn that light on when an object is within a particular range and turn it back off when that object's no longer within range. I could use something as simple as time of day. I could say

turn a light on at 8:00 p.m. And then I could create another automation to turn the light back off again, say at 6:00 a.m. I can even do something as crazy as like a temperature and humidity sensor. In this case, notice I've got two triggers. Say when the basement temperature is above 72 or the basement humidity is above 50% I would then run the actions in this case turn on a light. Do note that when you

have multiple triggers defined the actions will run when any one of those triggers evaluates to true. And of course we can do additional things in our actions other than just turning devices like lights off and on. And remember you can have multiple actions as part of an automation. You can do things like send a mobile notification, and this works with most Android and Apple devices. You can also do things like make a voice announcement over one

of your smart speakers. The garage lights have been on for 30 minutes. >> So, just realize you aren't limited to just doing a single action or things like turning a device off and on. And we've talked about triggers and we've talked about actions. We really haven't talked about conditions. So, let's go back to our original automation and see if we can make some additional improvements by using conditions. So, back on our original automation, let's assume for

a minute that we've installed this motion detector in this light in a room that has a lot of windows, so it's pretty bright during the day. And we really don't need this light to turn on automatically with motion during the daytime. We only want it to turn on during the night. Well, we can easily modify our automation and add a condition to check for that before we turn the light on. Hey, I'm back here on my

original automation which just turns on the light when motion is detected. But now we're going to add a condition in here. And remember, conditions must also be true or be met before the actions will run. So we're going to add a condition. Now I would have an option here just to specify a time and then the automation actions would only run after or before a certain time. But if I wanted to base this on how bright

the room might be, at least here in Indiana, there can be a wide difference between summer and winter in terms of when the room is going to get dark. Could be up to a 4hour difference between sunset times. So I would constantly have to be adjusting this time if I based it on time. Instead, let's base this on an entity and the state of an entity. But for that entity, we're actually going to use the sun.

And with that sun, I have an option to choose whether the sun is above or below the horizon. If I select below the horizon here now, the sun must have set and not have risen yet before these actions will fire. So really, it will only run when it's dark out. If it's actually not quite dark enough for me when the sun actually sets, I can actually again add a four here. If I put in 30 minutes,

now this will only run after the sun has set for at least 30 minutes. So now with that new condition added, you can see that motion is detected, but notice that the light didn't come on. In addition, the timer didn't start since it's an action as well. So none of the actions run even though the trigger fires. Now, if I were to wait until the sun went down a few hours from now and to run this

again when motion was detected, it would pass the condition that the sun is below the horizon and would then turn the light on. But let's take these conditions one step further. What happens if this is in a room and even though there are a lot of windows, let's say it's a dark, dreary winter day outside and the room is still fairly dark and you would like the light to come on even though the sun is up.

Well, we can add something like a light level sensor to our project and be able to control this light based on the actual light level in the room in addition to the sun position. For this test and to get the light level, I'm going to be using this little digital light level sensor. And I'm currently using this in my garage to control my overhead lighting in the garage. If you want to know more about the multi

sensor that I built and how I use that to control the lights, you can check out this video after this one. But just know for right now that I can set a light level with this potentiometer. And anytime the light is below that level, like when the lights are out, this will return on or true. And anytime the light level is above that, like when the lights are on, then the sensor is going to return off

or false. Once again, back over here in our automation, we see we still have our sun condition, but now we need to add an additional condition for that light level. So, I'm going to add a condition going to be an entity, the state of that entity. And now I can search for there's my digital light level. And I want a state to be on. Remember, that's when it's below a certain light level. I can go ahead

and I can add this condition and save it and see what happens. Okay, back over here in our little test situation. Currently the garage is dark. So therefore that light level sensor is on which should match our condition. So if I do this we see we get motion but the light still didn't turn on. Why not? Well it's still currently daytime and the sun is above the horizon. Back over here in our automation by default if

there are multiple conditions defined those are all combined with an and meaning all of the conditions must pass before the actions will run. That's not really what we want here because the sun is still above the horizon, but the room is so dark, we want the light to come on. In that case, we need our conditions to be combined with an or instead of an and. And that's pretty easy to do, and that's what these building

blocks are for. So, I'm going to add a building block. And I'm going to select or because I want my actions to run if either one of these conditions are true. So, we'll put ore in there. And all I've got to do now is take these conditions and drag them down here to our block so that they are combined with or instead of and. Now you can see on here it automatically states that if any of

these two conditions match, the sun is below the horizon or the digital light level is on, then our actions will run. Let me go ahead and save that. So now let's test the automation again. The sun is still up. is still above the horizon, but the garage is currently dark, so that light level sensor is on. Now, when we detect motion, the light comes on as expected. Now, I'll turn the garage lights on. So, the light

level is high enough that that digital light level sensor is off. And once again, I get motion, but the light doesn't turn on. So, you have a lot of flexibility with how you use conditions and whether you combine them with and or or. And you can get complex and even do ands and ors in the same set of conditions, but allows you to precisely control your automations and when they fire and when they don't. A couple

more quick things before I bring this video to a close. I did mention YAML before for more advanced automations. Since this is a beginner video, I'm not going to go into a lot of depth in terms of YAML, but you may run into situations where you're going to have to start writing small code blocks of YAML. A good way to start getting familiar with YAML is you can take any of your automations created through the UI

editor here. And because they actually create YAML for you in the background, we can look to that by going to these three dots and say edit and YAML. And there is the actual YAML for this automation that we're currently running. And you can simply go back to the visual editor by clicking those three dots again. In addition, if you go over to your file editor, browse to and open the automations.yaml YAML file. This is where all

of your automations from the UI editor get saved. So you can also look through this and start becoming familiar with YAML. Now do note that it's recommended you don't actually make any changes here in this file. If you created the automation with the UI editor, you should use the UI editor to edit that automation as well. And finally, if you have an automation just isn't working the way you want it to, there are some built-in debugging

and diagnostic tools you can use right here in Home Assistant to help you. For example, if I go into my automations and scenes and I find my automation that isn't working the way that I want it to, I can come over to these dots and I can choose traces. Traces allow us to look at particular runs of an automation and figure out exactly what is going on. So, if I pull up this one for example, I

can see that my automation failed on this step and it's because my sun below horizon condition was false. In addition, looking at the states under developers tools will allow you to make sure that all of your entities are behaving as expected. So, this is my binary sensor. If I move my hand in front of it, I ought to see it change to on and back off again. Need to make sure that all of your entities involved

in an automation are working correctly or the automation won't work right. Now, if you want to know more about troubleshooting your automations, I do have a separate video on just that topic. It is a bit dated, but a lot of the same concepts and steps apply to help you troubleshoot and resolve any issues you're having with your automations. I've only touched on the very basics of creating Home Assistant automations in this video. But if you're interested,

I have a whole series of Home Assistant 101 videos, and a lot of those I show additional examples of how to create and use automations. And if you still can't figure out an automation, there are a lot of folks like myself that are more than happy to try to help you out. And you can find us in places like the Home Assistant forum, Reddit, or Discord. Just don't be afraid to ask. I'll be back soon with

more videos on Home Assistant, DIY electronics, and LED projects. But until that time, I'd like to say thank you for watching, and I hope to see you again soon.

⚡ Saved you time reading this? Transcribe any YouTube video for free — no signup needed.