Skip to content

semitop7/telethon2sensor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SWUbanner

HA Lviv PowerOff Logo

⚡️ Telethon2Sensor

Home Assistant Add-on for send notification and create sensor by Telegram chatbot messages listener by Telethon python library. First of all, this application was developed to interact with the Telegram bot from the energy company LvivOblEnergo, but it can be adapted for other Telegram bots.

update-badge

Installation

To add this repository to Home Assistant use the badge below:

Open your Home Assistant instance and show the add add-on repository dialog with a specific repository URL pre-filled.

or add it manually by navigating to Settings > Add-ons > Add-on Store

Select the three dot menu in the upper right, choose Repositories, and add the following url:

https://github.com/semitop7/telethon2sensor

Refresh the page (hard refresh may be required), scroll down to Telethon2Sensor and install the add-on.

Creating your Telegram Application

Follow instructions here documentation. Then you will have access to the data about the application (App api_id, App api_hash), which is required for the addon.

Generate Telegram String Session

For generate telegram string session Use ./utils/session_generator.py

Require python and telethon library

pip install telethon==1.36.0
python ./utils/session_generator.py

If script successfully run you will see request for input. Follow input steps to generate telegram string session.

Enter your API_ID : 

After finished all steps check telegram "Saved Messages" chat to find you telegram string session.

Usage

This integration is configurable via UI.

For testing go to you Telegram chat bot chat and send message like

Шановний клієнте!
На період з 03.08.2024 12:00 до 14:00 заплановані стабілізаційні відключення (застосування ГПВ).

Go to Home Assistant and check Notifications.

Notification

Go to Home Assistant -> Developer Tools -> TEMPLATE tab and check sensor value.

{{ states('sensor.datetime_scheduled') }}

Sensor

Then you can use this sensor in Home Assistant Automations in template trigger.

{% set scheduled_time_3_min_before = as_datetime(states('sensor.datetime_scheduled'), '1987-01-01T00:00:00+03:00' | as_datetime ) - timedelta(minutes=3) %}

{% if scheduled_time_3_min_before <= now() <= scheduled_time_3_min_before + timedelta(minutes=1) %}true{% endif %}

Add-ons

This repository contains the following add-ons:

Supports aarch64 Architecture Supports amd64 Architecture Supports armhf Architecture Supports armv7 Architecture Supports i386 Architecture

Telegram chatbot messages listener for Home Assistant.

About

Home Assistant Add-on for create sensor by Telegram

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages