Store mqtt data into db

Hello guys!

I’m currently working on a project where I have a arduino which is delivering the current temperature to the mosquitto broker (running on home-assistant).

I can already read the data transmitted to the broker with a client running on my pc.

Now I’m trying to get this data (temperature) into a database.
At the moment I have the mariadb running (started with the ADD-ON STORE).

In my configuration.yaml file I have the following:

#automation:
automation:
trigger:
platform: mqtt
topic: /topic/qos1
action:
service: shell_command.todb

shell_command:
todb: ‘python3 /config/todb.py’

As far as I can see the script isn’t even starting.
Can you guys help me how to get this running?

best regards,
Floh

Your shell command won’t run unless you tell it to.
Use an automation to start it with HA (I guess it goes into a loop by itself)
Alternatively you can add the recorder component and configure it to record to a MariaDB, you’ll get exactly that.

It is already placed in a database, you are replicating what home assistant does already.

Please elaborate…
which database ?
how do I get access to the data received via the mosquito broker, in which db is it stored for long term.
I’d still like to be able to decide how where i want to start it via a python script as depending on conditions I might want to put it to a MariaDB or into a InfluxDB to be displayed via Grafana.
G

You can also use a MQTT sensor to get the MQTT stuff into a sensor (and hence the db). I was using this to create a usage sensor for my ISP usage using mosquitto_pub in a shell command and then a MQTT sensor to get data from the broker into a sensor.

I ended up abandoning doing it like that because hass.io doesn’t have mosquitto_pub available… I still have the working scripts here in my repo though. Look in the first file - the zip file for instructions and the scripts.

Sorry, forgot to say MQTT broker is installed on the hass.io build to which i can publish.

G

Well look at my repo and you can see how to get the mqtt topics into HA as sensors or in my case as a sensor with attributes.

thanks will do.
but thats not my question above.
my question is more in the direction of, should i run my entire consolidation of information and graphs on the HA platform, or should i push all energy values to OeM and graph there and just run the workflow and sonoff switching on the Ha.

G

Well you asked about getting access to the data for the long term and once it’s a sensor you get history of the state…

sorry… I’m the confused one, getting confused between different posts.
I was asking, “which database” based on the comment: “It is already placed in a database, you are replicating what home assistant does already.”

G

ah gotcha… nickrouts reply, not mine. You need a sensor to get it into the HA database…