Skip to content

binse03/Homeassistant-Telegram-Dashboard-Messages

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

10 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🏠 Home Assistant – Telegram Dashboard Messages

❗ Limitations

  1. This cannot display messages from bots due to Telegram's privacy policies.
  2. Only 255 characters can be displayed due to Home Assistant sensor limitations.
  3. This does not work with the Home Assistant Docker installation. You need to use the full Home Assistant OS or supervised installation with Add-ons support.

βœ… Prerequisites

  1. A working Telegram bot.
  2. Your bot's API token and the chat/group ID you want to use.

πŸ“˜ What We're Doing

  1. Telegram triggers an event when a new message is sent in the chat.
  2. Home Assistant receives the trigger and writes the message to a text file.
  3. A virtual sensor reads the last few lines of the text file.
  4. The sensor is then displayed on your dashboard.

βš™οΈ Installation Steps

  1. Install the File Editor Add-on from Home Assistant Add-on Store.

  2. In your Home Assistant config folder, create a new folder, e.g., file_notifications.

  3. Inside that folder, create a new file, e.g., telegram_log.txt.

  4. Open configuration.yaml using the File Editor.

  5. Add the following lines to allow access to your log file:

    homeassistant:
      allowlist_external_dirs:
        - "/your/path/to/txt/"
        - "/config/file_notifications/"
  6. Go to Settings > Devices & Services > Integrations, search for File, and click Add Integration.

  7. Choose Set up a notification service, enter the path to your log file, and click OK.

  8. Go back to the File Editor and open configuration.yaml again.

  9. Add the following configuration for the Telegram bot, notification service, and the virtual sensor:

    # Telegram Integration
    telegram_bot:
      - platform: polling
        api_key: "your_bot_api_token"
        allowed_chat_ids:
          - 123456789         # your personal chat ID
          - -1001234567890    # your group chat ID (note the minus)
    
    notify:
      - platform: telegram
        name: telegram
        chat_id: 123456789  # this should match one of the allowed_chat_ids
    
      - platform: file
        name: file
        filename: /config/file_notifications/telegram_log.txt
        timestamp: false
    
    sensor:
      - platform: command_line
        name: Telegram Virtual Sensor
        command: "tail -n 5 /config/file_notifications/telegram_log.txt"
        scan_interval: 5 

    πŸ“ You can change the tail -n 5 to show more or fewer lines, but remember: sensor values are limited to 255 characters.

  10. Save the file and open automations.yaml.

  11. Add the following automation to write Telegram messages to the log file:

    # automations.yaml
    
    - alias: Telegram Receive β†’ Write to File
      trigger:
        platform: event
        event_type: telegram_text
      action:
        - service: notify.send_message
          data:
            entity_id: notify.file
            message: >
              {{ now().strftime('%Y-%m-%d %H:%M:%S') }} - {{ trigger.event.data.user_id }}: {{ trigger.event.data.text }}

    βœ‚οΈ You can remove the timestamp or user ID in the message to save characters.

  12. Save all files and restart Home Assistant.

  13. Open your Dashboard and add the sensor.telegram_virtual_sensor as an entity card.


πŸ› οΈ Troubleshooting

  • If your sensor shows unknown, try reducing the number of lines read in the tail -n command.
  • Check Settings > System > Logs for detailed error messages.
  • Ensure your bot has the correct permissions and the text file exists at the specified path.

About

Ever wanted to display Groupmessages to your Homeassistent Dashboard?

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors