SQL “Delete” command

Hello all,

is it possible to execute a SQL “Delete” command via an automation?

Example:

Delete  FROM   states  WHERE state LIKE 'unknown'
1 Like

look into: https://www.home-assistant.io/integrations/sql/

Never used it nor done a delete. I’ve used a SQLite viewer and deleted that way, but that was the only time.

Thank you.

This I tried already. Only Select is possible.

Invalid config for [sensor.sql]: Only SELECT queries allowed for dictionary value @ data['queries'][0]['query']. Got "Delete FROM states WHERE state LIKE 'unknown';". (See ?, line ?).

Hello
I’d like to do the same. Have you found a work around?

Not yet :frowning:

I don’t know of a good way to do this but I do know of a hacky way to do this. The SSH & Web Terminal add-on comes with mysql installed. So you can use a shell command which actually ssh’s into that add-on and executes your delete command there by passing it into mysql.

I used a similar trick a while ago when I was trying to figure out how to backup my Nginx Proxy Manager config without actually backing up the MariaDB add-on (since it stores its config in there).