Skip to content

Relay Switch 2PM doesn't work via API properly #493

Description

@manni-2x

Analysis

Relay Switch 2PM doesn't work via API properly: only a few commands described in API-Documentation are working:
'setPosition': (value) => ({ command: 'setPosition', parameter: 0,ff,${value} }),
'setBlindPosition': (value) => ({ command: 'setPosition', parameter: String(value), commandType: 'command' }),
So one can substitute open and close with ({command: 'setPosition', parameter: '0'}) - or '100' responsively.

For 'pause'/'stop' are - probably - commands ({command: 'turnOff' parameter: '1' }) - or '2' needed:

Image

With these - in API named - commands: 'turnOn'/'turnOff' none of the relays in the device switch on/off (same environment). Despite of this the response is {"statusCode":100,"body":{},"message":"success"}.

Javascript for testing (Sample in above API is buggy: body is missing):

const crypto = require('crypto');
const https = require('https');
const { v4: uuidv4 } = require('uuid'); 

const nonce = uuidv4();
const token = "c734e6c01b6361cd3...";
const secret = "26392f2cc99...";

const t = Date.now();
const nonce = "requestID";
const data = token + t + nonce;
const sign = crypto
    .createHmac('sha256', secret)
    .update(data)
    .digest('base64');
console.log(sign);

const body = JSON.stringify({
    "command": "turnOn",
    "parameter": "1",     // or "2"
    "commandType": "command"
});
const deviceId = "9888E0D63736";
const options = {
    hostname: 'api.switch-bot.com',
    port: 443,
path: `/v1.1/devices/${deviceId}/commands`,
    method: 'POST',
    body: body,  // missing in API sample
    headers: {
        "Authorization": token,
        "sign": sign,
        "nonce": nonce,
        "t": t,
        'Content-Type': 'application/json',
        'Content-Length': body.length,
    },
};

const req = https.request(options, res => {
    console.log(`statusCode: ${res.statusCode}`);
    let responseBody = '';
    res.on('data', d => {
       // process.stdout.write(d);
       responseBody += d;
    });
    res.on('end', () => {
        console.log(`API Antwort: ${responseBody}`);
    });
});

req.on('error', error => {
    console.error(error);
});
req.write(body);
req.end();

Expected Behavior

Relay Switch 2PM works as in API described

Steps To Reproduce

Run above script on another implementation using API. Send turnOn/turnOff command as shown above. Check relays - no reaction.

Logs

javascript.0 | 15:49:22.370 | info | body {"command":"turnOn","parameter":"1","commandType":"command"}
javascript.0 | 15:49:22.374 | info | registered 0 subscriptions, 0 schedules, 0 messages, 0 logs and 0 file subscriptions
javascript.0 | 15:49:22.518 | info | statusCode: 200
javascript.0 | 15:49:22.519 | info | API Antwort: {"statusCode":100,"body":{},"message":"success"}

Configuration

n.a.

Environment

Plattform: docker (official image - v11.1.0)
Betriebssystem: linux
Architektur: arm64
CPUs: 4
Geschwindigkeit: 1800 MHz
Modell: Cortex-A72
RAM: 3.7 GB
System-Betriebszeit: 3 T. 23:08:45
Node.js: v22.22.2
Zeit: 6.7.2026, 15:54:14
Zeitversatz: -120
NPM: 10.9.7

Additional Context

No response

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions