Hi,
I decided to set up the Signal Messenger to receive notifications from my HA instance, so that I get “push notification” on my phone. Why I did this?
- Works with iOS, Android and Linux/Mac/Windows (with the Signal Desktop Client)
- Works with basic authentication on my nginx proxy (html5 notifications do not)
- It is secure (Pushbullet actually sounds pretty fishy when it comes to security)
- It’s free
So if you are also interested in setting this up, here is how I did it.
Setup Signal Messenger for HA Notifications
-
Install the Signal App on your phone and register your number
-
Download the Signal-Cli https://github.com/AsamK/signal-cli from github. There is also a link to precompiled binaires, so you don’t have to take care of this yourself.
-
Register your cellphone number, also described here https://github.com/AsamK/signal-cli (I used a different one than the one on my phone). To do this, you need to receive a text message this number. This has to be done only once! (Details in the Signal-Cli description)
-
Try to send yourself a message with
./signal-cli -u [number of sender] send -m "Testmessage" [receivernumber]
Note that you have to include your country code. So the numbers start with +xxx (+49 for Germany). I didn’t try yet, what happens if sender and receiver share the same number. -
If this works, we connect the signal-cli with homeassistant. I adjusted a notification script which you see below.
Place this inhomeassistant/components/notify/signalmessenger.py
and adjust yourcustomize.yaml
. -
You’re done! You can now use automations to send yourself a Signal message
Currently, only one receiver can be set. You can “hack” this by instantiating the notifier for each receiver.
Have fun trying it, feedback is appreciated!
Config Files
# configuration.yaml
notify:
- name: [choose your notification name
platform: signalmessenger
sender_nr: "+0987654321"
recp_nr: "+1234567890"
signal_cli_path: /home/user/signal-cli
"""
Signal Messenger for notify component.
Place this in `homeassistant/components/notify/signalmessenger.py`
"""
import pathlib
import subprocess
import logging
import voluptuous as vol
from homeassistant.components.notify import (
ATTR_DATA, ATTR_TITLE, ATTR_TITLE_DEFAULT, PLATFORM_SCHEMA,
BaseNotificationService)
from homeassistant.const import CONF_API_KEY
import homeassistant.helpers.config_validation as cv
REQUIREMENTS = []
_LOGGER = logging.getLogger("signalmessenger")
CONF_SENDER_NR = 'sender_nr'
CONF_RECP_NR = 'recp_nr'
CONF_SIGNAL_CLI_PATH = 'signal_cli_path'
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Optional(CONF_SENDER_NR): cv.string,
vol.Optional(CONF_RECP_NR): cv.string,
vol.Optional(CONF_SIGNAL_CLI_PATH): cv.string,
})
def get_service(hass, config, discovery_info=None):
"""Get the Join notification service."""
sender_nr = config.get(CONF_SENDER_NR)
recp_nr = config.get(CONF_RECP_NR)
signal_cli_path = config.get(CONF_SIGNAL_CLI_PATH)
if sender_nr is None or recp_nr is None or signal_cli_path is None:
_LOGGER.error("No device was provided. Please specify sender_nr"
", recp_nr, or signal_cli_path")
return False
return SignalNotificationService(sender_nr, recp_nr, signal_cli_path)
class SignalNotificationService(BaseNotificationService):
"""Implement the notification service for Join."""
def __init__(self, sender_nr, recp_nr, signal_cli_path):
"""Initialize the service."""
self.sender_nr = sender_nr
self.recp_nr = recp_nr
self.signal_cli_path = path.join(signal_cli_path, "signal-cli")
def send_message(self, message="", **kwargs):
"""Send a message to a user."""
# Raise an Exception if something goes wrong
p = subprocess.Popen([self.signal_cli_path, "-u", self.sender_nr, "send", "-m", message, self.recp_nr], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
# Wait for completion
p.wait()
output, err = p.communicate()
ret = p.returncode
if ret != 0:
raise Exception("Signal Error {}".format(ret))
Troubleshooting
During this setup i encountered some issues that I had to solve that I want to share with you.
- Make sure you can receive a textmessage on the number that you use in the registration process.
- If you try signal-cli on your local machine and you want to use it on your pi/server/nas afterwards, copy also
/home/user/.config/signal
to the new location. - Signal-cli takes ages to send a message? Then your entropy is probably too low required for the crypto stuff. Check with
cat /proc/sys/kernel/random/entropy_avail
It should be > 1000. If not you can installhaveged
.
!! But I did not check in detail what havegd does with your random number generator, so do this on your own risk !! - It is worth to take a look at the issued of the signal-cli repo https://github.com/AsamK/signal-cli
Edit: Fixed the points that @nhok mentioned. Thanks!