Skip to content

Commit

Permalink
added shelly blu gateway support for all gen2+ devices #164
Browse files Browse the repository at this point in the history
  • Loading branch information
windkh committed Sep 19, 2024
1 parent 227cb6b commit 1adb435
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Changelog
All notable changes to this project will be documented in this file.

## [11.2.0] - 2024-09-19
### all gen2+ devices can act as blu gateway - [#164](https://github.com/windkh/node-red-contrib-shelly/issues/164)

## [11.1.1] - 2024-09-19
### added Shelly Pro 2 UL - [#179](https://github.com/windkh/node-red-contrib-shelly/issues/179)

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ In callback mode a webhook is configured to the shelly which notifies to the nod
You must configure this network port, make sure that it is not already in use. If node-red runs inside a docker container or any other bridged network then you should also configure the hostname
under that the shelly device can reach the node-red server (Leave this field empty if you run inside the same network segment).
The node retries to set the webhook if the device is sleeping as long as it succeeds. As soon as the status shows "Connected" the webhook is set.
Note that gen2+ devices that have bluetooth support can act as a bluetooth gateway for shelly BLU devices. To activate that feature you must use callback node and check the bluetooth checkbox.


# Shelly Node (Generation 1)
Expand Down
2 changes: 1 addition & 1 deletion examples/blugateway.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"id":"0daaca6c559a4ac6","type":"shelly-gen2","z":"62a53d6e4cbdfb9a","hostname":"192.168.178.220","description":"BLU-Gateway","mode":"callback","server":"7f2759a4fe573634","outputmode":"event","uploadretryinterval":5000,"pollinginterval":5000,"pollstatus":false,"getstatusoncommand":true,"devicetype":"BluGateway","outputs":1,"x":280,"y":1140,"wires":[["0f371eef3226cba9"]]},{"id":"7e7af4802db81b4f","type":"debug","z":"62a53d6e4cbdfb9a","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":910,"y":1160,"wires":[]},{"id":"a3c70e46afb486d0","type":"inject","z":"62a53d6e4cbdfb9a","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":100,"y":1140,"wires":[["0daaca6c559a4ac6"]]},{"id":"0f371eef3226cba9","type":"function","z":"62a53d6e4cbdfb9a","name":"filter for BLU events","func":"let isBluMessage = msg.payload.info.event === \"shelly-blu\";\nif (isBluMessage){\n node.send(msg);\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":490,"y":1140,"wires":[["841589a76e05b12c"]]},{"id":"853a58645666004f","type":"debug","z":"62a53d6e4cbdfb9a","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":910,"y":1100,"wires":[]},{"id":"841589a76e05b12c","type":"function","z":"62a53d6e4cbdfb9a","name":"switch device","func":"// TODO: adapt your mac addresses here\nlet address1 = \"90:ab:96:3c:af:47\";\nlet address2 = \"90:ab:96:3c:af:48\";\n\nswitch (msg.payload.info.data.address){\n case address1:\n node.send([msg, null]);\n break;\n\n case address2:\n node.send([null, msg]);\n break;\n default:\n // nothing to do\n break;\n}\n","outputs":2,"noerr":0,"initialize":"","finalize":"","libs":[],"x":690,"y":1140,"wires":[["853a58645666004f"],["7e7af4802db81b4f"]]},{"id":"7f2759a4fe573634","type":"shelly-gen2-server","port":"20000","hostname":""}]
[{"id":"8e9829097c80f37f","type":"shelly-gen2","z":"62a53d6e4cbdfb9a","hostname":"192.168.178.76","description":"ShellyBluGateway","mode":"callback","verbose":false,"server":"7f2759a4fe573634","outputmode":"event","uploadretryinterval":5000,"pollinginterval":5000,"pollstatus":false,"getstatusoncommand":true,"devicetype":"SNGW-BT01","devicetypemustmatchexactly":false,"captureblutooth":true,"outputs":1,"x":370,"y":480,"wires":[["f25343742f4f9c0d","257776387e10fb0e"]]},{"id":"f8c170f943de0fa3","type":"debug","z":"62a53d6e4cbdfb9a","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1070,"y":500,"wires":[]},{"id":"1fd69529e146100a","type":"inject","z":"62a53d6e4cbdfb9a","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":180,"y":480,"wires":[["8e9829097c80f37f"]]},{"id":"f25343742f4f9c0d","type":"function","z":"62a53d6e4cbdfb9a","name":"filter for BLU events","func":"if(msg.payload.info){\n let isBluMessage = msg.payload.info.event === \"shelly-blu\";\n if (isBluMessage){\n node.send([msg, null]);\n }\n}\nelse{\n node.send([null, msg]);\n}\n","outputs":2,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":650,"y":480,"wires":[["52087e57509e02a1"],["83bfdecf1a502d74"]]},{"id":"a1251db2c18ee554","type":"debug","z":"62a53d6e4cbdfb9a","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1070,"y":440,"wires":[]},{"id":"52087e57509e02a1","type":"function","z":"62a53d6e4cbdfb9a","name":"switch device","func":"// TODO: adapt your mac addresses here\nlet address1 = \"90:ab:96:3c:af:47\";\nlet address2 = \"90:ab:96:3c:af:48\";\n\nswitch (msg.payload.info.data.address){\n case address1:\n node.send([msg, null]);\n break;\n\n case address2:\n node.send([null, msg]);\n break;\n default:\n // nothing to do\n break;\n}\n","outputs":2,"noerr":0,"initialize":"","finalize":"","libs":[],"x":850,"y":460,"wires":[["a1251db2c18ee554"],["f8c170f943de0fa3"]]},{"id":"83bfdecf1a502d74","type":"debug","z":"62a53d6e4cbdfb9a","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1050,"y":540,"wires":[]},{"id":"257776387e10fb0e","type":"debug","z":"62a53d6e4cbdfb9a","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1050,"y":580,"wires":[]},{"id":"7f2759a4fe573634","type":"shelly-gen2-server","port":"20000","hostname":"","hostip":"192.168.178.121"}]
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-red-contrib-shelly",
"version": "11.1.1",
"version": "11.2.0",
"description": "Shelly nodes.",
"node-red": {
"version": ">=3.0.0",
Expand Down
8 changes: 7 additions & 1 deletion shelly/99-shelly.html
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,7 @@ <h3>Details</h3>

devicetype: { value: "", required: true},
devicetypemustmatchexactly : { value: true, required: false },
captureblutooth : { value: false, required: false },

outputs: {value: 1},
},
Expand Down Expand Up @@ -701,7 +702,12 @@ <h3>Details</h3>
<div class="form-row">
<label for="node-input-uploadretryinterval"><i class="fa fa-clock-o"></i> Upload Retry Interval (ms)</label>
<input type="text" id="node-input-uploadretryinterval" placeholder="(Time in milliseconds. 0=off)">
</div>
</div>
<div class="form-row">
<label for="node-input-captureblutooth"><i class="fa fa-bluetooth"></i> Blutooth</label>
<input type="checkbox" id="node-input-captureblutooth" style="display: inline-block; width: auto; vertical-align: top;"> Install blutooth gateway script
</div>
<div class="form-tips" style="width: auto"><b>Tip:</b> If checked a blutooth gateway script is installed. Is automatically activated for BLU gateway.</div>
</div>
</div>

Expand Down
17 changes: 13 additions & 4 deletions shelly/99-shelly.js
Original file line number Diff line number Diff line change
Expand Up @@ -2463,7 +2463,9 @@ module.exports = function (RED) {
}

// Gets a function that initialize the device.
function getInitializer2(deviceType){
function getInitializer2(node){

let deviceType = node.deviceType;
let result;

switch(deviceType) {
Expand All @@ -2472,10 +2474,16 @@ module.exports = function (RED) {
case 'Measure':
case 'Dimmer':
case 'RGBW':
result = initializer2CallbackAsync;
// result = initializer2BluCallbackAsync; // TODO:
if(node.captureBlutooth) {
result = initializer2BluCallbackAsync;
}
else {
result = initializer2CallbackAsync;
}
break;
case 'BluGateway':
// Here we force the capturing f blutooth messages for this specific device.
node.captureBlutooth = true;
result = initializer2BluCallbackAsync;
break;
case 'Sensor':
Expand Down Expand Up @@ -2723,6 +2731,7 @@ module.exports = function (RED) {

let deviceType = config.devicetype;
node.deviceTypeMustMatchExactly = config.devicetypemustmatchexactly || false;
node.captureBlutooth = config.captureblutooth || false;

node.mode = config.mode;
if (!node.mode) {
Expand All @@ -2747,7 +2756,7 @@ module.exports = function (RED) {
node.types = getDeviceTypes2(node.deviceType, node.deviceTypeMustMatchExactly);
}

node.initializer = getInitializer2(node.deviceType);
node.initializer = getInitializer2(node);
node.inputParser = getInputParser2(node.deviceType);

(async () => {
Expand Down

0 comments on commit 1adb435

Please sign in to comment.