File Sensor: Plain Text File

Greetings! I am trying to create a file sensor to pull the very last line of a flat text file. Here’s the output of the file… essentially, it’s the a log of a switch.

GPO 1 Lhhhh
GPO 1 Hhhhh

Lhhhh= On.
Hhhhh= Off.

How would I go about creating a sensor to check and see the state of the very last line of a text file? So far… I have:

  - platform: file
    name: SwitchLog
    file_path: /config/switch/switchsensor.txt

I’m just not sure where to go next.

Thanks for your help. :slight_smile:

That should create a sensor named sensor.switchlog which has the line you want.

What else are you looking for?

1 Like

Thanks Nick! I must have missed a step, as I don’t see the Sensor anywhere. Maybe my file path is off.

OK! So the plot thinkens.

On a full restart of Home Assistant, I see the following error in the log:

Logger: homeassistant.components.file.sensor
Source: components/file/
Integration: file ([documentation](, [issues](
First occurred: 10:39:34 AM (1 occurrences)
Last logged: 10:39:34 AM

'/config/switch/switchsensor.txt' is not an allowed directory

Here from my configuration:

    - /config/switch

And the sensor…

  - platform: file
    name: axia
    file_path: /config/switch/switchsensor.txt

The text file exists:

bash-5.0# ls

bash-5.0# pwd

Any ideas? Thanks!

For what it’s worth, I’ve tried whitelist_external_dirs and also allowlist_external_dirs to no avail.