
How to create a simple automation in Home Assistant ? How to trigger an event with a door sensor? How to automatically turn on a light? Here I will try to show you - step by step.
The topic assumes that we already have a Home Assistant set up with a paired door sensor and relay. In this case, I have used Zigbee-based solutions, but from the HA's point of view, this is not relevant. Nevertheless, in the context of battery-powered devices such as temperature sensors, door openers, window sensors, etc, I strongly recommend Zigbee. It is simpler to use and the price is not much higher than for WiFi-based solutions. I value WiFi-based solutions for the fact that after changing the firmware , a lot can be realised on them and without a central server, but in terms of battery life, Zigbee always wins in my opinion.
For the automation presented here, two devices will be used - a relay and a door-opening sensor, both controlled by Zigbee:


I assume we have already paired and connected the whole thing, and the HA can see both pieces of equipment. The relay will switch on the bulb.

Now I will show how you can create an automation based on these.
Open HA settings, go to Automations & Scenes:

A new automation is created by the "Create automation" button:

There we have ready-made scenarios or the creation of an automation from 0:

The automations consist of three sections:
- When - the main event trigger, it initiates the whole action
- And if - additional conditions that must be met for the automation to execute
- Then do - a list of operations to be performed by the HA when the automation is triggered (e.g. turning on a light)

In this particular example, in the "When" section we first select the door sensor and then select its "Opened" event, separately we have the "Closed" option and a possible event time.
In the "And if" section I didn't select anything, but here you could additionally use, for example, an occupancy sensor - if the door is closed and no one is in the room, turn off the light.
It's worth remembering that you can preview our automation in YAML format in the side menu:


It remains to fill in the action to be performed. There again, we first select the object and then the operation on it. For example, for turning off a light bulb:

Finally, we call our automation:

All done, but it is still worth mentioning side possibilities. Once the automation has been created, it can of course be edited, but also duplicated (to create a variant), enabled, disabled, forced firing (convenient for testing) as well as checking the call history:

Left to test - below is a video of two automations - turning the light on when the door is open and off when it is closed.

This is how you can do simple automation in Home Assistant . The final version of the scenarios, of course, depends on what you want to achieve, because if, for example, you open the pantry door, it does indeed make sense to switch on the light as long as it is open, but in the case of, for example, a room or a bathroom, you may need to create a more complex logic - it does not make sense to switch off the light when someone is inside.... then it would be a good idea to use the "And if" condition and link the action also with the presence sensor, or you can simply assume that the light goes off by itself after a given time or you turn it off "classically", with a button.... perhaps I will try to discuss such a more advanced mechanism in the next topic, and in the meantime I will ask - have you tried to implement some simple automation in Home Assistant, and if so, on what principle of operation? Door sensor, motion sensor or maybe something else? .
Cool? Ranking DIY Helpful post? Buy me a coffee.