【Add-on Guide】Node-red

Release Note

2023.09.28 Update
node-red-contrib-ewelink-cube V1.1.0

  1. The control-device node now supports to:
    Change iHost Security Modes
    Adjust System Volume
    Adjust Alarm Volume
    Reverse ON/OFF status of switches/plugs

  2. The event-state node now supports to:
    Monitor the status of any channel on multiple-channel devices
    Monitor the Security Mode of iHost, and the Alarm status.

  3. Optimized the Register-device node and renamed it as Virtual-device

  4. The ewelink-cube nodes now will automatically search the iHost in LAN


Detailed Guide

How to install Node-RED add-on in CUBE?

  • Tap ‘+’ on the upper right and search for Node-red

  • Select noderred/node-red and add it

  • Tap ‘INSTALL’ to install the add-on

  • Tap ‘RUN’ to open the settings, select network as ‘Bridge’ and fill in other parameters according to your needs, then tap ‘RUN’

  • Wait a while and open a new browser tab to visit the Node-red page, the default URL is ihost.local:1880 or IP of iHost:1880 (for example 192.168.1.105:1880, you may find the IP on your router’s management page)

  • Click the menu on uper right and select ‘Manage palette’, search ewelink-cube and install


Just a quick question: did anyone try to access the speaker of the iHost form Node-Red? Like playing audio from Node-Red over the iHost speakers?

@csongor.varga yes, you can.

Using control-device node to play the internal sounds.

Or if you want a custom sound, you can use the REST API:

Payload:

msg.payload = {
audio_url: ‘https://download.samplelib.com/mp3/sample-12s.mp3
};

return msg;

POST Url: http://< ip >/open-api/v1/rest/media/audio-player

Only works with urls.

1 Like

Wow thanks. I have to try this out. Maybe I can host the files in a node-red static folder so it can be downloaded locally.

How did you set up the control-device node? For me it ignores the payload, just plays an alarm.

[
    {
        "id": "594490b18b08bc96",
        "type": "group",
        "z": "33295e77705cae31",
        "style": {
            "stroke": "#999999",
            "stroke-opacity": "1",
            "fill": "none",
            "fill-opacity": "1",
            "label": true,
            "label-position": "nw",
            "color": "#a4a4a4"
        },
        "nodes": [
            "aab38c244688cd63",
            "41e07a2c45cfcc9d",
            "3ff0c534c313f4f7",
            "2517bd6dba53e36e",
            "f113aaf8d4ffeffb",
            "a08015c90d109885",
            "7d241de5acc0278d"
        ],
        "x": 174,
        "y": 139,
        "w": 972,
        "h": 142
    },
    {
        "id": "aab38c244688cd63",
        "type": "control-device",
        "z": "33295e77705cae31",
        "g": "594490b18b08bc96",
        "name": "",
        "server": "e37d70fa8f41c384",
        "list": "{\"type\":\"ihost\",\"deviceId\":\"ihost\",\"ihostParams\":{\"ModeType\":\"alarmBell\",\"securityMode\":null,\"systemVolume\":\"\",\"systemVolumeValue\":\"\",\"alarmSound\":\"alert1\",\"alarmVolume\":\"50\",\"armedTime\":\"customize\",\"minute\":\"\",\"second\":\"5\"}}",
        "category": "all",
        "device": "ihost",
        "action": "",
        "x": 1040,
        "y": 180,
        "wires": [
            []
        ]
    },
    {
        "id": "41e07a2c45cfcc9d",
        "type": "function",
        "z": "33295e77705cae31",
        "g": "594490b18b08bc96",
        "name": "function 2",
        "func": "return msg.payload.emeters;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 500,
        "y": 180,
        "wires": [
            [
                "3ff0c534c313f4f7",
                "f113aaf8d4ffeffb"
            ]
        ]
    },
    {
        "id": "3ff0c534c313f4f7",
        "type": "switch",
        "z": "33295e77705cae31",
        "g": "594490b18b08bc96",
        "name": "",
        "property": "power",
        "propertyType": "msg",
        "rules": [
            {
                "t": "gt",
                "v": "3700",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 1,
        "x": 650,
        "y": 180,
        "wires": [
            [
                "2517bd6dba53e36e"
            ]
        ]
    },
    {
        "id": "2517bd6dba53e36e",
        "type": "delay",
        "z": "33295e77705cae31",
        "g": "594490b18b08bc96",
        "name": "",
        "pauseType": "rate",
        "timeout": "5",
        "timeoutUnits": "seconds",
        "rate": "1",
        "nbRateUnits": "1",
        "rateUnits": "minute",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": true,
        "allowrate": false,
        "outputs": 1,
        "x": 850,
        "y": 180,
        "wires": [
            [
                "aab38c244688cd63"
            ]
        ]
    },
    {
        "id": "f113aaf8d4ffeffb",
        "type": "debug",
        "z": "33295e77705cae31",
        "g": "594490b18b08bc96",
        "name": "Power Output",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 680,
        "y": 240,
        "wires": []
    },
    {
        "id": "a08015c90d109885",
        "type": "inject",
        "z": "33295e77705cae31",
        "g": "594490b18b08bc96",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 280,
        "y": 240,
        "wires": [
            [
                "7d241de5acc0278d"
            ]
        ]
    },
    {
        "id": "7d241de5acc0278d",
        "type": "shelly-gen1",
        "z": "33295e77705cae31",
        "g": "594490b18b08bc96",
        "hostname": "192.168.2.33",
        "description": "",
        "mode": "polling",
        "server": "",
        "outputmode": "event",
        "uploadretryinterval": 5000,
        "pollinginterval": "10000",
        "pollstatus": true,
        "getstatusoncommand": true,
        "devicetype": "Measure",
        "outputs": 2,
        "x": 270,
        "y": 180,
        "wires": [
            [
                "41e07a2c45cfcc9d"
            ],
            []
        ]
    },
    {
        "id": "e37d70fa8f41c384",
        "type": "api-server",
        "name": "Token",
        "ip": "127.0.0.1",
        "ipaddr": "",
        "token": "bef487e7-889e-43ac-8df2-2943ee5957cf"
    }
]


Sorry not this, the API call version. I tried setting up myself, but I get a error 400, headers.Authorization is invalid. What did you put into the header?

OK, I figured it out that I need to call the token generator URL to get a new token. I got it (see the second message in the debug). I added that to the audio-player call header, but I still get an error:

Remove the Header Autenticantion, and pick the option Use Authentication:

PS: are you using node-red with host or bridge network? If you use host, you can change the API url to 127.0.0.1 (because everytime you reset the ihost, the IP changes, at least to me :D)

Thanks it is working now.

About the IP: I set this as a reserver IP address for the mac address of the ihost to ensure it is the same all the time. And when I put 127.0.0.1 or localhost, or ihost.local it is not working. Am I missing something from the host file?

A slightly different question: did anyone successfully configured a static folder for Node-Red?
I created a static folder in filemanager in the node-red-files and also enabled this in the settings.js:

    httpStatic: 'static/', //single static source
    httpStaticRoot: '/static/',

But I am not really sure what is the full path of this folder inside the docker image. Do you know how to find it out?