2.5 KiB
title, description, ha_category, ha_release, ha_iot_class, ha_codeowners, ha_domain, ha_platforms, ha_integration_type
title | description | ha_category | ha_release | ha_iot_class | ha_codeowners | ha_domain | ha_platforms | ha_integration_type | ||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
File | Instructions on how to integrate sensors which read from files into Home Assistant. |
|
pre 0.7 | Local Polling |
|
file |
|
integration |
The File integration allows to store notifications to a file or to set up a sensor based on a file's content.
{% include integrations/config_flow.md %}
Notifications
The file
platform allows you to store notifications from Home Assistant as a file. 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. Add the path of your configuration folder (e.g., /config
) to save the file there. Setting the optional parameter name
allows multiple notifiers to be created. Setting timestamp
to true
adds a timestamp to every entry.
To use notifications, please see the getting started with automation page.
Use the notify.send_message
entity service 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 like shown below:
[...]
{"temperature": 21, "humidity": 39}
{"temperature": 22, "humidity": 36}
This would require the following settings extract the temperature:
- Name:
Temperature
- File path:
/home/user/.homeassistant/sensor.json
- Value template: {% raw %}
'{{ value_json.temperature }}'
{% endraw %} - 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 settings to extract the temperature:
- Name:
Temperature
- File path:
/home/user/.homeassistant/sensor.csv
- Value template: {% raw %}
'{{ value.split(",")[1] }}'
{% endraw %} - Unit of measurement:
"°C"