crowbarz / ha-sql_json

Updated SQL integration for Home Assistant that supports JSON attributes
7 stars 2 forks source link

Feature request: query template #2

Closed htmltiger closed 1 year ago

htmltiger commented 4 years ago

Hi,

is it possible to have a query template where we can build a query string based on other sensor state?

for eg query: "SELECT * FROM lookup WHERE Code = {{states('sensor.dx_trip_0')}};" https://community.home-assistant.io/t/add-support-for-query-template-to-sql-integration/188760

Thanks for the useful plugin.

crowbarz commented 3 years ago

Can you try the query-template branch to see if it does what you're asking for? The changes checks whether any of the queries are templates, and if so renders them before running the SQL query.

Due to validation (queries must start with SELECT) and heuristic substitutions (results are limited to 1 unless LIMIT is set) that the upstream integration performs on the query, those parts can't be templatised, though such use cases should be rare.

crowbarz commented 1 year ago

Added in edcf0395c928e71f351d7d1ede97d707e1ea597e