Add back yaml support (#24293)

Co-authored-by: Franck Nijhof <frenck@frenck.nl>
Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
G Johansson 2023-01-09 11:46:27 +01:00 committed by GitHub
parent cb052f9568
commit d6589bf86d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -19,8 +19,68 @@ ha_integration_type: integration
The `sql` sensor platform enables you to use values from an [SQL](https://en.wikipedia.org/wiki/SQL) database supported by the [sqlalchemy](https://www.sqlalchemy.org) library, to populate a sensor state (and attributes).
This can be used to present statistics about Home Assistant sensors if used with the `recorder` integration database. It can also be used with an external data source.
**This integration can be configured using both config flow and by YAML.**
{% include integrations/config_flow.md %}
## Configuration by YAML
To configure this sensor, define the sensor connection variables and a list of queries to your `configuration.yaml` file. A sensor will be created for each query.
To enable it, add the following lines to your `configuration.yaml` file (example by required fields):
{% raw %}
```yaml
# Example configuration.yaml
sql:
- name: Sun state
query: >
SELECT *
FROM states
WHERE entity_id = 'sun.sun'
ORDER BY state_id
DESC LIMIT 1;
column: "state"
```
{% endraw %}
{% configuration %}
sql:
description: Integration.
required: true
type: map
keys:
db_url:
description: The URL which points to your database. See [supported engines](/integrations/recorder/#custom-database-engines).
required: false
default: "Defaults to the default recorder `db_url` (not the current `db_url` of recorder)."
type: string
name:
description: The name of the sensor.
required: true
type: string
query:
description: An SQL QUERY string, should return 1 result at most.
required: true
type: string
column:
description: The field name to select.
required: true
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 to extract a value from the payload.
required: false
type: template
unique_id:
description: Provide a unique id for this sensor.
required: false
type: string
{% endconfiguration %}
## Information
See [supported engines](/integrations/recorder/#custom-database-engines) for which you can connect with this integration.