Giter Site home page Giter Site logo

mountaindude / verisure-mqtt Goto Github PK

View Code? Open in Web Editor NEW
10.0 4.0 4.0 1.22 MB

Dockerized Node.js app that queries Verisure's APIs for status, and then forward this info to MQTT.

Home Page: https://ptarmiganlabs.com/

License: MIT License

Dockerfile 6.24% JavaScript 93.76%
verisure verisure-api

verisure-mqtt's Introduction

verisure-to-mqtt-bridge

Build Status Maintainability

April 2021 update

Verisure has enabled 2-factor authentication (2FA) across (parts or all of?) their user base. This means that you will receive a code in an SMS message, and this code should be entered sent to Verisure as part of the login flow, to prove your identiy.

This is excellent news from a security perspective, but unfortunately it makes it harder to pull data from the Verisure APIs.

This means that in order to keep using the code in this repository you need to disable 2FA login at Verisure.
Wheter or not this is the right thing for you, is something that only you can decide.

The upside is that you can keep getting for example temperature, humidity etc from your Verisure system.

The downside is that you will not have as strong login security as you would have if 2FA was enabled.

If you decide to disable 2FA that can be done after logging into the Verisure "my pages" site online.

Note: The above is how things are at the time of this writing. As this whole field is ultimately controlled by Verisure, things may change at any time, possibly without prior notice.

Overview

Dockerized Node.js app that queries Verisure's APIs for status and sensor readings, and then forwards this info to MQTT.

Once the data has been injected into MQTT messages, it can be acted upon by any tool or system capable of subscribing to MQTT topics.

What kind of data that is available from different Verisure devices vary, but many of them (PIR, camera, smoke detectors etc) contain temperature and/or humidity sensors. These sensor readings can be logged and then provide useful long-term environmental information.

A powerful use case is to use Node-RED to automate various actions based on information retrieved from the alarm system.

For example

  • Turn on lamps, radio etc when someone arrives home and disarms (turns off) the alarm. Different actions could even be taken depending on who it is that turns off the alarm.
  • Store the climate readings (temperature and humidity) taken by the various alarm sensors in a time-series database such as InfluxDB.

The status JSON returned from Verisure is quite rich and includes both alarm related information (alarm state, status of door/window sensors), as well as temperature and humidity readings from the various devices in the system.

It is easy to change th MQTT topics in case the current ones don't fit your needs.

Note! Do NOT download and user master branch unless you know what you are doing. Instead use a suitable release. This will avoid issues due to new development that may have been done on master branch, since the last release was made.

Eye candy using InfluxDB and Grafana

Pushing the sensor readings to MQTT makes it possible to act on them from other systems. A Node-RED flow for taking the MQTT messages and storing them into InfluxDB can look like this:

Moving sensor data in MQTT messages to InfluxDB

While Node-RED was initially (and still is) positioned as a visual prototyping tool for IoT applications, it has over the past several years developed into a rock-solid platform that lots of people use for continuous data processing. It might not be solid enough for mission critical enterprise data, but it's not far away.

For the purpose of collecting and acting on sensor data in a home setting, Node-RED is more than adequate.

Oh, and Node-RED of course runs as a Docker container too.. making it a breeze to set up.

Once the data is stored in InfluxDB it can be visualised using Grafana och other similar tools. A Grafana dashboard showing temperatures and humidity can look like this:

Grafana dashboard showing Verisure sensor data

Querying Verisure's API

There is some rate limiting for the API, preventing too frequent calls.

It is hard to say how often calls can be made, but given that climate sensors only update once per hour, the Node.js code in index.js is set to query the API every 10 minutes. This seems to work fine from a rate limiting perspective.

Some parts (e.g. info on door locks, heat pumps, cameras etc) of the data received from Verisure's API are not forwarded to MQTT. The reason is simply that I don't have access to such devices, and thus don't know what the associated JSON looks like.

Please feel free to fork this repository and add the missing code if you have access to those missing devices.

Dockerizing the Node.js app

For testing purposes this guide is useful.

A proper production deployment requires more work, but even the steps outlined below will be enough to test things up on a home server, NAS or similar.

Build Docker image

cd /directory/where/node/app/is/stored
docker build -t mountaindude/verisure-mqtt .

Run Docker image

docker run --name verisure-mqtt -d mountaindude/verisure-mqtt

Even better, use docker-compose. Adapt the docker-compose.yaml file to your needs:

# docker-compose.yaml
version: '3.3'
services:
  verisure-mqtt:
    image: mountaindude/verisure-mqtt:1.4.1
    container_name: verisure-mqtt
    restart: always
    environment:
      - "VERISURE_DEBUG=true"
      - "MQTT_BROKER_HOST=<ip of MQTT broker>"
      - "MQTT_BROKER_PORT=<port used by MQTT broker>"
      - "MQTT_ROOT_TOPIC=myHouse/"
      - "VERISURE_USERNAME=<username used to log into Verisure web service>"
      - "VERISURE_PWD=<password used to log into Verisure web service"
    logging:
      driver: "json-file"
      options:
        max-file: "5"
        max-size: "5m"

Then run

docker-compose up

from the directory where docker-compose.yaml is stored.

Get shell inside running container

In case you want to see what's going on within the running container, you can attach to it:

docker exec -it verisure-mqtt /bin/bash

Monitor console output within the running container

Watch all console output messages generated within the container called verisure-mqtt

docker logs verisure-mqtt -f

Export image to file, for copying to new server

If you develop on one computer but then want to deploy your newly created Docker image to a server, you need to export it to a TAR file.

docker images

# Take note of the id of the image you want to export
docker save -o ./verisure-mqtt.tar <id>

Import image into new server

Once you have an image in a TAR file, you can load it into Docker on some other machine. An alternative to the steps below is to pubish the image to Docker Hub and thus make it generally available, but if that's too much work the steps below are quick and easy.

# Log into target server
# Copy verisure-mqtt.tar to temp folder on target server
docker load -i ./verisure-mqtt.tar
docker images

# Take note of the id of the newly loaded image. Then rename the image to something human readable
docker tag <image id> mountaindude/verisure-mqtt

# Copy docker-compose.yaml file to target server, then create and start a new container based on the image
docker-compose up

Use image on Docker Hub

If you don't want to build the Docker image yourself, it is also available on Docker Hub.

If the requested Docker image is not found locally, it will be requested from Docker Hub (or other image repository that you have configured/logged into).

This docker-compose.yaml file will use the latest available image on Docker Hub. Make sure to define the MQTT and user credentials in it before running docker-compose up.

# docker-compose.yaml
version: '3.3'
services:
  verisure-mqtt:
    # Use image on Docker Hub
    image: mountaindude/verisure-mqtt:latest
    container_name: verisure-mqtt
    restart: always

    # Set debug flag to true to output all received info to console.
    # False will limit output to only mention that a query to the Verisure API is made
    environment:
      - "VERISURE_DEBUG=true"
      - "MQTT_BROKER_HOST=<ip of MQTT broker>"
      - "MQTT_BROKER_PORT=<port used by MQTT broker>"
      - "MQTT_ROOT_TOPIC=myHouse/"
      - "VERISURE_USERNAME=<username used to log into Verisure web service>"
      - "VERISURE_PWD=<password used to log into Verisure web service"
    logging:
      driver: json-file

Then run

docker-compose up

Disclaimer

This repository and any code in it is provided as-is, the developer of this repository and the artefacts within it should not be held liable for any use of such artefacts or derivatives of them.

The Verisure API is not officially documented or supported by Verisure, and may change at any time. Finally, security is important and you should properly think things through how you use your Verisure username and password, and take appropriate security measures if you decide to use them in a project like this. You are on your own, basically.

verisure-mqtt's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

verisure-mqtt's Issues

Ability to choose Verisure server/country

Hello and thanks for taking the time for this.

I'm not sure whether this is a new feature or something is wrong with my installation.
Docker is running fine and publishing the 'Hellp mqtt' on my mqtt server but does not go any further.
I suspect there's an authentication issue and this could probably because of Verisure might have different web services for different countries. I'm using credentials that work for Spanish site (https://customers.securitasdirect.es/es/login)

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Ignored or Blocked

These are blocked by an existing closed PR and will not be recreated unless you click a checkbox below.

Detected dependencies

docker-compose
docker-compose-template.yaml
  • mountaindude/verisure-mqtt 1.4.1
dockerfile
Dockerfile
  • node 14-stretch
droneci
.drone.yml
npm
package.json
  • asyncinterval 0.0.7
  • jshint ^2.13.0
  • mqtt ^4.2.6
  • verisure ^4.0.0
  • eslint 7.32.0
  • eslint-config-google 0.14.0
  • nodemon 2.0.15

  • Check this box to trigger a request for Renovate to run again on this repository

Installed on a synology docker. --> npm ERR!

Crach error at start :
npn ERR! missing script: start.

Could be synology docker, since it's not easy to do a compose.yml All done with a gui.

HEre the environnement variable
PATH = /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
NODE_VERSION=8.15.1
YARN_VERSION=1.12.3

Host, port pwd username topic and debug has been filled

Error 1 when running image from Docker Hub

Describe the bug
When running versisure-mqtt with an image from Docker Hub, I get an error. Ran it on Docker on a Synology and on a Debian linux system, same error on both systems.

Error 1:  TypeError: Cannot read property 'toString' of undefined
    at /nodeapp/index.js:146:49
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
}

Some information is read and published to MQTT, but it is not complete.

To Reproduce
Redeployed the image several times, this error happens 10 minutes after starting the container.

Expected behavior
No error ;-)

Screenshots
If applicable, add screenshots to help explain your problem.

Describe environment:

  • OS: Synology and Debian 5.10
  • Containerisation yes, v20.10.22, build 3a2c30b
  • Version of Verisure MQTT used: The one in the Docker image on Docker Hub.
  • Command used to start Verisure MQTT:None

Config file(s)
What's the content of the config file(s) you use?
Entered the correct information in the Env settings when deploying the container.

Additional context
Add any other context about the problem here.

Action required: Greenkeeper could not be activated 🚨

🚨 You need to enable Continuous Integration on Greenkeeper branches of this repository. 🚨

To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because it uses your CI build statuses to figure out when to notify you about breaking changes.

Since we didn’t receive a CI status on the greenkeeper/initial branch, it’s possible that you don’t have CI set up yet. We recommend using Travis CI, but Greenkeeper will work with every other CI service as well.

If you have already set up a CI for this repository, you might need to check how it’s configured. Make sure it is set to run on all new branches. If you don’t want it to run on absolutely every branch, you can whitelist branches starting with greenkeeper/.

Once you have installed and configured CI on this repository correctly, you’ll need to re-trigger Greenkeeper’s initial pull request. To do this, please click the 'fix repo' button on account.greenkeeper.io.

Variable for polling time

Is your feature request related to a problem? Please describe.
It would be nice if you can add a variable (in Env of container) for the polling time

Describe the solution you'd like
With a previous script (which broke with the last update) I polled the API for the armState every minute and that worked just fine.

Describe alternatives you've considered
Or the possibility that it polls the API at startup. Now after startup you have to wait 10 min for the poll and find out your Node-RED config is wrong and doesn't work ;-)

Additional context
Add any other context or screenshots about the feature request here.

Error: This API is not supported anymore

Describe the bug
Since a couple of days, the error below is displayed

    data: {
      errorGroup: 'NOT_IMPLEMENTED',
      errorCode: 'VAL_01797',
      errorMessage: 'This API is not supported anymore '

To Reproduce
Happens every 10 min.

Expected behavior
That the werror would not occur ;-)

Describe environment:

  • OS: [Debian 11]
  • Containerisation (yes/, Docker v23.0.1)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.