Mam takie nieśmiałe pytanie:
Jak skonfigurować LEDy (ZAMEL SLW-01)?
Nie znalazłem w urządzeniach homekita nic pasującego parametrami.
RGB można z komunikatu wyjąć/złożyć ale co robić z color_brightness?
SUPLA - MQTT - Homebridge... i mamy Hej Siri!
Kod: Zaznacz cały
{
"type": "lightbulb-OnOff",
"name": "Salon TV",
"topics": {
"getOnline": {
"topic": "supla/channels/status/relay/7792",
"apply": "return JSON.parse(message).online;"
},
"getOn": {
"topic": "supla/channels/status/relay/7792",
"apply": "return JSON.parse(message).on;"
},
"setOn": {
"topic": "supla/channels/command/relay/7792",
"apply": "return JSON.stringify({id: 7792, on: message});"
}
},
"onValue": "1",
"offValue": "0",
"accessory": "mqttthing"
},
Sam sobie częściowo odpowiem:
Kod: Zaznacz cały
{
"type": "lightbulb",
"name": "ZAMEL SLW-01",
"topics": {
"getOnline": {
"topic": "supla/channels/status/rgblightning/6952",
"apply": "return JSON.parse(message).online;"
},
"getOn": {
"topic": "supla/channels/status/rgblightning/6952",
"apply": "return JSON.parse(message).color_brightness > 0;"
},
"setOn": {
"topic": "supla/channels/command/rgblightning/6952",
"apply": "return JSON.stringify({id: 6952, c_brightness: message * 100});"
},
"getRGB": {
"topic": "supla/channels/status/rgblightning/6952",
"apply": "return JSON.parse(message).color;"
},
"setRGB": {
"topic": "supla/channels/command/rgblightning/6952",
"apply": "return JSON.stringify({id: 6952, colors: {r: parseInt(message.substr(2,2), 16), g: parseInt(message.substr(4,2), 16), b: parseInt(message.substr(6,2), 16)}});"
},
"getBrightness": {
"topic": "supla/channels/status/rgblightning/6952",
"apply": "return JSON.parse(message).color_brightness;"
},
"setBrightness": {
"topic": "supla/channels/command/rgblightning/6952",
"apply": "return JSON.stringify({id: 6952, c_brightness: message});"
}
},
"integerValue": true,
"hex": true,
"hexPrefix": "0x",
"accessory": "mqttthing"
}
Niestety nadal jest problem z parametrem "brightness". Zmiana jasności w aplikacji nie wystawia informacji na topic setBrightness tylko zmienia kolor w topicu setRGB, co nic powoduje zmiany jasności w Supli.
SUPLA ma zrobione sterowanie RGB w bezsensowny sposób. Nie jet to kompatybilne z przyjętymi standardami.
Musimy wyeliminować "colorBrightness" zostawiając tylko RGB. Na chwilę obecną trzeba skonwertować RGB do HSV, następnie zapamiętać V. Zmienić V na 100 i skonwertować do RGB. Na koniec przesyłasz RGB i colorBrightness.
Będziemy to powoli porządkować. Jeszcze w 2.3 powinna pojawić się możliwość odwołania się do API w wersji 2.4 gdzie nie będzie już kombinacji z colorBrightness.
Musimy wyeliminować "colorBrightness" zostawiając tylko RGB. Na chwilę obecną trzeba skonwertować RGB do HSV, następnie zapamiętać V. Zmienić V na 100 i skonwertować do RGB. Na koniec przesyłasz RGB i colorBrightness.
Będziemy to powoli porządkować. Jeszcze w 2.3 powinna pojawić się możliwość odwołania się do API w wersji 2.4 gdzie nie będzie już kombinacji z colorBrightness.
Przykład dla nodejs
setColor
setColor
Kod: Zaznacz cały
module.exports = {
setRGBW: function(request, context, color, brightness, brightnessDelta) {
const credentials = tools.getCredentialsFromRequest(request);
const channelId = tools.getChannelId(request);
return api.get("/api/v2.3.0/channels/"+channelId+"?include=state", credentials).then((channel)=>{
let currentBrightness = channel && channel.state
&& channel.state.brightness !== undefined ? channel.state.brightness : 0;
let currentColorBrightness = channel && channel.state
&& channel.state.color_brightness !== undefined ? channel.state.color_brightness : 0;
let currentColor = channel && channel.state
&& channel.state.color !== undefined ? channel.state.color : 0x00FF00;
if (color !== null) {
currentColor = color;
}
if (channel.function.name === "RGBLIGHTING"
|| tools.getSubChannel(request) === "1") {
if (brightnessDelta !== null) {
currentColorBrightness += brightnessDelta;
} else if (brightness !== null) {
currentColorBrightness = brightness;
}
if (color !== null) {
currentColor = color;
}
} else if (channel.function.name === "DIMMER"
|| tools.getSubChannel(request) === "2") {
if (brightnessDelta !== null) {
currentBrightness += brightnessDelta;
} else if (brightness !== null) {
currentBrightness = brightness;
}
}
if (currentColorBrightness > 100) {
currentColorBrightness = 100;
} else if (currentColorBrightness < 0) {
currentColorBrightness = 0;
}
if (currentBrightness > 100) {
currentBrightness = 100;
} else if (currentBrightness < 0) {
currentBrightness = 0;
}
const payload = {
action: "SET_RGBW_PARAMETERS",
color: currentColor,
color_brightness: currentColorBrightness,
brightness: currentBrightness,
alexaCorrelationToken: tools.getCorrelationTokenWithSubchannel(request),
};
return api.patch("/api/v2.3.0/channels/"+channelId,
credentials,
JSON.stringify(payload),
"application/json");
});
},
setColor: function(request, context) {
let hue = request.directive.payload.color.hue;
let saturation = request.directive.payload.color.saturation * 100.00;
/* eslint-disable no-undef */
var convert = require("color-convert");
/* eslint-enable no-undef */
let rgb = convert.hsv.rgb([hue, saturation, 100]);
let color = rgb[0]<<16 & 0xFF0000 | rgb[1]<<8 & 0x00FF00 | rgb[2] & 0xFF;
color = "0x"+color.toString(16).toUpperCase()
this.setRGBW(request, context, color, null, null).then((result)=>{
context.succeed(tools.getDefferedResponse(request));
}).catch((e) => {
tools.endpointUnrechableResponse(request, context, e.message ? e.message : "-1");
});
},
};
Co robię źle?
- Raspberry Pi 4 B
- homebridge-raspbian-image
- Raspberry Pi 4 B
- homebridge-raspbian-image
Kod: Zaznacz cały
mqtt:
host: 'mqtthost' # MQTT server hostname
port: 1883 # MQTT server port
commands_file_path: '/home/pi/supla-mqtt-client/config/command.yaml' # absolute path to the command.yaml configuration file
states_file_path: '/home/pi/supla-mqtt-client/config/state.yaml' # absolute path to the state.yaml configuration file
client_name: 'supla_mqtt_client' #MQTT broker client name should be unique
protocol_version: 3 #MQTT protocol version. supported 3 for 3.1.1 (default) version and 5
publish_supla_events: true #if enabled client will publish supla client events
supla:
port: 2016 # SUPLA server port
host: 'svr3.supla.org' # SUPLA server hostname
email: 'moj@mail.org' # SUPLA user email
protocol_version: 10 # supla protocol version should be grater than 5
Kod: Zaznacz cały
pi@homebridge:/var/lib/homebridge/supla-core/supla-mqtt-client/Release $ ./supla-mqtt-client -config config_template.yaml
INFO[1596658615.461132] initializing main loop
INFO[1596658615.463121] Client GUID: AA4E3FC6E8EDB06602B6C9BC9D907059
Invalid quote. Line 3: 'mqtthost' # MQTT server hostname
INFO[1596658615.464914] SSL version: OpenSSL 1.1.1d 10 Sep 2019
INFO[1596658615.474539] Connecting...
ERR[1596658615.476193] Can't connect to host localhost
mqtt client error MQTT_ERROR_SOCKET_ERROR
mqtt client error MQTT_ERROR_SOCKET_ERROR
mqtt client error MQTT_ERROR_SOCKET_ERROR
mqtt client error MQTT_ERROR_SOCKET_ERROR
Ok, dodałem już do aplikacji Dom. Wyświetla się dodana brama garażowa, ale nie działa. Gdy klikam to jest nieskończona animacja otwierania bramy ale fizycznie z bramą nic się nie dzieje.
SBW-02 - użyty jeden kanał do bramy plus do tego podłączony kontaktron
SBW-02 - użyty jeden kanał do bramy plus do tego podłączony kontaktron
Kod: Zaznacz cały
"accessories": [
{
"accessory": "mqttthing",
"type": "garageDoorOpener",
"name": "garaz",
"topics": {
"setTargetDoorState": {
"topic": "supla/channels/command/garagedoor/12",
"apply": "return JSON.stringify({ id: 12, hi: message });"
},
"getTargetDoorState": {
"topic": "supla/channels/status/garagedoor/12",
"apply": "return JSON.parse(message).sensor_1;"
},
"getCurrentDoorState": {
"topic": "supla/channels/status/garagedoor/12",
"apply": "return JSON.parse(message).sensor_1;"
},
"setLockTargetState": {
"topic": "supla/channels/command/garagedoor/12",
"apply": "return JSON.stringify({ id: 12, hi: message });"
},
"getLockTargetState": {
"topic": "supla/channels/status/garagedoor/12",
"apply": "return JSON.parse(message).sensor_1;"
},
"getLockCurrentState": {
"topic": "supla/channels/status/garagedoor/12",
"apply": "return JSON.parse(message).sensor_1;"
},
"getObstructionDetected": {
"topic": "supla/channels/status/garagedoor/12",
"apply": "return JSON.parse(message).online;"
}
},
"doorValues": [
"1",
"1",
"0",
"0",
"0"
]
}
],
Jaki jest teraz problem?
Kod: Zaznacz cały
pi@homebridge:/var/lib/homebridge/supla-core/supla-mqtt-client/Release $ ./supla-mqtt-client -config config_template.yaml
INFO[1597073161.370352] initializing main loop
INFO[1597073161.372368] Client GUID: 02C62C0541919052C67D2AC6DF0B3AB3
INFO[1597073161.373740] command file not exists.
INFO[1597073161.373838] SSL version: OpenSSL 1.1.1d 10 Sep 2019
INFO[1597073161.383262] Connecting...