Getting Very Confused with the File Integration

Hi All, I have a sensor that I wish to write out it value to a CSV file, every so often.

So I followed the following steps,

(a) Added the following to my Configuration.yaml file

(b) Added the File Intergration and setup as below

(c) Created the automation shown below

(d) created the directory /tmp at the root level on my HA green box.
Note: I even tried creating the tmp directory inside the config directory as someone suggested that paths are relative to this directory.
I also created the file in each of these directories with a touch w.log command.

(e) I then manualy ran the automation which showed no errors and give the following trace output.

(f) check the file w.log in the tmp directory, size 0 bytes. If my automation ran with no errors WHAT FILE DID IT WRITE THE DATA TO?

Any help would be gratefully received. Many thanks.

As a side note, I could us the method described by David Proffer.

Query example to get whole house power usage for last two days, the SQL code may vary some for use with SQLite. Be gentle with your queries on the SQLite database of HA, if that is your default database, as it not as robust as other database. If you are going to experiment, first shutdown HA for a bit and copy the SQLite database to a test copy and then explore this copy of the data without effecting your HA running instance :

-- get SCE whole house power
SELECT
    *
FROM
    states
WHERE (entity_id = 'sensor.home_instantaneous_demand'
    AND last_updated > now() - interval '2 days')
ORDER BY
    last_updated DESC;
-- sqlite interval example :
-- https://stackoverflow.com/questions/1101182/what-are-the-sqlite-equivalents-of-mysqls-interval-and-utc-timestamp/7547245

Try with

homeassistant:
  packages: !include_dir_named packages
  allowlist_external_dirs:
    - "/config/tmp"

Thank you for your reply, Francis, but still end up with a file with zero bytes in.

All these work

with this configuration

homeassistant:
  packages: !include_dir_named packages
  allowlist_external_dirs:
    - "/config"

and actions like this:

  action:
  - service: notify.send_message
    target: 
      entity_id: notify.notifier_rflink
    data:
      message: '{{now().year}}-{{now().month}}-{{now().day}} {{now().hour}}:{{now().minute}}:{{now().second}}
        -> {{trigger.topic}} - {{ trigger.payload_json}}'

Thanks Francis, it now seems to work.

I went back to just creating a text file in the /config directory.

All I can presume is that although my message data showed up ok in the automation traces - although it the first case it is enclosed in single quotes, but in the second working case it is not enclosed in quotes of any kind - it was always writing an empty string (i.e. zero bytes) to my disk file.

Many thanks for all your help.