What do you think this is?

Just thoughts of a restless mind...

Multiple devices on HA's Signal Add-On

Recently I wanted to set up 2 new Home Assistant instances, and I installed the same add-ons I am using for my "main" instance. They are tested and I have automations built with them; one being the Signal Add-on.

Some background information

Signal is an open source messaging application. Home Assistant, a home automation platform extensible through Add-Ons is what I use for my Home automation needs. When you set up the Signal Add-on in Home Assistant, you need to decide if you will use your "normal" Signal Account, or a different one. Accounts in Signal are simply phone numbers. Using your normal account is not a good idea if you want to send messages to yourself, and my automations are supposed to inform me about changes in my environment.

When I set up my first instance, I registered a second Signal account using my second phone number. Obviously, when I set up the other two instances, I wanted to re-use the same number instead of registering new accounts. Signal allows you to add more than one devices to the same account. The idea behind that, is that you use your Signal account on your phone, on your computer, maybe your tablet etc.

The Signal Add-on is based on the signali-cli-rest-api which is an API around signal-cli. The later one is primarily intended to be used on servers to notify admins of important events.

Registering a second device on an existing account could not be simpler, but I couldn't find complete documentation anywhere. As a result, the first time I tried to do it, I spent almost an hour. Since the task takes (literally) 2 minutes, this is all the clues I need to write this down, in case I forget how to do it in the future.

Needless to say, the numbers, names and keys below are fake and just for illustration.

Adding devices the easy way

By far the easiest way to add a device to an existing Signal account, is using the API. Two steps need to be executed:

  • One step on the device to be added
  • A second step on the initial, main device

All new devices need to be added by executing the second step on the main device.

You will need a linux system with network connectivity to both, the main, and the new HA / Signal Add-on instances. You will also need this system to have curl installed and a tool to read QR codes. I am using zbar-tools as this package is offered in my distro's repository.

Assuming that your Home Assistant instances are named "main" and "secondary", you need to get the device code from the system-to-be-added, the secondary, by executing on your linux machine:

curl -X 'GET' 'http://secondary:8080/v1/qrcodelink?device_name=NewHA' -H 'accept: application/json' | zbarimg -

This will give you a text that looks like: sgnl://linkdevice?uuid=xyzxyzxyzxyzxyzxyzxyzx&pub_key=XYzXyZxyZXYzXyZxyZXYzXyZxyZXYzXyZxyZ

This is the device - specific URI to be used when you register this device on your account. Do that fast, because this URI is only valid for a limited amount of time (I think it's 30 seconds). As a second step, you register the new device by calling on your linux machine:

curl -X 'POST' 'http://main:8080/v1/devices/+01023456789' -H 'accept: application/json' -d '{"uri":"sgnl://linkdevice?uuid=xyzxyzxyzxyzxyzxyzxyzx&pub_key=XYzXyZxyZXYzXyZxyZXYzXyZxyZXYzXyZxyZ"}'

The number after the "devices/" text is your Signal account dedicated to your Home Assistant instances.

Does it work?

Multiple years in IT have tought me that nothing is done until tested. There is an easy way to check if this works, and that is to create a notification in Home Assistant. Add to your new device's configuration.yaml the lines:

notify: - name: signal platform: signal_messenger url: "http://1315902c-signal-messenger.local.hass.io:8080" number: "+01023456789" recipients: - "+01023456788"

This last number (the recipient), should be your "normal" Signal account. After that go to Home Assistant's "Developer Tools" and call the service notify.signal to test.

What if it doesn't work?

Some times things may be wrong, either on the Home Assistant setup or during the registration. The easiest (and at the same time, not so easy) way to troubleshoot is from the Add-on itself. To connect to the Signal Add-on, you need to connect to the Home Assistant OS first. The developers have great documentation on how to do that but in short, you just upload an SSH public key to Home Assistant and connect. Use a USB drive formatted with FAT, ext4, or NTFS and name it CONFIG (case sensitive). Create an authorized_keys file (no extension) containing your public key, and place it in the root of the USB drive. File needs to be ANSI encoded (not UTF-8) and must have Unix line ends (LF), not Windows (CR LF). Use the CLI (eg. SSH to the SSH add-on on port 22) and import the authorized_keys file with the ha os import command. You can now access your device as root over SSH on port 22222.

After connecting to your Home Assistant, you need to identify if the add-on is running, and you can do so by running

docker ps

If the add-on is running, connect to it by executing:

docker exec -it addon_1315902c_signal_messenger /bin/bash

It is advised to switch to the user signal-api by running:

su signal-api

And now you can see the devices connected (the dates should, of course, match your own):

signal-cli -c /data -a +01023456789 listDevices - Device 1 (this device): Name: null Created: 1617145627889 (2021-03-30T23:07:07.889Z) Last seen: 1663459200000 (2022-09-18T00:00:00.000Z) - Device 2: Name: NewHa Created: 1656261125002 (2022-06-26T16:32:05.002Z) Last seen: 1656201600000 (2022-06-26T00:00:00.000Z)

Do you notice the (this device) above? This tells you which device you're connected to. You should run this command once on your main, initially registered device and it will show you Device 1 as "this device". If you see more devices registered, as you would expect to, run the same command on each of the devices you added, to validate that they are all connected.

And that is all...