Beginner needs help: I would like to create my own log file to write down what happened when via the automations. Just to have control at the beginning, if everything runs correctly.
I would like to be able to integrate this log on a dashboard. is this possible as I imagine it?
I suppose you could use a system_log.write action to write to the log, and perhaps a command line sensor to use grep and tail to pull out the last X log messages, but to meet your stated goal of keeping track of if things are working “correctly” while you are an HA beginner, I would suggest using more “out of the box” approaches.
You can use traces to inspect what happens when your automations run. You can use notify actions in the automations to alert to you problems or unexpected occurrences. You can set helpers, like toggles or texts to express changing states in the system. These helpers would then be easy to add to a dashboard.
Going this way will have a few benefits for you:
You’ll avoid going down a rabbit hole of trying to get your bespoke approach to work the way you want and get further and further away from normal approaches which will make it harder for anyone to help you along the way.
You’ll learn new Home Assistant tricks and techniques that will help you tackle new projects and challenges in the future
The documentation and the forums will be full of helpful information you can use to get where you want to go.
I write ALL my own log files, simply because it’s much easier to use than the built in options. I am willing to share the code with you, just know that you’ll need to use a couple add-ins to use to the full potential. I have added an example of the RAW data I write to one of my logs. Security Log in this case. All data is written to a txt file, and that data is the displayed in the front end, dynamicly update. All logs can [optionally] be purged overnight to reduce file sizes. Incorporating it into your existing code requires a few lines of code and is very flexible about what you can pass to the script that builds the raw data. On my system, I write to 11 different files, with data sorted by topic. For example Security, HVAC, Media, Maintenance and so on. This allows me to log as much or as little data as I need, all into one concise file by topic.
RAW Security data from today:
<br><b>[0] ================= 06/22/2025 12:00 AM =================</b>
<br><b>[1] - Reset </b><big>SECURITY LOG</big><br>--------------------------
<br><b>[2] SECURITY ACTION 06/22/2025 01:38:46.069703</b>
<br>Automation - [Log Door Lock Status]
<br>[log_door_lock_status] triggered by lock.front_door_bolt_241 called from [automation.log_door_lock_status]
<br>1 - Front Door Lock was changed to LOCKED by Manual.
<br>2 - Art Home is ON, Steff Home is ON.
<br>3 - Everyone Home is ON, Someone Home is OFF, Nobody Home is OFF.
<br>--------------------------
<br><b>[3] SECURITY ACTION 06/22/2025 06:00:00.172010</b>
<br>Script - [Set Alarm Disarmed]
<br>[set_alarm_disarmed] called from [automation.set_alarm_to_disarmed_every_morning -> script.set_alarm_disarmed]
<br>1 - Alarm changed to DISARMED.
<br>--------------------------
<br><b>[4] SECURITY ACTION 06/22/2025 06:00:00.188094</b>
<br>Automation - [Set Alarm to Disarmed every morning]
<br>[set_alarm_to_disarmed_every_morning] triggered by Time: 06:00:00 called from [automation.set_alarm_to_disarmed_every_morning]
<br>1 - Alarm changed to DISARMED.
<br>2 - Art Home is ON, Steff Home is ON.
<br>3 - Everyone Home is ON, Someone Home is OFF, Nobody Home is OFF.
<br>--------------------------
<br><b>[5] SECURITY ACTION 06/22/2025 08:45:30.473219</b>
<br>Automation - [Perimeter Door Sensor Tripped] Play Sound
<br>[automation.perimeter_door_sensor_tripped] triggered by binary_sensor.garage_entry_door_state called from [automation.perimeter_door_sensor_tripped]
<br>1 - At 06/22/2025 08:45:30: Value=38
<br>--------------------------
<br><b>[6] SECURITY ACTION 06/22/2025 08:45:38.202886</b>
<br>Automation - [Log Door Status]
<br>[log_door_status] triggered by binary_sensor.tilt_sensor_2_state called from [automation.log_door_status]
<br>1 - Garage Door 2 was changed to OPEN
<br>--------------------------
<br><b>[7] SECURITY ACTION 06/22/2025 08:45:38.213634</b>
<br>Automation - [Log Door Lock Status]
<br>[log_door_lock_status] triggered by cover.garage_door_2 called from [automation.log_door_lock_status]
<br>1 - Garage Door 2 was changed to OPEN by Manual.
<br>2 - Art Home is ON, Steff Home is ON.
<br>3 - Everyone Home is ON, Someone Home is OFF, Nobody Home is OFF.
<br>--------------------------
<br><b>[8] SECURITY ACTION 06/22/2025 08:45:43.270220</b>
<br>Automation - [Perimeter Garage Door Sensor Tripped] Play Sound
<br>[automation.garage_tilt_sensor_tripped] triggered by binary_sensor.tilt_sensor_2_state called from [automation.garage_tilt_sensor_tripped]
<br>1 - At 06/22/2025 08:45:43: Value=56
<br>--------------------------
<br><b>[9] SECURITY ACTION 06/22/2025 08:47:07.250403</b>
<br>Automation - [Perimeter Door Sensor Tripped] Play Sound
<br>[automation.perimeter_door_sensor_tripped] triggered by binary_sensor.garage_entry_door_state called from [automation.perimeter_door_sensor_tripped]
<br>1 - At 06/22/2025 08:47:07: Value=38
<br>--------------------------
<br><b>[10] SECURITY ACTION 06/22/2025 09:24:27.326091</b>
<br>Automation - [Perimeter Door Sensor Tripped] Play Sound
<br>[automation.perimeter_door_sensor_tripped] triggered by binary_sensor.garage_entry_door_state called from [automation.perimeter_door_sensor_tripped]
<br>1 - At 06/22/2025 09:24:27: Value=38
As I mentioned, it is a bit of a task to get all the parts and pieces configured, but once you understand the workflow, adding additional logs is a piece of cake.
Please send me a private message if you are interested in doing this. I will go over all the required components, steps required to set up the notify services and code blocks that need to be inserted into your existing code. The scripts and automations do all the dirty work as well as the maintenance required. You just need to be willing to invest the time and effort to put it all together.
OK. You can contact me at any time.
Before you get too deeply entrenched, I’d like to offer some advice I learned the hard way. All of these tips can be researched right here if you need more info.
Develop a meaningful and consistent naming strategy. Entity names should make sense to you. Avoid using device_id as much as possible. It is MUCH more difficult to troubleshoot later. See two snippets of code below.
Same exact trigger action and device, but second is easier to read and later troubleshoot. Also note the naming; this switch is controlling the second garage door and is device #40 in my Z-Wave JS-UI controller. I know I am a bit anal retentive about it but it makes sense to me!
2. Use the GUI automation and scrip builders to help you become a proficient YAML coder. You can use the GUI builders to begin coding your automations. Remember to look at the YAML so you can learn syntax, requirements and code structure. Its really an easy language to learn once you respect its spacing requirements
3. Consider what you want your system to look like at completion. Build your automations to do one thing and do it correctly every time. It is far better to build small concise automations than to build one large mega complex automation to try to work through every scenario. Remember, automation can call scripts which can chain together a sequence of actions. Consider this; you want an automation to do the following: At 8 pm lock the front door, close the garage door and turn on the outside lights. I would build one automation that triggers at 8pm and the call 3 individual scripts, one for each task. If at some point you need to add or remove a task, it’s a simple edit of the calling automation. Additionally, these 3 scripts can be called from elsewhere as well, so you can call the ‘lock the front door’ script when you leave the house. No need to code it again and again in multiple automations. Create a simple ‘no one home’ automation and call the scripts necessary.
This snippet of code is from my doorbell automation. It calls multiple scripts and grabs a camera snapshot between the calls. the camera image is used in the last script which sends it to my email. The 8 sec delay just makes sure the image capture and write commands have completed.
Ask the community for help. There are lots of power users here but also a ton of people like yourself who are just getting their feet wet. A specific question of what you want to do, what didn’t work for you, and showing the code of what you tried will almost always get a response.
Avoid any of the online AI bots. More times than not you will get wrong or outdated code responses. It’s far better to search here, then ask questions if you’re still stuck. If you look at most of the posts here, there is usually a chunk of code that did not work for that OP, but Chat GPT doesn’t always understand that.
Good luck and have fun while building your dream smart home. HA shouldn’t be a task, but rather a fun project that makes your home better.