๐Ÿ”„ Reload automations automatically when a Blueprint is changed

This blueprint will automatically reload Automations when there is a change in the blueprints folder. This can be useful if you are creating Blueprints, since automations needs to be reloaded after every modification in the blueprint file.

Requirements:

You need to set up the Folder Watcher integration.

Add the path of your blueprints folder to the configuration.yaml:

folder_watcher:
- folder: /config/blueprints

Add it to the allowlist:
homeassistant:
allowlist_external_dirs:
- "/config/blueprints"

Restart Home Assistant.

Blueprint

Click the badge to import this Blueprint: (needs Home Assistant Core 2021.3 or higher)

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

Or you can import this Blueprint by using the forum topic URL:

blueprint:
  name: Reload automations on file change
  description: >
    When you modify a blueprint, automations need to be reloaded to pick up the latest changes.
    This blueprint automates the reloading when your file changes.
    It is required to setup the folder_watcher integration with /config/blueprints directory for this to work.
    https://www.home-assistant.io/integrations/folder_watcher/
  domain: automation

trigger:
  - platform: event
    event_type: 'folder_watcher'

condition:
  - condition: template 
    value_template: "{{ 'blueprints' in  trigger.event.data.folder }}" 

action:
  - service: automation.reload

Notes:

If you create an automation from this blueprint, and there is no Save button, try changing the name of the automation and the Save button will appear.

4 Likes

if i try to import your blueprint i get an error

No valid blueprint found in the topic. Blueprint syntax blocks need to be marked as YAML or no syntax.

Thank you, Iโ€™m trying to figure out what could be the problem.
Meanwhile you can import the same blueprint from Github:
https://github.com/vorostamas/ha-blueprints/blob/b0f40296ffcb738c5d958553fc2351d11597e195/blueprints/automation/vorostamas/reload_automations_on_file_change.yaml

1 Like

Have you considered adding a homeassistant.check_config call before going to automation.reload? If you have a typo while youโ€™re making config adjustments it looks like you get an error that โ€œthe following integrations could not be set up: automationโ€. Iโ€™m not sure if that breaks something or just fails to reload.

Instead you could do a homeassistant.check_config call and then proceed to the automation.reload only if persistent_notification.homeassistant_check_config did not exist (since that notification gets created if the config check fails). This seems like it would be nicer since then the logs would tell you exactly what was wrong with your config instead of just telling you that automations couldnโ€™t be loaded.

3 Likes

I have one question: why not just an automation instead of a blueprint to create an automation? Will this logic be reused somewhere?

1 Like

Thatโ€™s a clever idea! Thanks for sharing.
My problem is that I frequently press save, and the homeassistant.check_config can take a lot of time.
But I realized that this Blueprint has a bug, I should change the Run Mode from the default single to something else, like restart.

1 Like

For importing it with one click, and in the future you will be able to update your local blueprint with the changes I make.

3 Likes