mirror of
https://github.com/home-assistant/home-assistant.io.git
synced 2025-07-23 09:17:06 +00:00
Migrate file integration to config entry (#32593)
This commit is contained in:
parent
0678064793
commit
d6200af31c
@ -16,77 +16,22 @@ ha_platforms:
|
|||||||
ha_integration_type: integration
|
ha_integration_type: integration
|
||||||
---
|
---
|
||||||
|
|
||||||
There is currently support for the following device types within Home Assistant:
|
The File integration allows to store notifications to a file or to set up a sensor based on a file's content.
|
||||||
|
|
||||||
- [Notifications](#notifications)
|
{% include integrations/config_flow.md %}
|
||||||
- [Sensor](#sensor)
|
|
||||||
|
|
||||||
## Notifications
|
## Notifications
|
||||||
|
|
||||||
The `file` platform allows you to store notifications from Home Assistant as a file.
|
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](https://www.home-assistant.io/integrations/homeassistant/#allowlist_external_dirs). The file will be created if it doesn't exist. Add the path of your [configuration](/docs/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 enable file notifications in your installation, add the following to your `configuration.yaml` file:
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
# Example configuration.yaml entry
|
|
||||||
notify:
|
|
||||||
- name: NOTIFIER_NAME
|
|
||||||
platform: file
|
|
||||||
filename: FILENAME
|
|
||||||
```
|
|
||||||
|
|
||||||
{% configuration %}
|
|
||||||
name:
|
|
||||||
description: Setting the optional parameter `name` allows multiple notifiers to be created. The notifier will bind to the service `notify.NOTIFIER_NAME`.
|
|
||||||
required: false
|
|
||||||
default: notify
|
|
||||||
type: string
|
|
||||||
filename:
|
|
||||||
description: Name of the file to use. The file will be created if it doesn't exist. Add the path of your [configuration](/docs/configuration/) folder (e.g., `/config`) to save the file there.
|
|
||||||
required: true
|
|
||||||
type: string
|
|
||||||
timestamp:
|
|
||||||
description: Setting `timestamp` to `true` adds a timestamp to every entry.
|
|
||||||
required: false
|
|
||||||
default: false
|
|
||||||
type: boolean
|
|
||||||
{% endconfiguration %}
|
|
||||||
|
|
||||||
To use notifications, please see the [getting started with automation page](/getting-started/automation/).
|
To use notifications, please see the [getting started with automation page](/getting-started/automation/).
|
||||||
|
|
||||||
|
Use the `notify.{name}` service to store notification messages.
|
||||||
|
|
||||||
## Sensor
|
## 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](/integrations/homeassistant/#allowlist_external_dirs).
|
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](/integrations/homeassistant/#allowlist_external_dirs).
|
||||||
|
|
||||||
To enable the `file` sensor, add the following lines to your `configuration.yaml`:
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
# Example configuration.yaml entry
|
|
||||||
sensor:
|
|
||||||
- platform: file
|
|
||||||
file_path: /home/user/.homeassistant/sensor-data.txt
|
|
||||||
```
|
|
||||||
|
|
||||||
{% configuration %}
|
|
||||||
file_path:
|
|
||||||
description: Path to file that stores the sensor data.
|
|
||||||
required: true
|
|
||||||
type: string
|
|
||||||
name:
|
|
||||||
description: Name of the sensor to use in the frontend.
|
|
||||||
required: false
|
|
||||||
default: file name
|
|
||||||
type: string
|
|
||||||
unit_of_measurement:
|
|
||||||
description: Defines the units of measurement of the sensor, if any.
|
|
||||||
required: false
|
|
||||||
type: string
|
|
||||||
value_template:
|
|
||||||
description: Defines a [template](/docs/configuration/templating/#processing-incoming-data) to extract a value from the payload.
|
|
||||||
required: false
|
|
||||||
type: template
|
|
||||||
{% endconfiguration %}
|
|
||||||
|
|
||||||
### Examples
|
### Examples
|
||||||
|
|
||||||
In this section you find some real-life examples of how to use this sensor.
|
In this section you find some real-life examples of how to use this sensor.
|
||||||
@ -101,21 +46,12 @@ Assuming that the log file contains multiple values formatted as JSON like shown
|
|||||||
{"temperature": 22, "humidity": 36}
|
{"temperature": 22, "humidity": 36}
|
||||||
```
|
```
|
||||||
|
|
||||||
This would require the following entry in the `configuration.yaml` file to extract the temperature:
|
This would require the following settings extract the temperature:
|
||||||
|
|
||||||
{% raw %}
|
- Name: `Temperature`
|
||||||
|
- File path: `/home/user/.homeassistant/sensor.json`
|
||||||
```yaml
|
- Value template: {% raw %}`'{{ value_json.temperature }}'`{% endraw %}
|
||||||
# Example configuration.yaml entry
|
- Unit of measurement: `"°C"`
|
||||||
sensor:
|
|
||||||
- platform: file
|
|
||||||
name: Temperature
|
|
||||||
file_path: /home/user/.homeassistant/sensor.json
|
|
||||||
value_template: '{{ value_json.temperature }}'
|
|
||||||
unit_of_measurement: "°C"
|
|
||||||
```
|
|
||||||
|
|
||||||
{% endraw %}
|
|
||||||
|
|
||||||
#### Entries as CSV
|
#### Entries as CSV
|
||||||
|
|
||||||
@ -127,18 +63,9 @@ timestamp,temperature,humidity
|
|||||||
1631472949,22,36
|
1631472949,22,36
|
||||||
```
|
```
|
||||||
|
|
||||||
This would require the following entry in the `configuration.yaml` file to extract the temperature:
|
This would require the following settings to extract the temperature:
|
||||||
|
|
||||||
{% raw %}
|
- Name: `Temperature`
|
||||||
|
- File path: `/home/user/.homeassistant/sensor.csv`
|
||||||
```yaml
|
- Value template: {% raw %}`'{{ value.split(",")[1] }}'`{% endraw %}
|
||||||
# Example configuration.yaml entry
|
- Unit of measurement: `"°C"`
|
||||||
sensor:
|
|
||||||
- platform: file
|
|
||||||
name: Temperature
|
|
||||||
file_path: /home/user/.homeassistant/sensor.csv
|
|
||||||
value_template: '{{ value.split(",")[1] }}'
|
|
||||||
unit_of_measurement: "°C"
|
|
||||||
```
|
|
||||||
|
|
||||||
{% endraw %}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user