Read values from a txt file

these are my beginnings in Home Assistant
I want to read the value from the txt file and display it but nothing happens.

temp, 82.0, 10, 30,


  - platform: file
    name: kotla
    file_path: /config/test/data.txt
    value_template: >
        {{ value.split(',')[1] }}

I don’t get new entities

What am I doing wrong?

  1. Execute Configuration > Server Controls > Check Configuration
  2. Ensure it doesn’t report any errors. If it does, fix them before proceeding to the next step.
  3. Execute Configuration > Server Controls > Restart Home Assistant
  4. After it restarts, go to Configuration Logs and confirm these are no errors related to the File Sensor.

Hello, thanks for the quick reply.

it’s true:

Logger: homeassistant.components.file.sensor
Source: components/file/
Integration: file (documentation, issues)
First occurred: 14:21:23 (1 occurrences)
Last logged: 14:21:23

'/config/test/data.txt' is not an allowed directory

Where can the file be located?

In your configuration.yaml file, under the homeassistant: option, add information that allows Home Assistant to access the config/data directory.

    - '/config/data'

Then restart Home Assistant and check Logs for errors.

This is mentioned in the File Sensor’s documentation:

The file sensor platform reads the entries from a plain-text file and shows the found value. Only the last line of the file is used. This is similar to do $ tail -n 1 sensor.txt on the command-line. Note that file paths must be added to allow_external_dirs.

Hi, thanks for the repairs now working

1 Like

Glad to hear it solved the problem.

Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic is resolved. This helps other users find answers to similar questions. For more information, refer to guideline 21 in the FAQ.

I would need another help, namely.
But how can I read the data from the table, just certain data.

0;          data1 ;     2.0
 1;          data2 ;     3.0
 2;          data3 ;     1.0
 3;          data4 ;     0.0
 4;          data5 ;    78.0
 5;          data6 ;   117.0
 6;          data7 ;   119.0
 7;          data8 ;    53.0
 8;          data9 ;    35.0
 9;         data10 ;    41.0
10;         data n ;    65.0

The File Sensor integration only reads the last line in the file.

The file sensor platform reads the entries from a plain-text file and shows the found value. Only the last line of the file is used.

aha :flushed:
how could I do this to read the desired data from the table?

To my knowledge, there is no standard integration in Home Assistant that lets you read a specific line from a file.

However, it’s possible to create a python_script to read a file and return whatever information you want.

Here’s an example created by VDRainer that gets all lines from a file and returns them as attributes of a sensor. Once that’s done, the information within the attributes is easily accessible to any template for further processing.


If you want to discuss that way of retrieving data, you should start a new topic.

thanks for sending i will look and try to understand something.
When I’m in trouble, I’ll ask questions?