The ability to restore previous versions of an automation

One feature that would be really useful would be the ability to have multiple versions of automations saved. All too often i make number of changes to the logic which inadvertently makes the automation fail or not work as desired. When trying to then revert i have to remember the case logic i had before and then recreate it. It would be really useful that when you click save with the new changes it just creates a new version of the automation but also keeps the previous version so if a mistake is made you can then restore a previous working one. I know there are ways to backup the config folder as a whole but that seems to be a nuclear approach, it would be nice if it was just a built in feature in the Automation UI.

The visual Automation Editor is designed for novices. It doesn’t offer all of Home Assistant’s scripting features in visual mode and, in YAML mode, doesn’t support comments, !include statements, boolean values and a host of other things.

If you want complete control of your automations, including keeping older versions, I recommend you consider using a text editor, like Visual Studio Code (with the Home Assistant Config Helper).

For improved record-keeping, my automations are peppered with comments explaining why and when I changed something in an automation (sometimes with the old code commented out for future reference as opposed to deleted). Others use a version control system (like GitHub) thereby allowing them to rollback to a previous version.

Many more possibilities exist once you graduate from the Automation Editor to alternatives.

1 Like

I get your point but I wouldn’t expect something like this to be an advanced feature. I wouldn’t say i was a novice user and when i first started using HA the GUI for creating automations wasnt anywhere near as capbable as it is now i had to learn to do most things using YAML.

With each new update more and more things are being taken out of something you used to faff around with YAML and making them GUI only. Also if i was a new user i would love the ability to roll back a change in an automation which is isnt working following some changes. The Automation editor is front and centre for probably 80% of users so it was just something i would hope could be baked in, a basic way would be to comment out old code when you make a change in the Automation Editor.

With all those things noted i will have a look at the Visual Studio Code addon.

1 Like

Do you know of another home automation software (either free or paid) that offers this feature?

What you’re asking for is a version control system.

I thought I posted this on a feature request as it is something I thought was useful based on my experience with Home Assistant so far.

I know this isn’t something offered anywhere else which is why I thought it was a good idea.

I was just looking at the ability to just have multiple versions of automations stored in the event of something not working, I know it’s easy for me to just say that and I am happy to be told “it isn’t possible” or just use these addons and have them set up like this, or if this is just something I have to do manually that is fine too.

Don’t get me wrong, I’m not saying it’s not possible only that implementing your request is more complex than you may have imagined. As a consequence, it may be a long time, if ever, before the feature is implemented. In the interim, there are other means of achieving your goal.

Yes that is fair, understood. It is never as straight forward as the user thinks it is. I will look at alternatives in the interim for my specific use case. A simple one would be just to take a backup of the automation yaml before I make any wholesale changes to a automation.

You brought up a point I overlooked to mention. The Automation Editor stores all automations (created using the Automation Editor) in one file (assuming your configuration.yaml file contains automation: !include automations.yaml).

In contrast, if you choose to create automations with a text editor, they can be stored separately in as many files as you want and in a separate directory (i.e. if you wish, each automation can be in a separate file). In fact, it’s advisable to keep “manually created” automations separate from automations.yaml (i.e. out of reach of the Automation Editor because it deletes any comments you add and do several other things you may not want).

The procedure is documented here.

For example, my configuration.yaml file contains the following:

automation: !include automations.yaml
automation manual: !include_dir_merge_list automations/

All of the automations that I create with a text editor are stored, in multiple files, within a sub-directory named automations.


FWIW, here’s an example of a comment block that appears at the beginning of one of my automations.

## FRONT LIGHT
##
## New version combines three automations into one.
##
## 2021-07-03 Changed alias (removed the word "Outside")
## Added `id`.
## Added new `target` option.
## Added `default` to `choose`.
##
## 2022-03-11 Specify exact states for garage door.
## Ensures it will not trigger for state changes
## involving `unavailable` or `unknown`.
##
- alias: 'Automatic Front Light'
  id: automatic_front_light
  trigger:
  ... etc ...

If I change parts of the automation, I comment out the old lines of YAML rather than delete it. Once I am satisfied that the modified automation is behaving correctly (might be days later) I delete the commented-out bits (unless I want to keep them for posterity).

I screw up automations all the time. Start with a duplicate of your working automation, make and test your changes (name it “…-1” for your own version control). If good, delete your original automation. Or if you are like me and want to revert, just delete the duplicate automation.

Oh right! I didnt know it works like that. Super helpful advice thanks.

I’m aware that I’m resurrecting an oldish feature request. But as I’m trying to solve the same problem as OP I ended up here and didn’t find any other similar feature request.

While I generally agree that VCS are tremendously complex, I’d like to strongly disagree to the analogy concerning home assistant.

VCS are used in software development to enable multiple people collaborating on often large code bases.

However, an environment like Home Assistant is a lot less complex. Meaning: we’re mostly talking single ‘developer’, no need for a concept like branches to maintain different streams, merging, performance requirements and so on.

Given the much reduced complexity and set of features, I think some kind of revision management would, at least conceptually, not be very hard to implement.

A very simple implementation could work like this (maybe not all assumptions I make are true, I don’t really know the inner workings of HA):

  • an automation A, even when edited in the UI, is represented by a yaml file A.yaml
  • whenever automation A is changed and saved, a popup could be shown to enter a comment describing the changes
  • before A.yaml is overwritten, it is backed up in some folder, e.g., ‘automations-history’ with a file name A_0_2024-10-25-00:07.yaml
  • the new state of A is written into A.yaml with the comment as metadata in a header in the file
  • repeat, the next change will lead to a backup A_1_.yaml and so on
  • then in the UI there could be a menu ‘Show revisions’ which presents the list of previous revisions that could be restored
  • once this MVP exists, it could be improved incrementally: deleting revisions, automatically only keeping n latest revisions, showing a diff between two revisions…

I’m aware that implementing this might not be as easy as it sounds but we’re very far from the complexity of a VCS and it would do the job just fine for 99% of the use cases.
This pattern could also be applied to other constructs like integrations or wherever else it might be helpful.

1 Like

After the release of the new backup feature and the uproar against encrypted backups it seems like a lot of users use backups to copy code from old yaml files (myself included). A revision history of yaml files that could easily be restored would simplify this process a lot.