For the next ones who could pass here. I struggled with that too.
There are my findings:
Nesting the config in the sensor array did not worked for me. Putting the config outside of sensor worked.
Example:
NOT WORKING:
sensor:
- platform: sql
db_url: !secret maria_db_url
scan_interval: 3600
queries:
- name: MariaDB DB Size
query: 'SELECT table_schema "database", Round(Sum(data_length + index_length) / POWER(1024,2), 1) "value" FROM information_schema.tables WHERE table_schema="ha-record" GROUP BY table_schema;'
column: "value"
unit_of_measurement: MB
WORKING:
sql:
- name: MariaDB Database Size
db_url: !secret maria_db_url
query: 'SELECT table_schema "database", Round(Sum(data_length + index_length) / POWER(1024,2), 1) "value" FROM information_schema.tables WHERE table_schema="ha-record" GROUP BY table_schema;'
column: "value"
unit_of_measurement: MB
device_class: data_size
LIMITATION:
There is no way to set the “scan_interval” from sensor. To be honest I have no idea how often it will update. I don’t see any config that allow me to define that.
But at least the sensor is there. Maybe not exactly how I wanted at first but it’s already a beginning. If I find a way to configure the update interval I’ll update this post.
SELECT
table_schema AS db_name,
ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS size_mb
FROM
information_schema.TABLES
WHERE
table_schema = ‘homeassistant’;
Thanks! This worked for me, using the SQL integration in the UI (so I didn’t need to explicity provide the db_url as it could use the default from the recorder).