Code Monkey home page Code Monkey logo

teslamate-telegram-bot's Introduction

TeslaMate Telegram Bot

CI version docker pulls image size Donate

This is a telegram bot written in Python to notify by Telegram message when a new SW update for your Tesla is available. It uses the MQTT topic which TeslaMate offers.

Screenshots

Telegram Message: SW Update available

Table of contents

Features

  • Sends a telegram message to you if an update for your tesla is available

Requirements

Installation

Make sure you fulfill the Requirements.

It is recommended to backup your data first.

This document provides the necessary steps for installation of TeslaMate Telegram Bot on an any system that runs Docker.

This setup is recommended only if you are running TeslaMate Telegram Bot on your home network, as otherwise your telegram API tokens might be at risk.

  1. Create a file called docker-compose.yml with the following content (adopt with your own values):

       services:
         teslamatetelegrambot:
           image: teslamatetelegrambot/teslamatetelegrambot:latest
           restart: unless-stopped
           environment:
             # - CAR_ID=1 # optional, defaults to 1
             - MQTT_BROKER_HOST=IP_Address # defaults to 127.0.0.1
             # - MQTT_BROKER_PORT=1883 #optional, defaults to 1883
             # - MQTT_BROKER_USERNAME=username #optional, only needed when broker has authentication enabled
             # - MQTT_BROKER_PASSWORD=password #optional, only needed when broker has authentication enabled
             # - MQTT_NAMESPACE=namespace # optional, only needed when you specified MQTT_NAMESPACE on your TeslaMate installation
             - TELEGRAM_BOT_API_KEY=secret_api_key
             - TELEGRAM_BOT_CHAT_ID=secret_chat_id
           ports:
             - 1883
           build:
             context: .
             dockerfile: Dockerfile
  2. Build and start the docker container with docker compose up. To run the containers in the background add the -d flag:

    docker compose up -d

Update

Check out the release notes before upgrading!

Pull the new images:

docker compose pull

and restart the stack with docker compose up. To run the containers in the background add the -d flag:

docker compose up -d

Contributing

All contributions are welcome and greatly appreciated!

Donation

Maintaining this project isn't effortless, or free. If you would like to kick in and help me cover those costs, that would be awesome. If you don't, no problem; just share your love and show your support.

Donate with PayPal

Disclaimer

Please note that the use of the Tesla API in general and this software in particular is not endorsed by Tesla. Use at your own risk.

teslamate-telegram-bot's People

Contributors

dependabot[bot] avatar jakoblichterfeld avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

teslamate-telegram-bot's Issues

Python implementation

The proof of conecpt (#1) shows it works, perfect.
Let us implement it in python, as there are libraries for mqtt and telegram bot available for cool features in the future.

Proof of Concept

As a user I want to be informed when an update is available for my Tesla car. This can be done by messaging service to my mobile.

I do not want do have a full weight automation such as Openhab2, HomeAssist, NodeRed, ... running.

If environment variable validation fails, CPU usage is very high

Today after updating to version 0.7.2 and 0.7.3, which caused issues #33 and #35, my server CPU usage was constantly at >90%. Probably there is an endless loop running trying to validate the config again and again.
After I stopped the (broken) teslamatetelegrambot container, CPU usage returned to normal:

Screenshot 2024-03-21 at 13 43 11

MQTT namespace variable

Its possible to define a mqtt namespace variable in teslamate.

MQTT_NAMESPACE=

If it is defined, the telegram bot won't notify the update, because its looking in a wrong topic.

teslamate/$namespace/cars/2/inside_temp

would work then.

UnboundLocalError: cannot access local variable 'message_text' where it is not associated with a value

v0.7.3 runs on test system, fails on production with:

teslamatetelegrambot | Traceback (most recent call last):
teslamatetelegrambot | File "/app/./src/teslamate_telegram_bot.py", line 227, in
teslamatetelegrambot | asyncio.run(main())
teslamatetelegrambot | File "/usr/local/lib/python3.12/asyncio/runners.py", line 194, in run
teslamatetelegrambot | return runner.run(main)
teslamatetelegrambot | ^^^^^^^^^^^^^^^^
teslamatetelegrambot | File "/usr/local/lib/python3.12/asyncio/runners.py", line 118, in run
teslamatetelegrambot | return self._loop.run_until_complete(task)
teslamatetelegrambot | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
teslamatetelegrambot | File "/usr/local/lib/python3.12/asyncio/base_events.py", line 685, in run_until_complete
teslamatetelegrambot | return future.result()
teslamatetelegrambot | ^^^^^^^^^^^^^^^
teslamatetelegrambot | File "/app/./src/teslamate_telegram_bot.py", line 205, in main
teslamatetelegrambot | await check_state_and_send_messages(bot, chat_id)
teslamatetelegrambot | File "/app/./src/teslamate_telegram_bot.py", line 172, in check_state_and_send_messages
teslamatetelegrambot | await send_telegram_message_to_chat_id(bot, chat_id, message_text)
teslamatetelegrambot | ^^^^^^^^^^^^
teslamatetelegrambot | UnboundLocalError: cannot access local variable 'message_text' where it is not associated with a value
teslamatetelegrambot exited with code 0

feat: allow negative chat_id, which means group chats

After upgrading to v0.7.3 I am now getting this error:

ERROR - Error: Please set the environment variable TELEGRAM_BOT_CHAT_ID to a valid number and try again.

My env variable:

TELEGRAM_BOT_CHAT_ID=-410996XXX

XXX are more digits, removed for privacy. I guess the issue is that it is a negative number. Also doesn't work if I wrap it in double quotes.

deployment-as-docker

Thanks for config with files (#4). It would be cool to have it as a docker container, so no need to take care about requirments and so on as a user.

config-with-files

Thanks for the python implemantation (#2), to edit the source code for my own config is not the prefered way. Can we have the confi in one or more additional files?

`car_id` 'int' object has no attribute 'isdigit'

After upgrading to v0.7.2 I am getting the following error (with and without setting the CAR_ID env variable):

teslamate-teslamatetelegrambot-1  | Traceback (most recent call last):
teslamate-teslamatetelegrambot-1  |   File "/app/./src/teslamte_telegram_bot.py", line 64, in <module>
teslamate-teslamatetelegrambot-1  |     if not car_id.isdigit() or int(car_id) < 1:
teslamate-teslamatetelegrambot-1  |            ^^^^^^^^^^^^^^
teslamate-teslamatetelegrambot-1  | AttributeError: 'int' object has no attribute 'isdigit'
teslamate-teslamatetelegrambot-1  | Traceback (most recent call last):
teslamate-teslamatetelegrambot-1  |   File "/app/./src/teslamte_telegram_bot.py", line 64, in <module>
teslamate-teslamatetelegrambot-1  |     if not car_id.isdigit() or int(car_id) < 1:
teslamate-teslamatetelegrambot-1  |            ^^^^^^^^^^^^^^
teslamate-teslamatetelegrambot-1  | AttributeError: 'int' object has no attribute 'isdigit'
teslamate-teslamatetelegrambot-1  | Traceback (most recent call last):
teslamate-teslamatetelegrambot-1  |   File "/app/./src/teslamte_telegram_bot.py", line 64, in <module>
teslamate-teslamatetelegrambot-1  |     if not car_id.isdigit() or int(car_id) < 1:
teslamate-teslamatetelegrambot-1  |            ^^^^^^^^^^^^^^
teslamate-teslamatetelegrambot-1  | AttributeError: 'int' object has no attribute 'isdigit'
teslamate-teslamatetelegrambot-1  | Traceback (most recent call last):
teslamate-teslamatetelegrambot-1  |   File "/app/./src/teslamte_telegram_bot.py", line 64, in <module>
teslamate-teslamatetelegrambot-1  |     if not car_id.isdigit() or int(car_id) < 1:
teslamate-teslamatetelegrambot-1  |            ^^^^^^^^^^^^^^
teslamate-teslamatetelegrambot-1  | AttributeError: 'int' object has no attribute 'isdigit'
teslamate-teslamatetelegrambot-1  | Traceback (most recent call last):
teslamate-teslamatetelegrambot-1  |   File "/app/./src/teslamte_telegram_bot.py", line 64, in <module>
teslamate-teslamatetelegrambot-1  |     if not car_id.isdigit() or int(car_id) < 1:
teslamate-teslamatetelegrambot-1  |            ^^^^^^^^^^^^^^
teslamate-teslamatetelegrambot-1  | AttributeError: 'int' object has no attribute 'isdigit'
teslamate-teslamatetelegrambot-1  | Traceback (most recent call last):
teslamate-teslamatetelegrambot-1  |   File "/app/./src/teslamte_telegram_bot.py", line 64, in <module>
teslamate-teslamatetelegrambot-1  |     if not car_id.isdigit() or int(car_id) < 1:
teslamate-teslamatetelegrambot-1  |            ^^^^^^^^^^^^^^
teslamate-teslamatetelegrambot-1  | AttributeError: 'int' object has no attribute 'isdigit'

Btw: there is a typo in the filename teslamte_telegram_bot.py

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.