File
There is currently support for the following device types within Home Assistant:
Notifications
The file
platform allows you to store notifications from Home Assistant as a file.
To enable file notifications in your installation, add the following to your configuration.yaml
file:
# Example configuration.yaml entry
notify:
- name: NOTIFIER_NAME
platform: file
filename: FILENAME
Configuration Variables
Setting the optional parameter name
allows multiple notifiers to be created. The notifier will bind to the service notify.NOTIFIER_NAME
.
Name of the file to use. The file will be created if it doesn’t exist. Add the path of your configuration folder (e.g., /config
) to save the file there.
To use notifications, please see the getting started with automation page.
Sensor
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 allowlist_external_dirs.
To enable the file
sensor, add the following lines to your configuration.yaml
:
# Example configuration.yaml entry
sensor:
- platform: file
file_path: /home/user/.homeassistant/sensor-data.txt
Examples
In this section you find some real-life examples of how to use this sensor.
Entries as JSON
Assuming that the log file contains multiple values formatted as JSON like shown below:
[...]
{"temperature": 21, "humidity": 39}
{"temperature": 22, "humidity": 36}
This would require the following entry in the configuration.yaml
file to extract the temperature:
# Example configuration.yaml entry
sensor:
- platform: file
name: Temperature
file_path: /home/user/.homeassistant/sensor.json
value_template: '{{ value_json.temperature }}'
unit_of_measurement: "°C"
Entries as CSV
Assuming the log file contains multiple values formatted as CSV like shown below:
timestamp,temperature,humidity
1631472948,21,39
1631472949,22,36
This would require the following entry in the configuration.yaml
file to extract the temperature:
# Example configuration.yaml entry
sensor:
- platform: file
name: Temperature
file_path: /home/user/.homeassistant/sensor.csv
value_template: '{{ value.split(",")[1] }}'
unit_of_measurement: "°C"