name: Einträge Multi-Sensoren mit Temperatur -100.0 Grad
database URL: sqlite:////home/user/.homeassistant/config/home-assistant_v2.db (shouldn’t be needed according to docs cause I use the default one - anyway, when leaving it blank the form will complain about it)
column: Anzahl
statement:
SELECT COUNT (*)
FROM 'states'
WHERE entity_id LIKE 'sensor.multi_%_temperature' AND state='-100.0'
ORDER BY entity_id ASC, last_updated DESC;
The problem is: the form doesn’t accept the SQL statement, it always returns “SQL statement invalid” and resets all fields:
The SQL statement is working just fine in the SQLite Web. I really tried every constellation (used state as column, put the SQL statement in one line, tried " / ', …) - NOTHING is working. → What’s wrong with it? → Certain syntax needed for the SQL integration?
Next problem i see is that you order by colums that are not returned by you query.
Try:
SELECT COUNT(*) as Anzahl, entity_id, last_updated
FROM states
WHERE entity_id LIKE 'sensor.multi_%_temperature' AND state='-100.0'
ORDER BY entity_id ASC, last_updated DESC;
BTW, i also removed the space in count (*) and the quotes around 'states' to test your query without errors in my sql client.
I use mariadb, but most of the syntax is mostly the same.
I don’t use that initial SQL statement as the ordering is useless when counting.
It must be a bug in the UI because:
Create a new SQL integration with SQL statement SELECT COUNT (*) AS Anzahl FROM states;
→ That works just fine, integration is being created
Change the configuration of the existing SQL integration by changing the SQL statement to SELECT COUNT (*) AS Anzahl FROM states WHERE "entity_id" LIKE "sensor.multi_%_temperature" AND state="-100.0";
→ Now this is also working! Which it doesn’t when being used at the integration form.
So to summarize:
The exact same SQL statement is not accepted when being used initially.
The exact same SQL statement is accepted when changing an existing SQL integration configuration.
I can not confirm the “rumors” about double quotes, single quotes, no quotes - as my double quotes example finally worked (on the 2nd attempt).
I’d tend to call this either an UI integration or documentation disaster - or there’s another issue specific to my setup, which I don’t think so.
I meanwhile created a few other sensor. It always behaves the same (weird). Unfortunately I don’t remember the exact „trick“ which worked and works for me.
According to your screenshot I‘d say at least the database URL is missing. What error/message is shown?
That’s the last one I created. UI shows the configure/edit mode once it has been created. So I think database was always needed:
There we go: although the UI says: ‘Leave DB Url empty for standard HA database’, It appears I do have to fill it in completely (including credentials for my SQL connection). Thanks!