Issue when adding more then one SQL sensor

Hi all!

I think i have found a bug. I wanted to monitor tables in my HA Database. So, first of all, ive added following manual configuration:

- platform: sql
    db_url: mysql://homeassistant:[email protected]/homeassistant?charset=utf8mb4
    queries:
      - name: HomeAssistant DB Size
        query: 'SELECT table_schema "database", Round(Sum(data_length + index_length) / 1024 / 1024, 1) "value" FROM information_schema.tables WHERE table_schema="homeassistant" GROUP BY table_schema;'
        column: 'value'
        unit_of_measurement: MB
      - name: HomeAssistant States DB Size
        query: 'SELECT table_name AS "Table", ROUND(((data_length + index_length) / 1024 / 1024), 2) AS "Size (MB)" FROM information_schema.TABLES WHERE table_schema = "homeassistant" AND table_name = "states" ORDER BY (data_length + index_length) DESC;'
        column: 'value'
        unit_of_measurement: MB
      - name: HomeAssistant State Attributes DB Size
        query: 'SELECT table_name AS "Table", ROUND(((data_length + index_length) / 1024 / 1024), 2) AS "Size (MB)" FROM information_schema.TABLES WHERE table_schema = "homeassistant" AND table_name = "state_attributes" ORDER BY (data_length + index_length) DESC;'
        column: 'value'
        unit_of_measurement: MB
      - name: HomeAssistant Statistics Short Term DB Size
        query: 'SELECT table_name AS "Table", ROUND(((data_length + index_length) / 1024 / 1024), 2) AS "Size (MB)" FROM information_schema.TABLES WHERE table_schema = "homeassistant" AND table_name = "statistics_short_term" ORDER BY (data_length + index_length) DESC;'
        column: 'value'
        unit_of_measurement: MB
      - name: HomeAssistant Statistics DB Size
        query: 'SELECT table_name AS "Table", ROUND(((data_length + index_length) / 1024 / 1024), 2) AS "Size (MB)" FROM information_schema.TABLES WHERE table_schema = "homeassistant" AND table_name = "statistics" ORDER BY (data_length + index_length) DESC;'
        column: 'value'
        unit_of_measurement: MB
      - name: HomeAssistant Events DB Size
        query: 'SELECT table_name AS "Table", ROUND(((data_length + index_length) / 1024 / 1024), 2) AS "Size (MB)" FROM information_schema.TABLES WHERE table_schema = "homeassistant" AND table_name = "events" ORDER BY (data_length + index_length) DESC;'
        column: 'value'
        unit_of_measurement: MB

But after restart, HA adds only first query (HomeAssistant DB Size), and rest 5 is marked as “Newly found Device - SQL”.
So then, i removed from config (which i don’t like, since i feel better with YAML configuration than UI one), and tried to add SQL integration manually.
One time it works, but second time it claims that “invalid SQL address” :expressionless: And when i left SQL address empty, it says “Invalid SQL statement”.

What is wrong? Looks like bug for me.

The SQL sensor moved to the GUI (Settings → Devices & Services) quite a few versions ago. YAML is no longer supported.

Can you take a screenshot of trying to enter the query using the GUI?

Sure. Here it is.


First one show when i put all data (including DB URL).
Second one is when i put all data without DB URL.
Not really useful i think, just UI removes all my input and marks field on red.
Input data is exactly same as i posted before, just copied from YAML configuration (without apostrophes).

A name goes in the first text box

The URL goes in the second text box.

The query goes in the third. Do not quote the query.

I’m doing exactly like you said:


But this leads me to: