From the Node-RED website:
Node-RED is a programming tool for wiring together hardware devices, APIs and online services in new and interesting ways.
It provides a browser-based editor that makes it easy to wire together flows using the wide range of nodes in the palette that can be deployed to its runtime in a single-click.
This integration guide assumes that Teslamate is deployed on docker and that Node-RED will not be exposed to the internet. Of course, you can install Node-RED outside of Docker and on another server, if that suits. The integration with Teslamate is entirely via MQTT. Notifications included in the examples are sent using available Node-RED modules for email and Telegram. Other notifications (e.g. Slack) are relatively simple by replacing the final node in the Notifications flow. One could also integrate with public tools such as IFTT. Or get really creative and integrate with Alexa or Google Assistant to control the car by voice. :)
Creation of the Telegram bot is not covered in this guide; there is plenty of documentation on the net explaining how to do this (links are provided in the Requirements section below). However, the configuration of the Telgram node in Node-RED is described below.
Included are Node-RED flows with two examples:
- A simple Node-RED dashboard with Car Status and Charge Status panels
- Notification logic for state changes, entering/exiting geofences and time remaining to charge.
|Example Telegram Notifications
- Teslmate environment, preferably installed in Docker (if you are new to Docker, see Installing Docker and Docker Compose)
- Access by Node-RED to the internet to send notifications
- A mobile device with Telegram client installed or use Telegram's browser interface
- your own Telegram Bot, see Creating a new telegram bot
- your own Telegram chat id, see Get your Telegram chat ID
Visit the Node-RED Getting Started page for the various deployment options. If you are using Docker, the following section should suffice to get running.
Add the following parameters to your
docker-compose.yml file. It's assumed that your timezone in set in the .env file's TM_TZ environment variable.
Build and start the docker container with
docker compose up. To run the containers in the background, add the
docker compose up -d
There are two flows in the example exports provided. The first flow creates a simple dashboard with some of the MQTT values. The second flow sends notifications to Telegram. The flow names are "Car Dashboard" and "Notifications".
After bringing up the Node-RED container the first time, save the following shell script to a file (e.g. named add-nr-modules.sh, then run
bash ./add-nr-modules.sh) to install modules required for the example flows:
for MODULE in $MODULES
docker compose exec -T node-red npm install --no-audit --no-update-notifier --no-fund --save --prefix=/data --production $MODULE
docker compose stop node-red
docker compose start node-red
Note that if your function nodes need additional NPM packages, you can add those into 'MODULES'. You can import those in the function node 'Setup' page, like add module 'linq-js' and import it as variable 'Enumerable'.
- Download the example JSON file Node-RED-Teslamate-flows.json
- Go to Node-RED's hamburger menu in the upper right corner and select
- Use the
select file to importbutton on the pop-up to upload the JSON file.
If you are using the standard MQTT docker configuration as per the Teslamate installation guide, after you import the flows Node-RED should automatically connect. Otherwise, open the
teslamate/cars/1/# node in the Car Dashboard flow, select the pencil icon next to the
Server field in the panel, then edit the MQTT server's parameters. Click Update, Done and Deploy.
To enter your Telegram Bot's parameters:
- Edit the
Status MessagesTelegram node in the Notifications flow, then select the pencil icon next to the
- Replace the
Bot-Namefield with the name of your Telegram bot
- Fill the
Tokenfield with the value that you copied from setting up your bot.
|Telegram configuration pop-up
- Edit the
Format messagesnode in the Notifications flow
- Replace the value for
chatIdwith the chatId that you obtained setting up the bot.
Deployto re-deploy your flows. "Connected" should now display beneath the
If you want to quickly try out this implementation without Telegram, you can simply remove the connection between the
Format Messages and
Status Messages nodes, then connect
Format Messages with the
- When you re-deploy your flows, a Tesla entered Geofence ... message and a Tesla Driver is present: notification may be sent. Some might consider this a bug. Or a test that the notification channel is working. :)