Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
mqtt_for_digitalstrom [29.01.2018 09:55] – created Pascal Suter | mqtt_for_digitalstrom [06.07.2024 09:51] (current) – Pascal Suter | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== MQTT for digitalSTROM ====== | ====== MQTT for digitalSTROM ====== | ||
+ | **this is me, 6 years later**: i am still using Chriss Gross' gateway and it has been working great for me. Turns out the little delay that i get sometimes when a few lights have to be turned on via mqtt while the rest is directly via digitalstrom doesn' | ||
+ | i am now migrating the gateway to a new server and with that, it will be [[digitalstrom_mqtt_gateway_in_a_docker_container|running inside a docker container]], | ||
+ | |||
+ | ====== old article ====== | ||
+ | |||
I use [[http:// | I use [[http:// | ||
- | * DS is relatively open. the digitalSTROM Server (DSS) software is open source and comes with various openly documented API's to extend your setup. One is the DSS API which is good for polling status information about the bus system and the other is the VDC-API which allows to create virtual digtialSTROM devices to control stuff outside of your DS network | + | * DS is relatively open. the digitalSTROM Server (DSS) software is open source and comes with [[https:// |
* the bus itself does not require any additional cables. DS is perfect to install in an already existing house, where you had conventional electrical cabling so far. no extra bus lines are needed as the whole bus works across a relatively slow but very stable powerline network. | * the bus itself does not require any additional cables. DS is perfect to install in an already existing house, where you had conventional electrical cabling so far. no extra bus lines are needed as the whole bus works across a relatively slow but very stable powerline network. | ||
* thanks to the DSS's web-interface, | * thanks to the DSS's web-interface, | ||
* despite the fact, that DS has these api's, uses a built-in web-server and connects to all kinds of devices via TCP/IP it is still very robust. That's due to the fact, that the DSS is not actually required for the pure digitalSTROM components to work together. This means, that even if your DSS crashes (which in my case almost never happened, and if it did it was usually me screwing around in the lower levels of the DSS, where you aren't supposed to change stuff ;)) or if your network fails, your wifi acts up or anything computer related happens, your light switches will still turn your light on and off! you lose all the extra features but at least you and more importantly your wife are not sitting in the dark while you debug what happened ;) | * despite the fact, that DS has these api's, uses a built-in web-server and connects to all kinds of devices via TCP/IP it is still very robust. That's due to the fact, that the DSS is not actually required for the pure digitalSTROM components to work together. This means, that even if your DSS crashes (which in my case almost never happened, and if it did it was usually me screwing around in the lower levels of the DSS, where you aren't supposed to change stuff ;)) or if your network fails, your wifi acts up or anything computer related happens, your light switches will still turn your light on and off! you lose all the extra features but at least you and more importantly your wife are not sitting in the dark while you debug what happened ;) | ||
- | * while DS isn't as cheap as some wifi-based solutions like [[sonoff] and firends, it is relatively cheap compared to other professional systems like KNX, even though it provides a very similar stability and can be nicely integrated. | + | * while DS isn't as cheap as some wifi-based solutions like [[sonoff]] and firends, it is relatively cheap compared to other professional systems like KNX, even though it provides a very similar stability and can be nicely integrated. |
* DS is owned by Hager, a large manufacturer of electrical hardware in europe. So it can be expected that DS will be around for some time as it already has made it into the market. | * DS is owned by Hager, a large manufacturer of electrical hardware in europe. So it can be expected that DS will be around for some time as it already has made it into the market. | ||
===== current MQTT solution and its downside ===== | ===== current MQTT solution and its downside ===== | ||
- | one downside of DS is the lack of MQTT support. Fortunately, | + | one downside of DS is the lack of MQTT support. Fortunately, |
So far so good, but the problem with this MQTT bridge is, that it needs to poll your DSS every few seconds. If you set the interval too low (depends on the size of your installation and hardware-revision of your DSS, in my case i can't go below 1s) it slows down your DSS and has a negative impact on the user experience of the DSS apps and other control methods that use the API or the Web-Interface as well. Your light switches will still work normally though. | So far so good, but the problem with this MQTT bridge is, that it needs to poll your DSS every few seconds. If you set the interval too low (depends on the size of your installation and hardware-revision of your DSS, in my case i can't go below 1s) it slows down your DSS and has a negative impact on the user experience of the DSS apps and other control methods that use the API or the Web-Interface as well. Your light switches will still work normally though. | ||
- | |||
===== what I want to add ===== | ===== what I want to add ===== | ||
- | While the existing MQTT bridge is fine for changign | + | While the existing MQTT bridge is fine for changing |
- | luckily there is a nice socket-based API for virtual devices available | + | luckily there is a [[http:// |
The downsides of this approach are: | The downsides of this approach are: | ||
Line 25: | Line 29: | ||
* so far the whole solution isn't very stable. when i re-scan the devices on my digitalSTROM bus via the web-interface of the DSS, it will loose the connection to my virtual device. I need to re-start the node.js script to re-connect to the vdcd which provides the API, but as soon as i disconnect the API-Client (my node.js script) the vdcd segfaults. this can of course be solved by simply running it via something like systemd, which whill then simply restart it, but the main issue here is, that my node.js script is not informed, that the connection has been lost by the DSS or that it wants to re-scan all devices. So unless i notice the malfunction personally and fix it manually, my node.js script will not stop and re-initiate the connection. | * so far the whole solution isn't very stable. when i re-scan the devices on my digitalSTROM bus via the web-interface of the DSS, it will loose the connection to my virtual device. I need to re-start the node.js script to re-connect to the vdcd which provides the API, but as soon as i disconnect the API-Client (my node.js script) the vdcd segfaults. this can of course be solved by simply running it via something like systemd, which whill then simply restart it, but the main issue here is, that my node.js script is not informed, that the connection has been lost by the DSS or that it wants to re-scan all devices. So unless i notice the malfunction personally and fix it manually, my node.js script will not stop and re-initiate the connection. | ||
+ | The upside, that makes it all worth doing: | ||
+ | * NO LAG! which leads to a high WAF (Wife Approval Factor) of the installation :) | ||
===== Current Stats of this project ===== | ===== Current Stats of this project ===== | ||
Line 36: | Line 42: | ||
This was a nice test to see how fast the VDC api and also the whole MQTT side was. The on-command for my sonoff had to first be issued by the DSS and its virtual device connector. it was then pushed over a tcp socket to the VDSD, from there through another tcp socket to the VDCD, form there through tcp to my node.js script. from there to an MQTT broaker then to node-red and finally over a wifi-connection to the sonoff device. All in all three pyhsical devices where involved: my DSS (oldest and slowest revision with up-to-date firmware), my server (with 8-core Intel E5-2630L v3 cpu), and finally the sonoff. | This was a nice test to see how fast the VDC api and also the whole MQTT side was. The on-command for my sonoff had to first be issued by the DSS and its virtual device connector. it was then pushed over a tcp socket to the VDSD, from there through another tcp socket to the VDCD, form there through tcp to my node.js script. from there to an MQTT broaker then to node-red and finally over a wifi-connection to the sonoff device. All in all three pyhsical devices where involved: my DSS (oldest and slowest revision with up-to-date firmware), my server (with 8-core Intel E5-2630L v3 cpu), and finally the sonoff. | ||
+ | |||
+ | ===== the script ===== | ||
here is the source-code of my current prototype implementation. I am still trying to understand exactly how the API works and how I can possibly react to re-scans in the future. also i would like to implement the blink-feature, | here is the source-code of my current prototype implementation. I am still trying to understand exactly how the API works and how I can possibly react to re-scans in the future. also i would like to implement the blink-feature, | ||
- | <file dss-vd.js | + | < |
//you may use this code under GPL v3 at your own risk :) | //you may use this code under GPL v3 at your own risk :) | ||
var net = require(' | var net = require(' | ||
Line 157: | Line 165: | ||
JSONaction=` | JSONaction=` | ||
{ | { | ||
- | 'message':'${type}', | + | "message":"${type}", |
- | 'id':'${id}', | + | "id":"${id}", |
- | 'value':100, | + | "value":100, |
- | 'tag':'${tag}', | + | "tag":"${tag}", |
}` | }` | ||
client.write(JSONaction); | client.write(JSONaction); | ||
Line 177: | Line 185: | ||
JSONaction=` | JSONaction=` | ||
{ | { | ||
- | 'message':'${type}', | + | "message":"${type}", |
- | 'id':'${id}', | + | "id":"${id}", |
- | 'value': | + | "value": |
- | 'tag':'${tag}', | + | "tag":"${tag}", |
}` | }` | ||
client.write(JSONaction); | client.write(JSONaction); |