Skip to content

Instantly share code, notes, and snippets.

@vladyspavlov
Created November 2, 2023 21:37
Show Gist options
  • Save vladyspavlov/74d25856a58e252a1acee392286b7207 to your computer and use it in GitHub Desktop.
Save vladyspavlov/74d25856a58e252a1acee392286b7207 to your computer and use it in GitHub Desktop.
ESPHome Telegram bot send message example
substitutions:
TELEGRAM_BOT_TOKEN: !secret telegram_bot_token
api_key: !secret api_key
ota_password: !secret ota_password
chat_id: xxxxxxxxx
esphome:
name: wemos
friendly_name: wemos
esp8266:
board: d1_mini_pro
# Enable logging
logger:
# Enable Home Assistant API
api:
encryption:
key: ${api_key}
ota:
password: ${ota_password}
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
captive_portal:
status_led:
pin: GPIO2
http_request:
useragent: esphome/device
timeout: 10s
button:
- platform: template
name: Send Telegram message
on_press:
- http_request.post:
url: "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage"
headers:
Content-Type: application/json
json:
chat_id: ${chat_id}
text: Message from ESPHome
verify_ssl: false
@xxgmxx
Copy link

xxgmxx commented Mar 1, 2024

Wow, that's simply great! I am so happy you shared your config with us :)

@stheid
Copy link

stheid commented Mar 19, 2024

ok, that was simple. nice! Thanks for sharing

@eledetrans
Copy link

Hi.
I try to run this example and i received this error

Error: connection refused
[E][component:164]: Component http_request set Error flag: unspecified
[E][component:176]: Component http_request cleared Error flag

can you help me?

Thanks

@stheid
Copy link

stheid commented Jul 23, 2024

I suggest debugging the http request first before moving on to esphome. I suggest trying out a tool like "bruno" for that. If you have verified that your request is correct and your bot is responding as planned, than you can continue with the yaml.

@eledetrans
Copy link

I put the same example to connect with telegram api and return this error.

@stheid
Copy link

stheid commented Jul 23, 2024

with chatid: xxxxx? Again, setting up the bot (which is nessesary for this to work) is not so trivial and i'd suggest verifying that all ids are correct before continuing with the esphome

@eledetrans
Copy link

no i change the correct chat_id. is a group id but i test the conection to connect via web url and connect correctly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment