What error are you getting?
I just added this sensor and am getting an error no such function: pg_database_size.
I am using PostgresSQL - and followed the SQL sensor component instructions.
It works great with my postgresql database, but with SQL Server if fails. I beleive it’s due to the coded in LIMIT 1 which does not work in SQL Server. Instead of LIMIT 1 SQL Server may use “SELECT TOP 1 columns FROM database”.
Is this something that can be changed at the integration end at some point in time? If you want me to post this on github please let me know, but I would need some guidance as to where as I am not familiar with the platform.
hi everyone, i’m trying to create a sensor from an sqlite query but it wont work and i don’t know why
here is my sensor config
sensor:
- platform: sql
db_url: sqlite:////config/home-assistant_v2.db
scan_interval: 10
queries:
- name: test
query: "SELECT substr(attributes,147,4) FROM states WHERE domain LIKE 'climate' ORDER BY created DESC LIMIT 1;"
column: "attributes"
unit_of_measurement: "#"
and here is my sqlite query
sqlite> SELECT substr(attributes,147,4) FROM states WHERE domain LIKE 'climate' ORDER BY created DESC LIMIT 1;
17.5
it return the temp value i’m looking for but why it didnt succeed with my sensor ?
i’ve tried db_url: sqlite:////home-assistant_v2.db or /home-assistant_v2.db or /usr/share/hassio/homeassistant/home-assistant_v2.db path but none of them seems to work and all are unknown as sensor value
is there any other way to make this working ?
thx
regards
i finaly succed to make it work,
i was pretty sure that the issue was caused by my substring but the sqlite db engine seem to be ok with it so i 've been trying to format the result in a way it could be handled in some automation thereafter
and in fact , i’ve succeed to format it correcly with something like
{% set temp = states('sensor.test') |from_json %}
{{ temp.temperature }}
but in fact the issue was my column value that should be
column: "substr(attributes,147,4)"
instead of
column: "attributes"
so here is my complete sensor configuration
sensor:
- platform: sql
db_url: sqlite:////config/home-assistant_v2.db
scan_interval: 10
queries:
- name: test
query: "SELECT substr(attributes,147,4) FROM states WHERE domain LIKE 'climate' ORDER BY created DESC LIMIT 1;"
column: "substr(attributes,147,4)"
unit_of_measurement: "#"