Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node-red Alice integration #29

Open
d347h4ck opened this issue Dec 13, 2020 · 0 comments
Open

Node-red Alice integration #29

d347h4ck opened this issue Dec 13, 2020 · 0 comments

Comments

@d347h4ck
Copy link

d347h4ck commented Dec 13, 2020

Добрый день! Я тут на досуге создал программу автоматизации для node-red под управлением Алисы.
image
Оно использует этот плагин для node-red, но он довольно классный)
Код ниже необходимо импортировать в Node-red IDE. Потом необходимо авторизоваться для ноды mqtt сервера и нод устройств алисы.

    {
        "id": "a4fd6b01.5ef658",
        "type": "tab",
        "label": "Flow 1",
        "disabled": false,
        "info": ""
    },
    {
        "id": "b3b6d65b.51cbf8",
        "type": "mqtt in",
        "z": "a4fd6b01.5ef658",
        "name": "ON/OFF",
        "topic": "homeassistant/light/ESP-cda520/status",
        "qos": "2",
        "datatype": "auto",
        "broker": "2848f647.f877da",
        "x": 120,
        "y": 120,
        "wires": [
            [
                "44dd6947.81fb38"
            ]
        ]
    },
    {
        "id": "44dd6947.81fb38",
        "type": "function",
        "z": "a4fd6b01.5ef658",
        "name": "To_Alice",
        "func": "msg.payload = msg.payload == \"ON\";\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "x": 380,
        "y": 120,
        "wires": [
            [
                "5d78b9b7.095a38"
            ]
        ]
    },
    {
        "id": "5d78b9b7.095a38",
        "type": "On_Off",
        "z": "a4fd6b01.5ef658",
        "device": "473d7e83.83852",
        "name": "Комната:Лампа Гайвера",
        "retrievable": true,
        "response": true,
        "x": 610,
        "y": 120,
        "wires": [
            [
                "206b579.86e91a8"
            ]
        ]
    },
    {
        "id": "a27b36c1.dce598",
        "type": "mqtt out",
        "z": "a4fd6b01.5ef658",
        "name": "ON/OFF",
        "topic": "homeassistant/light/ESP-cda520/switch",
        "qos": "2",
        "retain": "false",
        "broker": "2848f647.f877da",
        "x": 1060,
        "y": 120,
        "wires": []
    },
    {
        "id": "206b579.86e91a8",
        "type": "function",
        "z": "a4fd6b01.5ef658",
        "name": "To_MQTT",
        "func": "if (msg.payload){\n    msg.payload = \"ON\";\n} else {\n    msg.payload = \"OFF\";\n}\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "x": 900,
        "y": 120,
        "wires": [
            [
                "a27b36c1.dce598"
            ]
        ]
    },
    {
        "id": "78162c7b.8803d4",
        "type": "Range",
        "z": "a4fd6b01.5ef658",
        "device": "473d7e83.83852",
        "name": "Комната:Лампа Гайвера",
        "instance": "brightness",
        "unit": "unit.percent",
        "min": "0",
        "max": "100",
        "precision": "5",
        "response": true,
        "retrievable": true,
        "x": 630,
        "y": 180,
        "wires": [
            [
                "2612182b.2eb298"
            ]
        ]
    },
    {
        "id": "3834937.5a94f6c",
        "type": "mqtt in",
        "z": "a4fd6b01.5ef658",
        "name": "BRI",
        "topic": "homeassistant/light/ESP-cda520/brightness/status",
        "qos": "2",
        "datatype": "auto",
        "broker": "2848f647.f877da",
        "x": 110,
        "y": 180,
        "wires": [
            [
                "39e28341.524fbc"
            ]
        ]
    },
    {
        "id": "39e28341.524fbc",
        "type": "function",
        "z": "a4fd6b01.5ef658",
        "name": "To_Alice",
        "func": "msg.payload = parseInt(msg.payload);\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "x": 380,
        "y": 180,
        "wires": [
            [
                "78162c7b.8803d4"
            ]
        ]
    },
    {
        "id": "2612182b.2eb298",
        "type": "function",
        "z": "a4fd6b01.5ef658",
        "name": "To_MQTT",
        "func": "msg.payload = Math.round(2.55 * msg.payload).toString();\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "x": 900,
        "y": 180,
        "wires": [
            [
                "9892e48.4aa9a18"
            ]
        ]
    },
    {
        "id": "9892e48.4aa9a18",
        "type": "mqtt out",
        "z": "a4fd6b01.5ef658",
        "name": "BRI",
        "topic": "homeassistant/light/ESP-cda520/brightness/set",
        "qos": "2",
        "retain": "false",
        "broker": "2848f647.f877da",
        "x": 1050,
        "y": 180,
        "wires": []
    },
    {
        "id": "c6ad1345.039c1",
        "type": "Color",
        "z": "a4fd6b01.5ef658",
        "device": "473d7e83.83852",
        "name": "Комната:Лампа Гайвера",
        "scheme": "rgb_normal",
        "response": true,
        "x": 610,
        "y": 240,
        "wires": [
            [
                "b1507993.fbdb78"
            ]
        ]
    },
    {
        "id": "42a0e0f.046822",
        "type": "mqtt in",
        "z": "a4fd6b01.5ef658",
        "name": "RGB",
        "topic": "homeassistant/light/ESP-cda520/rgb/status",
        "qos": "2",
        "datatype": "auto",
        "broker": "2848f647.f877da",
        "x": 110,
        "y": 240,
        "wires": [
            [
                "d8bfab90.925fc8"
            ]
        ]
    },
    {
        "id": "d8bfab90.925fc8",
        "type": "function",
        "z": "a4fd6b01.5ef658",
        "name": "To_Alice",
        "func": "var rgb = msg.payload.split(',').map(Number);\nmsg.payload = {'r': rgb[0], 'g' : rgb[1], 'b' : rgb[2]};\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "x": 380,
        "y": 240,
        "wires": [
            [
                "c6ad1345.039c1"
            ]
        ]
    },
    {
        "id": "b1507993.fbdb78",
        "type": "function",
        "z": "a4fd6b01.5ef658",
        "name": "To_MQTT",
        "func": "var rgb = msg.payload \nmsg.payload = `${rgb['r']}, ${rgb['g']}, ${rgb['b']}`;\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "x": 900,
        "y": 240,
        "wires": [
            [
                "79c190cf.188dd"
            ]
        ]
    },
    {
        "id": "79c190cf.188dd",
        "type": "mqtt out",
        "z": "a4fd6b01.5ef658",
        "name": "RGB",
        "topic": "homeassistant/light/ESP-cda520/rgb/set",
        "qos": "2",
        "retain": "false",
        "broker": "2848f647.f877da",
        "x": 1050,
        "y": 240,
        "wires": []
    },
    {
        "id": "4a835f57.d1468",
        "type": "Range",
        "z": "a4fd6b01.5ef658",
        "device": "473d7e83.83852",
        "name": "Комната:Лампа Гайвера",
        "instance": "channel",
        "unit": "unit.number",
        "min": "0",
        "max": "29",
        "precision": 1,
        "response": true,
        "retrievable": true,
        "x": 620,
        "y": 300,
        "wires": [
            [
                "5f892e9.847bcd"
            ]
        ]
    },
    {
        "id": "f7d30a8c.5017d8",
        "type": "mqtt in",
        "z": "a4fd6b01.5ef658",
        "name": "Effect",
        "topic": "homeassistant/light/ESP-cda520/effect/status",
        "qos": "2",
        "datatype": "auto",
        "broker": "2848f647.f877da",
        "x": 110,
        "y": 300,
        "wires": [
            [
                "aa2e8e81.c4fdd"
            ]
        ]
    },
    {
        "id": "aa2e8e81.c4fdd",
        "type": "function",
        "z": "a4fd6b01.5ef658",
        "name": "To_Alice",
        "func": "switch(msg.payload){\n    case 'Конфетти':\n        msg.payload = 0;\n        break;\n    case 'Огонь':\n        msg.payload = 1;\n        break;\n    case 'Радуга верт.':\n        msg.payload = 2;\n        break;\n    case 'Радуга гориз.':\n        msg.payload = 3;\n        break;\n    case 'Смена цвета':\n        msg.payload = 4;\n        break;\n    case 'Безумие 3D':\n        msg.payload = 5;\n        break;\n    case 'Облака 3D':\n        msg.payload = 6;\n        break;\n    case 'Лава 3D':\n        msg.payload = 7;\n        break;\n    case 'Плазма 3D':\n        msg.payload = 8;\n        break;\n    case 'Радуга 3D':\n        msg.payload = 9;\n        break;\n    case 'Павлин 3D':\n        msg.payload = 10;\n        break;\n    case 'Зебра 3D':\n        msg.payload = 11;\n        break;\n    case 'Лес 3D':\n        msg.payload = 12;\n        break;\n    case 'Океан 3D':\n        msg.payload = 13;\n        break;\n    case 'Цвет':\n        msg.payload = 14;\n        break;\n    case 'Снегопад':\n        msg.payload = 15;\n        break;\n    case 'Матрица':\n        msg.payload = 16;\n        break;\n    case 'Светлячки':\n        msg.payload = 17;\n        break;\n    case 'Аквариум':\n        msg.payload = 18;\n        break;\n    case 'Звездопад':\n        msg.payload = 19;\n        break;\n    case 'Пейнтбол':\n        msg.payload = 20;\n        break;       \n    case 'Спираль':\n        msg.payload = 21;\n        break;\n    case 'Теплый свет':\n        msg.payload = 22;\n        break;\n    case 'Маятник':\n        msg.payload = 23;\n        break;\n    case 'Мерцание':\n        msg.payload = 24;\n        break;\n    case 'Полицейская сирена':\n        msg.payload = 25;\n        break;\n    case 'Дрейф':\n        msg.payload = 26;\n        break;\n    case 'Стая':\n        msg.payload = 27;\n        break;\n    case 'Мотыльки в банке':\n        msg.payload = 28;\n        break;\n    case 'Демо':\n        msg.payload = 29;\n        break;\n}\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "x": 380,
        "y": 300,
        "wires": [
            [
                "4a835f57.d1468"
            ]
        ]
    },
    {
        "id": "5f892e9.847bcd",
        "type": "function",
        "z": "a4fd6b01.5ef658",
        "name": "To_MQTT",
        "func": "switch (msg.payload) {\n    case 0: \n        msg.payload = \"Конфетти\";\n        break;\n    case 1: \n        msg.payload = \"Огонь\";\n        break;\n    case 2: \n        msg.payload = \"Радуга верт.\";\n        break;\n    case 3: \n        msg.payload = \"Радуга гориз.\";\n        break;\n    case 4: \n        msg.payload = \"Смена цвета\";\n        break;\n    case 5: \n        msg.payload = \"Безумие 3D\";\n        break;\n    case 6: \n        msg.payload = \"Облака 3D\";\n        break;\n    case 7: \n        msg.payload = \"Лава 3D\";\n        break;\n    case 8: \n        msg.payload = \"Плазма 3D\";\n        break;\n    case 9: \n        msg.payload = \"Радуга 3D\";\n        break;\n    case 10: \n        msg.payload = \"Павлин 3D\";\n        break;\n    case 11: \n        msg.payload = \"Зебра 3D\";\n        break;\n    case 12: \n        msg.payload = \"Лес 3D\";\n        break;\n    case 13: \n        msg.payload = \"Океан 3D\";\n        break;\n    case 14: \n        msg.payload = \"Цвет\";\n        break;\n    case 15: \n        msg.payload = \"Снегопад\";\n        break;\n    case 16: \n        msg.payload = \"Матрица\";\n        break;\n    case 17: \n        msg.payload = \"Светлячки\";\n        break;\n    case 18: \n        msg.payload = \"Аквариум\";\n        break;\n    case 19: \n        msg.payload = \"Звездопад\";\n        break;\n    case 20: \n        msg.payload = \"Пейнтбол\";\n        break;\n    case 21: \n        msg.payload = \"Спираль\";\n        break;\n    case 22: \n        msg.payload = \"Теплый свет\";\n        break;\n    case 23: \n        msg.payload = \"Маятник\";\n        break;\n    case 24: \n        msg.payload = \"Мерцание\";\n        break;\n    case 25: \n        msg.payload = \"Полицейская сирена\";\n        break;\n    case 26: \n        msg.payload = \"Дрейф\";\n        break;\n    case 27: \n        msg.payload = \"Стая\";\n        break;\n    case 28: \n        msg.payload = \"Мотыльки в банке\";\n        break;\n    case 29: \n        msg.payload = \"Демо\";\n        break;\n}\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "x": 900,
        "y": 300,
        "wires": [
            [
                "3908f3c0.aff6ac"
            ]
        ]
    },
    {
        "id": "3908f3c0.aff6ac",
        "type": "mqtt out",
        "z": "a4fd6b01.5ef658",
        "name": "Effect",
        "topic": "homeassistant/light/ESP-cda520/effect/set",
        "qos": "2",
        "retain": "false",
        "broker": "2848f647.f877da",
        "x": 1050,
        "y": 300,
        "wires": []
    },
    {
        "id": "c36e6e3.7b6b89",
        "type": "comment",
        "z": "a4fd6b01.5ef658",
        "name": "Gyver Lamp Flow",
        "info": "",
        "x": 100,
        "y": 40,
        "wires": []
    },
    {
        "id": "2848f647.f877da",
        "type": "mqtt-broker",
        "name": "mosquitto",
        "broker": "localhost",
        "port": "1883",
        "clientid": "",
        "usetls": false,
        "compatmode": false,
        "keepalive": "60",
        "cleansession": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthPayload": "",
        "closeTopic": "",
        "closeQos": "0",
        "closePayload": "",
        "willTopic": "",
        "willQos": "0",
        "willPayload": ""
    },
    {
        "id": "473d7e83.83852",
        "type": "alice-device",
        "service": "bb49e58e.37a968",
        "name": "Лампа Гайвера",
        "description": "",
        "room": "Комната",
        "dtype": "devices.types.light"
    },
    {
        "id": "bb49e58e.37a968",
        "type": "alice-service",
        "name": "email"
    }
] 

Что умеет это устройство:

  1. Включение/выключение
  2. Регулирование яркости
  3. Изменение цвета в режиме цвет
  4. Изменение режимов как каналов в телевизоре.
@Whilser Whilser pinned this issue Jan 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant