/homeassistant-mysql_command

A Home Assistant custom component that creates a Notify service to send commands (e.g. INSERT) to a MySQL server.

Primary LanguagePython

HACS Custom GitHub Latest Release GitHub All Releases Community Forum

MySQL Command

A Home Assistant custom component that creates a notify service to send a command to a MySQL server.

Forum Topic: https://community.home-assistant.io/t/mysql-command/539839

Features

  • Send commands to a MySQL server using the Notify platform / service

Installation

Using HACS

This component can be installed using HACS. Please follow directions here and use https://github.com/qrioniclabs/homeassistant-mysql_command as the repository URL.

Manual

  • Copy directory custom_components/mysql_command to your <config dir>/custom_components directory
  • Configure with config below
  • Restart Home Assistant

Configuration

YAML

In configuration.yaml:

notify:
  - name: mysql_command_example_db
    platform: mysql_command
    host: YourHostnameOrIP
    username: YourUser
    password: YourPassword
    db: YourDB

Then, use the service like so:

- service: notify.mysql_command_example_db
      data_template:
        message: >
          INSERT INTO `table` (column1, column2, column3) VALUES ('value1', 'value2', 'value3');

Here is an example with a template timestamp:

- service: notify.mysql_command_example_db
      data_template:
        message: >
          INSERT INTO `table` (datetime, column1, column2) VALUES ('{{ now().timestamp() | timestamp_custom('%Y-%m-%d %H:%M:%S') }}', 'value1', 'value2');

Available configuration parameters

Key Type Required Value Description
platform string true mysql_command Name of a platform
host string true 192.168.1.123 Hostname or IP address of MySQL server
username string true example_user MySQL user with access to the database
password string true aVerySecretPassword Password for the MySQL user
db string true example_db The database that the command is sent to
port int false 3307 The TCP/IP port of the MySQL server. Default: 3306
timeout int false 30 Timeout (in seconds) for the database connection. Default: 10

Special thanks