Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions source/_components/notify.smtp.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Configuration variables:
- **password** (*Optional*): Password for the SMTP server that belongs to the given username. If the password contains a colon it need to be wrapped in apostrophes.
- **recipient** (*Required*): Recipient of the notification.
- **starttls** (*Optional*): Enables STARTTLS, eg. True or False. Defaults to False.
- **product_name** (*Optional*): Sets a 'product name' for the emails headers (*From* = *Custom name <example@mail.com>*, *X-Mailer* = *Custom name*).
- **debug** (*Optional*): Enables Debug, eg. True or False. Defaults to False.

A sample configuration entry for Google Mail.
Expand All @@ -54,6 +55,7 @@ notify:
username: john@gmail.com
password: thePassword
recipient: james@gmail.com
product_name: My Home
```

Keep in mind that Google has some extra layers of protection which need special attention (Hint: 'Less secure apps').
Expand All @@ -79,6 +81,73 @@ To use the SMTP notification, refer to it in an automation or script like in thi

The optional `images` field adds in-line image attachments to the email. This sends a text/HTML multi-part message instead of the plain text default.

The optional `html` field makes a custom text/HTML multi-part message, allowing total freedom for sending rich html emails. In them, if you need to attach images, you can pass both arguments (`html` and `images`), the attachments will be joined with the basename of the images, so they can be included in the html page with `src="cid:image_name.ext"`.

```yaml
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add ` # Example configuration.yaml entry``in the top of this example.

burglar:
alias: Burglar Alarm
sequence:
- service: shell_command.snapshot
- delay:
seconds: 1
- service: notify.NOTIFIER_NAME
data_template:
message: 'Intruder alert at apartment!!'
data:
images:
- /home/pi/snapshot1.jpg
- /home/pi/snapshot2.jpg
html: >
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Intruder alert</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.5/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
<style type="text/css">
@font-face {
font-family: 'Open Sans';
font-style: normal;
font-weight: 300;
src: local('Open Sans Light'), local('OpenSans-Light'), url(http://fonts.gstatic.com/s/opensans/v13/DXI1ORHCpsQm3Vp6mXoaTZS3E-kSBmtLoNJPDtbj2Pk.ttf) format('truetype');
}
h1,h2,h3,h4,h5,h6 {
font-family:'Open Sans',Arial,sans-serif;
font-weight:400;
margin:10px 0
}
</style>
</head>
<body>
<div class="jumbotron jumbotron-fluid" style="background-color: #f00a2d; color: white;">
<div class="container py-0">
<h1>Intruder alert at apartment!!</h1>
</div>
</div>
<div class="container-fluid">
<div class="row">
<div class="col-xs-12 col-md-6 px-0">
<img class="rounded" style="width: 100%;"
alt="snapshot1" src="cid:snapshot1.jpg" />
</div>
<div class="col-xs-12 col-md-6 px-0">
<img class="rounded" style="width: 100%;"
alt="snapshot2" src="cid:snapshot2.jpg" />
</div>
</div>
<br>
</div>
</body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.5/js/bootstrap.min.js"></script>
</html>

```
Obviously, this kind of complex html email reporting is done much more conveniently using Jinja2 templating from an [AppDaemon app](https://home-assistant.io/docs/ecosystem/appdaemon/tutorial/), for example.

This platform is fragile and not able to catch all exceptions in a smart way because of the large number of possible configuration combinations.

A combination that will work properly is port 587 and STARTTLS. It's recommended to enable STARTTLS, if possible.
Expand Down
94 changes: 92 additions & 2 deletions source/_components/notify.telegram.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ The `telegram` platform uses [Telegram](https://web.telegram.org) to delivery no
The requirements are:

- You need a [Telegram bot](https://core.telegram.org/bots). Please follow those [instructions](https://core.telegram.org/bots#6-botfather) to create one and get the token for your bot. Keep in mind that bots are not allowed to contact users. You need to make the first contact with your user. Meaning that you need to send a message to the bot from your user.
- The `chat_id` of an user.
- The `chat_id` of an user, or a list of `user_id`s for sending messages to multiple users.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Separate changes to telegram out to it's own PR.


To retrieve your `chat_id`, contact any of the Telegram bots created for this purpose (@myidbot, @get_id_bot)

Expand Down Expand Up @@ -51,16 +51,39 @@ notify:
platform: telegram
api_key: ABCDEFGHJKLMNOPQRSTUVXYZ
chat_id: YOUR_CHAT_ID

# With more than one authorized target:
notify:
- name: NOTIFIER_NAME
platform: telegram
api_key: ABCDEFGHJKLMNOPQRSTUVXYZ
user_id:
User_name_1: CHAT_ID_USER_1
User_name_2: CHAT_ID_USER_2
```

Configuration variables:

- **name** (*Optional*): Setting the optional parameter `name` allows multiple notifiers to be created. The default value is `notify`. The notifier will bind to the service `notify.NOTIFIER_NAME`.
- **api_key** (*Required*): The API token of your bot.
- **chat_id** (*Required*): The chat ID of your user.
- **chat_id** (*Optional*): The chat ID of your user.
- **user_id** (*Optional*): Multiple chat IDs for multiple users.
- **parse_mode** (*Optional*): Default parser for messages if not explicit in message data: 'html' or 'markdown'. Default is 'markdown'.

To use notifications, please see the [getting started with automation page](/getting-started/automation/).

### {% linkable_title Common message data parameters %}

- **message** (*Required*): Message text.
- **title** (*Optional*): Will be composed as '%title\n%message'.
- **parse_mode** (*Optional*): Parser for the message text: 'html' or 'markdown'.
- **timeout** (*Optional*): If this value is specified, use it as the definitive timeout (in seconds) for urlopen() operations.
- **disable_notification** (*Optional*): Sends the message silently. iOS users will not receive a notification, Android users will receive a notification with no sound.
- **disable_web_page_preview** (*Optional*): Disables link previews for links in the message.
- **reply_to_message_id** (*Optional*): If the message is a reply, ID of the original message.
- **keyboard** (*Optional*): List of rows of commands, comma-separated, to make a custom keyboard.
- **inline_keyboard** (*Optional*): List of rows of commands, comma-separated, to make a custom inline keyboard with buttons with asociated callback data.

### {% linkable_title Photo support %}

```yaml
Expand All @@ -86,6 +109,7 @@ action:
- **username** (*Optional*): Username for a URL which require HTTP basic authentication.
- **password** (*Optional*): Username for a URL which require HTTP basic authentication.


### {% linkable_title Document support %}

```yaml
Expand Down Expand Up @@ -127,3 +151,69 @@ action:
- **latitude** (*Required*): The latitude to send.
- **longitude** (*Required*): The longitude to send.

### {% linkable_title Answering callback queries %}

To send a quick answer when receiving a [callback query event](/_components/telegram_bot.markdown/) sent from an inline keyboard. The answer will be displayed to the user as a notification at the top of the chat screen or as an alert.

```yaml
...
trigger:
platform: event
event_type: telegram_callback
action:
- service: notify.NOTIFIER_NAME
data:
message: "OK, I'm listening"
data:
callback_query:
callback_query_id: '{{ trigger.event.data.id }}'
show_alert: false
```

- **callback_query** (*Required*):
- **callback_query_id** (*Required*): Unique id of the callback response.
- **show_alert** (*Optional*): Show a permanent notification.

### {% linkable_title Editing messages sent previously %}

You can edit a message (`edit_message`) or a image caption (`edit_caption`) from a previusly sent message:

```yaml
...
action:
- service: notify.NOTIFIER_NAME
data_template:
title: '*Message edit*'
message: 'This is the new text of the message'
data:
edit_message:
message_id: '{{ trigger.event.data.message.message_id }}'
disable_notification: true
inline_keyboard:
- '/edit,/NO'
- '/remove button'
...
```

- **edit_message** or **edit_caption** (*Required*):
- **message_id** or **inline_message_id** (*Required*): id of the message to be edited.

or change the keyboard or the inline keyboard of the message of origin (`edit_replymarkup`):

```yaml
...
action:
- service: notify.NOTIFIER_NAME
data:
message: ''
edit_replymarkup:
message_id: 'last'
disable_notification: true
inline_keyboard:
- '/edit,/NO'
...
```

- **edit_replymarkup** (*Required*):
- **message_id** or **inline_message_id** (*Required*): id of the message to be edited.
- **keyboard** or **inline_keyboard** (*Required*): New keyboard.
Loading