Hi everyone, I’m trying to get a value from a MySQL Database from the same device where HA is installed.
I want to get it while running an automation and if the value is 0 or 1, run differents actions.
I’ve checked the “The sql sensor platform”, but i think it doesn’t suit me, because i need to get different data in many automations.
Has anyone tried or done something like this? What would be the best way to achieve this? Still kinda new to this.
I haven’t done this myself, but it may be helpful to explain what type of data you’re after.
It’s possible what you’re looking for is available natively in HA, without having to extract it from the database. After all, that’s where the database got it. There are things like state.last_changed which may already have what you’re after. Alternatively, you can set up a template to track a value under whatever specific conditions you are interested in. But without more info these are just wild guesses.
As @CaptTom says. There may be other ways to solve your problem with Home Assistant.
But if you really need values from your SQL database, you should take a look at the SQL Sensor Platform: SQL - Home Assistant (home-assistant.io)
Can you expand on your description of the task you are trying to accomplish? Not enough details presented. From your writing, it seems as though this MySQL database is different from any database that Home Assistant might be using as part of it’s data storage, am I correct?
Example of needing more information from you:
‘but i think it doesn’t suit me, because i need to get different data in many automations.’
The thing is that i have an external neural network algorythm that gets the activity fo the person in the house and saves the information in a MySQL database in the same NUC where i’m running Home Assistant, saving this kind of data:
Then, in an automation about remind the person to take the pills, i want to check if the person has done it by getting the info from the database, to see if the automation needs to tell they to take their pills or not. And same for other activities and automations like eating, shower…
So i can’t use @CaptTom command cause it’s not HA info.
I’ve checked SQL sensor @CM000n, but i’m not sure if i can create many sensors and how it works with this external data.
And @dproffer, hope i gave more useful info about what i’m trying to do. I need an automation to remember the person to take their pills (after checking if they have done it in the database), and maybe for another 10 or more situations and activities.
Shure. You can create multiple sql sensors.
Your database must be accessible for Home Assistant. And you must specify the connection string.
You can use the values from the SQL sensors for further actions in Home Assistant, for example notifications, automations, etc.
I am new babie in home assistant and have similar requirements.
I want to calculate the time the TV is up to apply some rules for the kids.
I have integrated the Mariadb and the notifications are now stored in db. Idea is to run the automation every day at night and calculate the time and send the email using gmail integration.
I am able to setup SQL sensor but struggling to call from automation. any help is appreciated.