XaF / qolsysgw

Qolsys IQ Panel 2+ gateway to an Home Assistant Alarm Control Panel
MIT License
116 stars 11 forks source link
appdaemon automation hacs home-assistant home-automation qolsys

Qolsys Gateway - qolsysgw

build hacs validation latest release

Qolsys Gateway (qolsysgw) is an AppDaemon automation that serves as a gateway between a Qolsys IQ Panel (2, 2+ or 4) and Home Assistant. Qolsys Gateway works by establishing a connection to your Qolsys Panel and uses the MQTT integration of Home Assistant. It takes advantages of the MQTT discovery feature (automatically enabled when you setup the integration) to declare the device, alarm control panels (for each partition) and different sensors, and keep them up to date with the information coming from the panel, while providing you with the means to arm, disarm or trigger your alarm directly from Home Assistant, manually or through automations.

How It Works

Qolsys Gateway is an async application and has a few parallel workflows:

  1. The communication with the Qolsys Panel

    1. Qolsys Gateway connects to your Qolsys Panel using the configured information (hostname, token, port), thanks to a Control4 interface

    2. As soon as the connection is established, Qolsys Gateway requests from the panel the information on the current state of the panel, its partitions and sensors

    3. Qolsys Gateway listens for messages from the panel, and calls a callback method everytime a message can be parsed to an executable action; the callback will push that message in an MQTT thread (that step is not mandatory but doing that loop allows to debug the application from Home Assistant by sending events directly in MQTT)

    4. Every 4 minutes, a keep-alive message is sent to the connection, in order to avoid the panel from disconnecting Qolsys Gateway

  2. The communications with MQTT

    1. Qolsys Gateway listens to an event topic, when a message is received, we update the state of the panel according to the event (it can be updating the sensors, the partitions or the panel itself). Messages in that topic are the messages that come from the Qolsys Panel, and that we intepret as change to the state of the panel. In general, with the update, we will trigger a few MQTT messages to be sent to update the status of the element at the source of the event in Home Assistant.

    2. Qolsys Gateway also listens to a control topic, when a message is received, we communicate the action to perform to the Qolsys Panel. Messages in that topic are coming from Home Assistant as reactions to service calls on the alarm_control_panel entities, or of manually configured actions. They can be used to arm or disarm the system, or even to trigger the alarm on the device.

Requirements

Installation

Installing Qolsys Gateway requires the following steps.

Installing Home Assistant

You can get to the Home Assistant documentation for installation page in order to setup Home Assistant for your needs.

Installing an MQTT Broker

You will require a working MQTT broker alongside your Home Assistant installation. Home Assistant provides documentation on how to install and configure an MQTT broker. If you wish to use MQTT through a docker deployment, you can use the eclipse-mosquitto docker image. If you can, setup a username and password to secure your broker even more.

Installing AppDaemon

Qolsys Gateway is an AppDaemon automation, which means it depends on a working and running version of AppDaemon, connected to your Home Assistant. You can find all the resources necessary in AppDaemon's documentation about how to install AppDaemon and how to configure it with the HASS plugin for communicating with Home Assistant, and with the MQTT plugin for communicating with your MQTT broker.

If you wish to use AppDaemon through a docker deployment, you can use the acockburn/appdaemon docker image.

See an example of appdaemon.yaml ```yaml appdaemon: time_zone: "America/New_York" # Adapt this to your actual timezone # All three of those might be already filled for you, or you set the # values here, or use the secrets.yaml file to setup the values latitude: !secret latitude longitude: !secret longitude elevation: !secret elevation plugins: # If using the add-on in Home Assistant, that plugin will already be # enabled; when using the docker container, you will have to add it here HASS: type: hass ha_url: "http://homeassistant:8123" token: !secret ha_token # The token you get from home assistant # And we need to add the MQTT plugin MQTT: type: mqtt namespace: mqtt # We will need that same value in the apps.yaml configuration client_host: mosquitto # The IP address or hostname of the MQTT broker client_port: 1883 # The port of the MQTT broker, generally 1883 # Only if you have setup an authenticated connection, otherwise skip those: client_user: appdaemon # The username client_password: !secret mqtt_password # The password ```

Installing HACS (optional, recommended)

HACS is the Home Assistant Community Store and allows for community integrations and automations to be updated cleanly and easily from the Home Assistant web user interface. If it is simple to install Qolsys Gateway without HACS, keeping up to date requires manual steps that HACS will handle for you: you will be notified of updates, and they can be installed by a click on a button.

If you want to use HACS, you will have to follow their documentation on how to install HACS.

Installing Qolsys Gateway

Installing Qolsys Gateway is pretty simple once all the applications above are setup. You can either follow the path using HACS (a bit more steps initially, easier on the longer run) or use the manual setup approach.

With HACS (recommended)

To install Qolsys Gateway with HACS, you will need to make sure that you enabled AppDaemon automations in HACS, as these are not enabled by default:

  1. Click on Configuration on the left menu bar in Home Assistant Web UI
  2. Select Devices & Services
  3. Select Integrations
  4. Find HACS and click on Configure
  5. In the window that opens, make sure that Enable AppDaemon apps discovery & tracking is checked, or check it and click Submit
  6. If you just enabled this (or just installed HACS), you might have to wait a few minutes as all repositories are being fetched; you might hit a GitHub rate limit, which might then require you to wait a few hours for HACS to be fully configured. In this case, you won't be able to proceed to the next steps until HACS is ready.

Now, to install Qolsys Gateway with HACS, follow these steps:

  1. Click on HACS on the left menu bar in Home Assistant Web UI
  2. Click on Automations in the right panel
  3. Click on Explore & download repositories in the bottom right corner
  4. Search for qolsysgw, and click on Qolsys Gateway in the list that appears
  5. In the bottom right corner of the panel that appears, click on Download this repository with HACS
  6. A confirmation panel will appear, click on Download, and wait for HACS to proceed with the download
  7. Qolsys Gateway is now installed, and HACS will inform you when updates are available

Manually

Installing Qolsys Gateway manually can be summarized by putting the content of the apps/ directory of this repository (the qolsysgw/ directory) into the apps/ directory of your AppDaemon installation.

For instance, if your Home Assistant configuration directory is in /hass/config/, you most likely have AppDaemon setup in /hass/config/appdaemon/, and you can thus put qolsysgw/ into /hass/config/appdaemon/apps/.

Configuration

Configuring the MQTT integration in Home Assistant

The MQTT integration of Home Assistant needs to be configured with your MQTT broker in order for Qolsys Gateway to work. If you haven't setup the MQTT integration yet, you can do so with the following steps:

  1. Click on Configuration on the left menu bar in Home Assistant Web UI
  2. Select Devices & Services
  3. Select Integrations
  4. Click on Add Integration in the bottom right corner
  5. Search for MQTT, and click on the MQTT integration
  6. Fill in the information as configured for your MQTT broker (hostname, port, and username and password if setting things up with an authenticated connection)
  7. Click on Submit, Home Assistant will try and connect to the MQTT broker, and the integration will be setup upon success.

Configuring your Qolsys IQ Panel

If you already have the Control4 token for your Qolsys IQ Panel, you can skip that step. If you do not understand what that sentence is about, you definitely need to go through that step.

Qolsys Gateway communicates with your Qolsys Panel using a protocol that exists for communications with Control4 automation. That protocol is not enabled on your Qolsys Panel by default, so we will need to enable it and note the token that will be provided to us.

To enable the feature and get your secure token, you will need to:

  1. Connect your Qolsys Panel to your WiFi network (if not already done) 1. Swipe down from the top menu bar and select `Settings`. 2. Touch `Advanced Settings` and use either the _installer_ code or the _dealer_ code (you might have access with the main user code, too). 3. Touch `Wi-Fi`. 4. Check the `Enable Wi-Fi` box if not already active. 5. Available networks will appear in a list. 6. Touch the desired network and use the keyboard to type the password (if required).

    Qolsys documentation to connect to WiFi

  2. Enable 3rd party connections 1. Swipe down from the top menu bar and select `Settings`. 2. Touch `Advanced Settings` and use the _dealer_ code (you **might** have access with the _installer_ code, too). 3. Touch `Installation`. 4. Touch `Devices`. 5. Touch `Wi-Fi Devices`. 6. Touch `3rd Party Connections`. 7. Check the `Control4` box to enable 3rd Party Connections. 8. The panel will reboot in order to apply the change. 9. Come back to the same menu once the reboot is done. 10. Touch `Reveal secure token` and note the token that the panel is providing you, we will need it to configure Qolsys Gateway. 11. If you ever leak that token, come back to this menu and touch `Regenerate secure token` in order to make sure that nobody can get access to control your alarm system.

    Qolsys documentation for 3rd party connections

Configuring Qolsys Gateway

Qolsys Gateway needs to be configured in the apps.yaml file of AppDaemon. If your Home Assistant configuration directory is in /hass/config/, and AppDaemon in /hass/config/appdaemon/, you will find this file in /hass/config/appdaemon/apps/apps.yaml (next to the qolsysgw/ directory we moved here previously).

Required configuration

The minimum configuration to use Qolsys Gateway is the following:

qolsys_panel:
  module: gateway
  class: QolsysGateway
  panel_host: <qolsys_panel_host_or_ip>
  panel_token: <qolsys_secure_token>

With:

Optional configuration related to the Qolsys Panel itself

Optional configuration related to the representation of the panel in Home Assistant

Optional configuration related to MQTT & AppDaemon

Other documentation

Acknowledgements and thanks

The initial findings that made this project possible are discussed in the community forum of Home Assistant, where the Control4 interface was initially mentioned, as well as a number of the events and actions that could be used once the connection initiated with the Qolsys Panel.

The ad-qolsys project by @roopesh, which I used before deciding to rewrite the automation from scratch with different features and a different way to handle events and actions. This project is not using a line of code of ad-qolsys, but was initially inspired by it.