Skip to content

Commit

Permalink
Merge pull request #1043 from Scrounger/blu-4-btn
Browse files Browse the repository at this point in the history
Added Shelly BLU Wall Switch 4 & Shelly BLU RC Button 4
  • Loading branch information
klein0r authored Sep 16, 2024
2 parents 5c4bb3f + f678fd9 commit bd85dd3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ It uses the default Shelly firmware (no flashing of firmware needed!). You will
Adapter version >= v6.8.0 required!

- Shelly BLU Button and Button Tough 1
- Shelly BLU Wall Switch 4
- Shelly BLU RC Button 4
- Shelly BLU Door Window
- Shelly BLU Motion
- Shelly BLU H&T
Expand Down Expand Up @@ -150,6 +152,11 @@ execute
Placeholder for the next version (at the beginning of the line):
### **WORK IN PROGRESS**
-->

### **WORK IN PROGRESS**

* (Scrounger) Added Shelly BLU Wall Switch 4 & Shelly BLU RC Button 4

### 8.1.1 (2024-08-27)

* (@klein0r) Fixed lint issues and Shelly Gen 3 import
Expand Down
15 changes: 12 additions & 3 deletions docs/en/ble-devices.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Requirements:
Add this script in the Shelly Scripting section of a Shelly Plus or Pro device (Gen 2+) and start it:

```javascript
// v0.3
// v0.4
const SCRIPT_VERSION = '0.3';
const BTHOME_SVC_ID_STR = 'fcd2';

Expand Down Expand Up @@ -138,7 +138,7 @@ const BTH = {
0x2c: { n: 'vibration', t: uint8 },
0x2d: { n: 'window', t: uint8 },
// Events
0x3a: { n: 'button', t: uint8 },
0x3a: { n: 'button', t: uint8, b: 1 },
0x3c: { n: 'dimmer', t: uint8 }
};

Expand Down Expand Up @@ -210,6 +210,8 @@ let BTHomeDecoder = {

let _bth;
let _value;
let _name;
let _btnNum = 1;
while (buffer.length > 0) {
_bth = BTH[buffer.at(0)];
if (typeof _bth === 'undefined') {
Expand All @@ -220,7 +222,14 @@ let BTHomeDecoder = {
_value = this.getBufValue(_bth.t, buffer);
if (_value === null) break;
if (typeof _bth.f !== 'undefined') _value = _value * _bth.f;
result[_bth.n] = _value;

_name = _bth.n;
if (typeof _bth.b !== "undefined") {
_name = _name + '_' + _btnNum.toString();
_btnNum++;
}

result[_name] = _value;
buffer = buffer.slice(getByteSize(_bth.t));
}
return result;
Expand Down
10 changes: 6 additions & 4 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -437,17 +437,19 @@ class Shelly extends utils.Adapter {
);

for (const [key, value] of Object.entries(val.payload)) {
if (Object.keys(typesList).includes(key)) {
const typeListKey = key.includes('button_') ? 'button' : key;

if (Object.keys(typesList).includes(typeListKey)) {
await this.extendObjectAsync(`ble.${val.srcBle.mac}.${key}`, {
type: 'state',
common: {
name: key,
type: typesList[key].type,
type: typesList[typeListKey].type,
role: 'value',
read: true,
write: false,
unit: typesList[key]?.unit,
states: typesList[key]?.states,
unit: typesList[typeListKey]?.unit,
states: typesList[typeListKey]?.states,
},
native: {},
});
Expand Down

0 comments on commit bd85dd3

Please sign in to comment.