File
The File integration allows storing notifications in a file or setting up a sensor based on a file’s content.
配置
要将 File integration 添加到您的 Home Assistant 实例中,请使用此 My 按钮:
手动配置步骤
如果上述 My 按钮不起作用,您也可以手动执行以下步骤:
-
浏览到您的 Home Assistant 实例。
-
转到
设置 > 设备与服务。 -
在右下角,选择
Add Integration 按钮。 -
从列表中选择 File。
-
按照屏幕上的说明完成设置。
Notifications
Make sure that the file you want to use is added to the allowlist_external_dirs. The file will be created if it doesn’t exist, but make sure the folder exists. Add the path of your configuration folder (for example, /config/file_notifications
) to save the file there. Setting timestamp
to true
adds a timestamp to every logged entry.
After creating a config entry, you can change the entry name, the name of the notify entity, or the entity ID, if you prefer.
To use notifications in automations or scripts, see the getting started with automation page.
Use the notify.send_message
entity to store notification messages.
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.
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 as shown below:
[...]
{"temperature": 21, "humidity": 39}
{"temperature": 22, "humidity": 36}
This would require the following settings to extract the temperature:
- 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 as shown below:
timestamp,temperature,humidity
1631472948,21,39
1631472949,22,36
This would require the following settings to extract the temperature:
- Name:
Temperature
- File path:
/home/user/.homeassistant/sensor.csv
- Value template:
'{{ value.split(",")[1] }}'
- Unit of measurement:
"°C"