
Viewing MySQL queries in Home Assistant
If we have a database out there with curious data and we want to visualize them in our Home Assistant… This is your post! We will see how we can easily make inquiries to BD, in this example it will be a MySQL where we will integrate it with Hassio, And we'll see in the end how cool it is.
In my particular case I have a database in MySQL with quite a few tables where I store various values with states of a lot of gadgets, If you have followed the blog, You may already know that I store metrics from quite a few sensors, humidity, temperature, pressure, Scales, Fitbit Themes… I leave you with a couple of examples to give you an idea of how little it will cost us, and it is only in the same configuration file of Home Assistant or Hassio where we will register as sensors each query we want to make, As I said:
- Platform: SQL db_url: Mysql://USUARIO_BD:CONTRASEÑA@SERVIDOR_BBDD/NOMBRE_BD queries: - Name: Moisture query: 'SELECT humedad from temp_cocina order by fecha DESC LIMIT 1;' column: 'humedad' unit_of_measurement: '%' - Platform: SQL db_url: Mysql://USUARIO_BD:CONTRASEÑA@SERVIDOR_BBDD/NOMBRE_BD queries: - Name: Temperature Street query: 'SELECT ROUND(street,2) as t_calle FROM temp_calle ORDER BY DESC LIMIT date 1;' column: 't_calle' unit_of_measurement: 'ºC'
After saving the configuration file and restarting Home Assistant we can edit the interface and add the SQL sensors, In addition, we can customize the icon we want it to have, for this, remember that we can click on the dots > “Configure the user interface” > We click again on the three dots > “Raw Configuration Editor”. There below each entity we will add the icon that we like, we can get quite a few in www.materialdesignicons.com.
And this would be a snapshot of how we would see the results of our database queries, It's really cool, ¿No? Little by little it takes on color. Thank you for following the posts and sharing them on social media, I hope you are interested.