Writing values to DB

Hello everyone. I need to write the value of input_number to the table in Maria DB by pressing the input_button. I’m trying to do it through automation.

       action:
         - service: sql.query
           data:
             db_url: "mysql://homeassistant:homeassistant@core-mariadb/homeassistant?charset=utf8"
             query: >-
               INSERT INTO my_data (adding_time, my_data, my_number)
               VALUES (
                 '{{ now().strftime("%Y-%m-%d %H:%M:%S") }}',
                 '{{ states('input_datetime.my_data') }}',
                 {{ states('input_number.my_number') | int }},
               );

I get an error:

Error executing script. Service not found for call_service at pos 1: Action sql.query not found

Did I set something up wrong or does it not do this at all?

Did you see this thread?
MySQL Command - Share your Projects! - Home Assistant Community

Which integration is supposed to provide that service?

1 Like

Thank you very much. That’s what I needed.
And how can I display the last three lines from the table in the interface as a table?

There are probably ways to push the values into an array, but I don’t know an SQL-way to do that.

With my limited knowledge I’d have to create two (history) helpers for every entity and rotate the values through them, i.e.

input_datetime.my_data => input_datetime.my_data-1 => input_datetime.my_data-2