This tutorial is about setting up OpenHab to send messages via Signal messenger. It is based on this (german) and this Java client. (Please forgive and correct any linux specific errors - I am only a basic linux guy )
Notes/Prerequisites
- I used a raspberry based on Raspbian Jessie (paths can vary on other systems) with OpenHab 2.2 stable and Zulu JRE
- You need a free phone number to send messages including the international prefix. (e.g. +491231234567 - I used my landline)
- You will need the exec binding to run scripts from openhab
Install Signal client
The steps to install the signal client are described on github. The following steps are based on the version available at this time (0.6.2):
- Prepare directory:
mkdir /var/lib/signal-cli
- Download & install
cd /tmp curl -L https://github.com/AsamK/signal-cli/releases/download/v0.6.2/signal-cli-0.6.2.tar.gz tar xf signal-cli-0.6.2.tar.gz -C /opt ln -sf /opt/signal-cli-0.6.2/bin/signal-cli /usr/local/bin/
- configure JRE with unlimited strength crypto (If you do not do this, you will receive an
InvalidKeyException
when sending a message.- For the Zulu JRE (recommended by Openhab) download the policies from here and unzip to
/usr/lib/jvm/zulu-embedded-8-armhf/jre/lib/security/
- For the Oracle JRE follow the steps from Stackoverflow
- For the Zulu JRE (recommended by Openhab) download the policies from here and unzip to
- Register a phone number (you need the full number including international prefix). You will receive a call where a voice tells you a verification code, which you need to write down.
sudo signal-cli --config /var/lib/signal-cli -u <PHONE NUMBER> register --voice
- Verify your account
sudo signal-cli --config /var/lib/signal-cli -u <PHONE NUMBER> verify <VERIFICATION CODE>
- change permissions to the config file, so that any user on the system can send messages
sudo chmod a+rw /var/lib/signal-cli/data/*
- Test Signal client (you need a destination phone number to send a message to)
signal-cli --config /var/lib/signal-cli -u <PHONE NUMBER> send -m "Hello from Signal ;-)" <DESTINATION PHONE NUMBER>
- If you get an
InvalidKeyException
follow step 3 and check your JRE.
- If you get an
Create script to run from openhab
This tutorial uses the exec binding to run the script.
- create a script file named
send-signal.sh
in the openhab script directory (I assume/etc/openhab2/scripts
) with the following content (replace<phone number>
with your number)#!/bin/bash # Usage: send-signal.sh <recipient number> 'message to send' /usr/local/bin/signal-cli --config /var/lib/signal-cli -u <PHONE NUMBER> send -m "$2" $1
- allow execution of script file
chmod +x send-signal.sh
Integrate in openhab
I use a string item and a rule which sends a message when the item is changed - a script binding would also be possible.
- Item:
String SendMessage
- Rule
rule "Send message via signal"
when
Item SendMessage received command
then
if(SendMessage.state !== null)
{
var String command = '/etc/openhab2/scripts/signal.sh '
executeCommandLine(command + "<DESTINATION PHONE> '" + SendMessage.state.toString + "'", 60000)
}
end