From 019bdac5f78060aa220fd879c7fe34371a627fc7 Mon Sep 17 00:00:00 2001 From: dougiteixeira <31328123+dougiteixeira@users.noreply.github.com> Date: Mon, 8 Jul 2024 16:58:49 -0300 Subject: [PATCH] Adds note about unit and device class for database size sensor (#33642) --- source/_integrations/sql.markdown | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/source/_integrations/sql.markdown b/source/_integrations/sql.markdown index d44613acee7..b2dea2735e5 100644 --- a/source/_integrations/sql.markdown +++ b/source/_integrations/sql.markdown @@ -248,6 +248,12 @@ SELECT pg_database_size('dsmrreader')/1024/1024 as db_size; Use `db_size` as column for value. Replace `dsmrreader` with the correct name of your database. +{% tip %} +The unit of measurement returned by the above query is `MiB`, please configure this correctly. + +Set the device class to `Data size` so you can use UI unit conversion. +{% endtip %} + #### MariaDB/MySQL Change `table_schema="homeassistant"` to the name that you use as the database name, to ensure that your sensor will work properly. @@ -257,6 +263,12 @@ SELECT table_schema "database", Round(Sum(data_length + index_length) / POWER(10 ``` Use `value` as column for value. +{% tip %} +The unit of measurement returned by the above query is `MiB`, please configure this correctly. + +Set the device class to `Data size` so you can use UI unit conversion. +{% endtip %} + #### SQLite If you are using the `recorder` integration then you don't need to specify the location of the database. For all other cases, add `sqlite:////path/to/database.db` as Database URL. @@ -266,6 +278,12 @@ SELECT ROUND(page_count * page_size / 1024 / 1024, 1) as size FROM pragma_page_c ``` Use `size` as column for value. +{% tip %} +The unit of measurement returned by the above query is `MiB`, please configure this correctly. + +Set the device class to `Data size` so you can use UI unit conversion. +{% endtip %} + #### MS SQL Use the same Database URL as for the `recorder` integration. Change `DB_NAME` to the name that you use as the database name, to ensure that your sensor will work properly. Be sure `username` has enough rights to access the sys tables. @@ -282,3 +300,9 @@ Connecting with MSSQL requires "pyodbc" to be installed on your system, which ca SELECT TOP 1 SUM(m.size) * 8 / 1024 as size FROM sys.master_files m INNER JOIN sys.databases d ON d.database_id=m.database_id WHERE d.name='DB_NAME'; ``` Use `size` as column for value. + +{% tip %} +The unit of measurement returned by the above query is `MiB`, please configure this correctly. + +Set the device class to `Data size` so you can use UI unit conversion. +{% endtip %}