File Integration -- there seems to be no way of debugging it?

I use the File integration’s notification feature to write several log files from automations that all use the same script. Mostly they work, but if they don’t, how do you figure out why not?

I have already tried …

  1. Restarting the system several times
  2. Deleting the Entry and setting it up again as below
  3. Disabling the Entry and then re-enabling it

The problem is, there is not much else I can do. Amongst File integration’s shortcomings are that it does not produce error messages, even with debugging enabled, and an entry cannot be checked or edited after it has been created (except to turn the timestamp on or off).

Setup Method

I originally set them up with a configuration file. Sadly, they had to be migrated last year to the new File Integration, where they now have to be edited by hand. That was a retrograde step but here we are.

I have since successfully set up new notification services by hand. This is tedious but works if you do not make a mistake. You have to:

  1. Go to the File integration and click ‘add entry’
  2. Fill in the file path, which in this example is /config/log_files/ground_floor_zone_control.log
  3. Click submit. You then get an new entry in the list with a name like filenotify[/config/log_files/ground_floor_zone_control.log]
  4. To give it a friendly name you have to click the three dots on the right and of the entry and select rename. I called mine “Ground Floor Zone Control Log”
  5. If this is the first one, you have to make sure that you have enabled the path in the configurations.yaml file – in my case:
homeassistant:
  allowlist_external_dirs:
    - /config
  1. Back in the File Integration, if you now click on the “1 entity” link under the name of the entry, it takes you to the Entity view. You will find that it is unhelpfully named ‘File’ with the entity_name notify.file, so you have to edit both by hand, in my case to “Ground Floor Zone Control Log” and notify.ground_floor_zone_control_log respectively.
  2. Restart the system with a full restart (not just a quick start) to ensure the changes ‘take’.
  3. Now the notification service is finally ready to use in an automation!
  4. Repeat for every single notification service that you want (in my case a couple of dozen).

Why the designers think this is straightforward, and better than a single YAML file, is a mystery!

My immediate issue

I have repeated this process several time, usually with success. However in one case (Ground Floor Zone Control Log) it fails. The automation runs fine but:

  • I get no log file content (though other files written using the same script are fine)
  • I get no error messages in the integration
  • I get no log file messages, even with debug enabled in the integration

The only anomaly I can find is that if I navigate to the entity associated with the entry, it is shown as either unknown or unavailable (it keeps switching between the two).

My immediate questions

  1. Can anyone see a problem with my setup procedure that would cause it to work most of the time but fail occasionally?
  2. Does anyone know of a method of debugging a file notification that I have not mentioned?

Suggested future improvements to the File integration (feature requests)

  1. Reintroduce the option to define notification services using a YAML file
  2. In the UI: During setup it should be possible to set a friendly name for the service as well as the path and file name (/config/log_files/ground_floor_zone_control.log and “Ground Floor Zone Control Log”)
  3. This friendly name (“Ground Floor Zone Control Log”) should be reflected in the Entity name
  4. The entity id should be based on the entity name (notify.ground_floor_zone_control_log)
  5. After defining a new entry, it should be possible to see and edit all the parameters supplied when first setting it up.

Welcome to the file integration for notifications.

https://community.home-assistant.io/t/notify-send-message-in-2024-6/737177/25?u=biscuit

Debugging is probably best done by deleting the entry and starting again.

Edit
Debugging can probably only be done by deleting the entry and starting again.

As I said, I already tried that several times.

I have also tried regenerating the entry with a new entity name, because after renaming ‘file’, I often get a mysterious warning message in the system log 'unable to migrate history … because new entity name is already in use". Not that there is any history to migrate anyway, but this might be a clue?

If I try to send a message to the file manually using Developer tools - Action, it knows the entity name and tries to send a message but reports “unknown error” - the least helpful of all error messages!

I can’t for the life of me see why this new entry is any different from the 20-odd files that already work correctly and am very frustrated by the total absence of any debugging information for the File integration :thinking:

Exactly. You are indeed welcome to this integration.

About the only thing I suspect as being your issue, is that you are using

/config/log_files/ground_floor_zone_control.log

and you have added

/config

to your homeassistant allowlist_external_dirs

and if you read my posting from last year, you will note that the allow list operates only on the given directory, and hence sub directories are not permitted by default. You probably need to add

/config/log_files

to the list. Assuming, of course, that you have not already done so.

The new file was in the same log_files subdirectory as all the 20-odd others that work correctly, so it can’t be that. Anyway, as I recall, the integration does give an error message if it cannot write to a file.
(I added it anyway to be on the safe side).

I finally got it working today but I don’t know how, so I cannot mark any item above as a solution. My best theory, based on several trials with test files and testing via the Developer Tools, is that it has something to do with the renaming of notify.file to the name you actually want, and what happens if you make a mistake…

  1. I originally made an Entry for ground_floor_zone_control.log but (I think) made a typo in the pathname. I deleted it and recreated it but it did not work, even after a system restart.
  2. If I start from scratch with a new entry using a new file (/config/log_files/test.log) and leaving the default entity “File” / notify.file, it works. (So it is not a permissions / file access issue).
  3. If I change the new entity name and entity_id to one that has never been used before (notify.ground_floor_zone_control_log_x), it still works. (So it is not a problem with my procedure for setting it up).
  4. If I change the new entity name and entity_id to the one I want, but it has previously been used and deleted (notify.ground_floor_zone_control_log), it does not work initially.
  5. However, it did work after a complete system restart (not just a quick reload) between deleting it, and then another restart after redefining it.

So, in the absence of further information, my best advice to anyone with a similar problem is: every time you add, delete, or change a notification, do a complete system restart (not just a quick reload) after each step.

It’s a good Integration when it works, but a bugger to debug! :imp:

BTW you should also note that the Developer Tools ACTION section has not yet eliminated the legacy notify.notify action as an option. This will not work with the current version of HA core (“unknown error”). Be sure to use notify.send_message to test your new notifications file :crazy_face: