BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

My home automation projects built with MQTT and Node Red

node-red
mqtt
home_automation

#41

Yes I did.


#42

Hmmm… I guess the MagicHome UFO node needs to be configured as well. When I put this node on my flow and deploy it, it fills everything else because it’s not configured. That’s why the screenshot of my flow shows the Alexa and MagicHome nodes with red dots against them.

What does it say if you type node-red-start in the command line of your Pi?

Pete.


#43

pi@hassbian:~ $ node-red
3 Nov 13:29:38 - [info]

Welcome to Node-RED
===================

3 Nov 13:29:38 - [info] Node-RED version: v0.19.4
3 Nov 13:29:38 - [info] Node.js  version: v8.11.1
3 Nov 13:29:38 - [info] Linux 4.14.71-v7+ arm LE
3 Nov 13:29:43 - [info] Loading palette nodes
3 Nov 13:29:58 - [info] Dashboard version 2.10.0 started at /ui
3 Nov 13:29:59 - [info] Settings file  : /home/pi/.node-red/settings.js
3 Nov 13:29:59 - [info] Context store  : 'default' [module=memory]
3 Nov 13:29:59 - [info] User directory : /home/pi/.node-red
3 Nov 13:29:59 - [warn] Projects disabled : editorTheme.projects.enabled=false
3 Nov 13:29:59 - [info] Flows file     : /home/pi/.node-red/flows_hassbian.json
3 Nov 13:29:59 - [info] Server now running at http://127.0.0.1:1880/
3 Nov 13:30:00 - [warn]

---------------------------------------------------------------------
Your flow credentials file is encrypted using a system-generated key.

If the system-generated key is lost for any reason, your credentials
file will not be recoverable, you will have to delete it and re-enter
your credentials.

You should set your own key using the 'credentialSecret' option in
your settings file. Node-RED will then re-encrypt your credentials
file using your chosen key the next time you deploy a change.
---------------------------------------------------------------------

3 Nov 13:30:00 - [info] Starting flows
3 Nov 13:30:00 - [info] [blynk-ws-client:50178c3e.8203c4] LOG PINS ["0"]
3 Nov 13:30:00 - [info] [blynk-ws-client:50178c3e.8203c4]  ws:///xxx.xxx.xxx.xxx/websockets
3 Nov 13:30:00 - [info] [blynk-ws-client:Development] LOG PINS ["0"]
3 Nov 13:30:00 - [info] [blynk-ws-client:Development]  ws://xxx.xxx.xxx.xxx/websockets
Callback URL = http:///xxx.xxx.xxx.xxx:1880/wemoNG/notification
3 Nov 13:30:00 - [info] [blynk-ws-client:50178c3e.8203c4] Register input node - type: style-btn pin: 37
3 Nov 13:30:00 - [info] [blynk-ws-client:50178c3e.8203c4] Register input node - type: write pin: 37
3 Nov 13:30:01 - [info] [blynk-ws-client:50178c3e.8203c4] Register email node
3 Nov 13:30:01 - [info] [MagicHome UFO:Living Room Strip] RGBW
3 Nov 13:30:01 - [info] [blynk-ws-client:50178c3e.8203c4] Register input node - type: zergba pin: 40
3 Nov 13:30:01 - [info] [MagicHome UFO:Living Room Strip] RGBW
3 Nov 13:30:01 - [info] [blynk-ws-client:50178c3e.8203c4] Register input node - type: zergba pin: 40
3 Nov 13:30:01 - [info] [blynk-ws-client:50178c3e.8203c4] Register input node - type: zergba pin: 40
3 Nov 13:30:02 - [info] [blynk-ws-client:Development] Register input node - type: write pin: 2
3 Nov 13:30:02 - [info] [blynk-ws-client:50178c3e.8203c4] Register input node - type: write pin: 37
3 Nov 13:30:02 - [info] [blynk-ws-client:Development] Register input node - type: zergba pin: 1
3 Nov 13:30:02 - [info] [MagicHome UFO:3ebf6e5b.4ac8a2] RGBW
3 Nov 13:30:02 - [info] Started flows
3 Nov 13:30:02 - [info] [mqtt-broker:MQTT] Connected to broker: mqtt:///xxx.xxx.xxx.xxx:1883
3 Nov 13:30:02 - [error] [alexa-home-conf:aaf3258b.fe05a8] Error: connect ECONNREFUSED 34.240.81.189:8883
3 Nov 13:30:02 - [error] [alexa-home-conf:83b02cb9.19b74] Error: connect ECONNREFUSED 34.240.81.189:8883
3 Nov 13:30:02 - [info] [blynk-ws-client:Development] login -> ***************************5eb45
3 Nov 13:30:02 - [info] [blynk-ws-client:Development] SEND -> Cmd: LOGIN, Id: 1, len: 32, data: "***************************5eb45"
3 Nov 13:30:02 - [info] [blynk-ws-client:50178c3e.8203c4] Client logged
3 Nov 13:30:02 - [info] [blynk-ws-client:Development] RECV <- Cmd: RSP, Id: 1, responseCode: OK
3 Nov 13:30:02 - [info] [blynk-ws-client:Development] Client logged
3 Nov 13:30:02 - [info] [blynk-ws-client:Development] SEND -> Cmd: INTERNAL, Id: 2, len: 82, data: "ver|0.5.3|h-beat|10|buff-in|32767|dev|node-red|con|Blynk-ws|build|0.7.1 2018-08-04"
3 Nov 13:30:02 - [info] [blynk-ws-client:Development] RECV <- Cmd: RSP, Id: 2, responseCode: OK
3 Nov 13:30:07 - [red] Uncaught Exception:
3 Nov 13:30:07 - Error: connect ECONNREFUSED 127.0.0.1:5577
    at Object._errnoException (util.js:1022:11)
    at _exceptionWithHostPort (util.js:1044:20)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1198:14)
pi@hassbian:~ $

#44

The Blynk websockets client called Development is what I’ve called my WS connection, so I think you must have a node that hasn’t been changed over to one of your connections.

If Node-red wont start because of this, you could try restoring your old flows file. In your case this is called /home/pi/.node-red/flows_hassbian.json,backup and needs to be re-named flows_hassbian.json

Alternatively, you could try editing your flows file, which in your case is at /home/pi/.node-red/flows_hassbian.json
Make a backup first then search the file for “Development” and you’ll find the ID of that connection

    {
        "id": "859549ef.52e4b8",
        "type": "blynk-ws-client",
        "z": "",
        "name": "Development",
        "path": "ws://blynk-cloud.com/websockets",
        "key": "21c69accfxxxxxxxxx90", // Redacted before posting
        "dbg_all": false,
        "dbg_read": false,
        "dbg_write": false,
        "dbg_notify": false,
        "dbg_mail": false,
        "dbg_prop": false,
        "dbg_sync": false,
        "dbg_bridge": false,
        "dbg_low": false,
        "dbg_pins": "",
        "multi_cmd": false,
        "proxy_type": "no",
        "proxy_url": ""
    },

If you then search for that ID (859549ef.52e4b8 in my example above) then you’ll find the node(s) that are using it and you can change this to your connection ID which seems to be “50178c3e.8203c4”. You should then be able to delete the Development connection data and save the file then stop/start Node-Red.

Pete.


#45

I deleted all new Flows (today flows ) and still can’t run Node-Red ?

pi@hassbian:~ $ /home/pi/.node-red/flows_hassbian.json,backup
-bash: /home/pi/.node-red/flows_hassbian.json,backup: No such file or directory
pi@hassbian:~ $


pi@hassbian:~ $ /home/pi/.node-red/flows_hassbian.json
-bash: /home/pi/.node-red/flows_hassbian.json: Permission denied
pi@hassbian:~ $

#46

I think the first message is because it needs to see a backup file there. If you create an empty file (with the correct permissions) then it should be fine.
The second is permissions on the flows file. It will need to have read/write permissions for the user that node-red is running under (Pi maybe?).
If you’re using WinSCP then you can right click on the file file and change the properties and owner. Mine looks like this:

image

Pete.


#47

not working correctly. the o/p at Magic Home is turned on then off with different colors.
same happened when you press the on / off or move the slider.

I will test each function tomorrow and let you know


#48

Okay.
The problem is that the documentation for the MagicHome node is a bit sketch to say the least, and without and MagicHome hardware of my own to test it with it’s difficult to work-out what’s happening.

However, your screenshot shows that a value of 255,0,2 was received from the zeRGBa and the Calc Brightness node shows “Dimmed 2114,0,17” which is obviously an illegal value.

However, when I do the same thing, my Calc Brightness node shows “Dimmed 128,0,1” which is exactly what I’d expect from this input.
Your debug messages are also showing some colour values with too many digits.

I’m not sure why this is happening though!

Pete.


#49

more info about MagicHome UFO that may help you
MagicHome output on the PuTTY screen colors are [ W, R, G, B, M, Y, C, OFF]

4 Nov 06:07:14 - [info] [MagicHome UFO:Living Room Strip] #00000
4 Nov 06:07:14 - [info] [MagicHome UFO:Living Room Strip] 0, 0, 0, 0, 0
4 Nov 06:07:14 - [info] [MagicHome UFO:Living Room Strip] #FFFFFF00
4 Nov 06:07:14 - [info] [MagicHome UFO:Living Room Strip] 255, 255, 255, 0, 0
4 Nov 06:08:07 - [info] [MagicHome UFO:Living Room Strip] #00000
4 Nov 06:08:07 - [info] [MagicHome UFO:Living Room Strip] 0, 0, 0, 0, 0
4 Nov 06:08:07 - [info] [MagicHome UFO:Living Room Strip] #FF000000
4 Nov 06:08:07 - [info] [MagicHome UFO:Living Room Strip] 255, 0, 0, 0, 0
4 Nov 06:08:13 - [info] [MagicHome UFO:Living Room Strip] #00000
4 Nov 06:08:13 - [info] [MagicHome UFO:Living Room Strip] 0, 0, 0, 0, 0
4 Nov 06:08:13 - [info] [MagicHome UFO:Living Room Strip] #00FF0000
4 Nov 06:08:13 - [info] [MagicHome UFO:Living Room Strip] 0, 255, 0, 0, 0
4 Nov 06:08:24 - [info] [MagicHome UFO:Living Room Strip] #00000
4 Nov 06:08:24 - [info] [MagicHome UFO:Living Room Strip] 0, 0, 0, 0, 0
4 Nov 06:08:24 - [info] [MagicHome UFO:Living Room Strip] #0000FF00
4 Nov 06:08:24 - [info] [MagicHome UFO:Living Room Strip] 0, 0, 255, 0, 0
4 Nov 06:08:55 - [info] [MagicHome UFO:Living Room Strip] #00000
4 Nov 06:08:55 - [info] [MagicHome UFO:Living Room Strip] 0, 0, 0, 0, 0
4 Nov 06:08:55 - [info] [MagicHome UFO:Living Room Strip] #FF00FF00
4 Nov 06:08:55 - [info] [MagicHome UFO:Living Room Strip] 255, 0, 255, 0, 0
4 Nov 06:09:02 - [info] [MagicHome UFO:Living Room Strip] #00000
4 Nov 06:09:02 - [info] [MagicHome UFO:Living Room Strip] 0, 0, 0, 0, 0
4 Nov 06:09:02 - [info] [MagicHome UFO:Living Room Strip] #FFFF0000
4 Nov 06:09:02 - [info] [MagicHome UFO:Living Room Strip] 255, 255, 0, 0, 0
4 Nov 06:09:11 - [info] [MagicHome UFO:Living Room Strip] #00000
4 Nov 06:09:11 - [info] [MagicHome UFO:Living Room Strip] 0, 0, 0, 0, 0
4 Nov 06:09:11 - [info] [MagicHome UFO:Living Room Strip] #00FFFF00
4 Nov 06:09:11 - [info] [MagicHome UFO:Living Room Strip] 0, 255, 255, 0, 0
4 Nov 06:09:46 - [info] [MagicHome UFO:Living Room Strip] #00000
4 Nov 06:09:46 - [info] [MagicHome UFO:Living Room Strip] 0, 0, 0, 0, 0
4 Nov 06:09:46 - [info] [MagicHome UFO:Living Room Strip] #00000000
4 Nov 06:09:46 - [info] [MagicHome UFO:Living Room Strip] 0, 0, 0, 0, 0

don’t ask me about the 5th “0”.


#50

Clipboard Copy of Flow Code

[
    {
        "id": "4e47329e.fd121c",
        "type": "blynk-ws-zergba",
        "z": "1b5ef425.fdae0c",
        "name": "",
        "pin": "40",
        "client": "85df424e.f59f5",
        "x": 250,
        "y": 240,
        "wires": [
            [
                "38319350.dd8f6c"
            ]
        ]
    },
    {
        "id": "38319350.dd8f6c",
        "type": "function",
        "z": "1b5ef425.fdae0c",
        "name": "zeRGBa to MagicHome",
        "func": "msg.payload = {\"on\":  true,\"brightness\": 0,\"color\": msg.hex+\"00\"}\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "x": 590,
        "y": 240,
        "wires": [
            [
                "f62bae61.99ffe"
            ]
        ]
    },
    {
        "id": "f62bae61.99ffe",
        "type": "MagicHome UFO",
        "z": "1b5ef425.fdae0c",
        "name": "Living Room Strip",
        "ip": "192.168.xxx.xxx",
        "style": "RGBW",
        "x": 950,
        "y": 240,
        "wires": [
            [
                "228a1ff0.016f7"
            ]
        ]
    },
    {
        "id": "8c9d7e31.bb53",
        "type": "inject",
        "z": "1b5ef425.fdae0c",
        "name": "OFF",
        "topic": "",
        "payload": "{\"on\":false,\"brightness\":0,\"color\":\"#00000000\"}",
        "payloadType": "json",
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "x": 690,
        "y": 160,
        "wires": [
            [
                "f62bae61.99ffe"
            ]
        ]
    },
    {
        "id": "228a1ff0.016f7",
        "type": "debug",
        "z": "1b5ef425.fdae0c",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "x": 1190,
        "y": 240,
        "wires": []
    },
    {
        "id": "78741757.5138d8",
        "type": "inject",
        "z": "1b5ef425.fdae0c",
        "name": "BLUE",
        "topic": "",
        "payload": "{\"on\":true,\"brightness\":0,\"color\":\"#0000FF00\"}",
        "payloadType": "json",
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "x": 690,
        "y": 120,
        "wires": [
            [
                "f62bae61.99ffe"
            ]
        ]
    },
    {
        "id": "a8ac8b68.cbaf98",
        "type": "inject",
        "z": "1b5ef425.fdae0c",
        "name": "GREEN",
        "topic": "",
        "payload": "{ \"on\":  true,\"brightness\": 0,\"color\": \"#00FF0000\"}",
        "payloadType": "json",
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "x": 690,
        "y": 80,
        "wires": [
            [
                "f62bae61.99ffe"
            ]
        ]
    },
    {
        "id": "a6bf263c.d4e5f8",
        "type": "inject",
        "z": "1b5ef425.fdae0c",
        "name": "RED",
        "topic": "",
        "payload": "{ \"on\":  true,\"brightness\": 0,\"color\": \"#FF000000\"}",
        "payloadType": "json",
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "x": 690,
        "y": 40,
        "wires": [
            [
                "f62bae61.99ffe"
            ]
        ]
    },
    {
        "id": "82ccaf8d.392de",
        "type": "inject",
        "z": "1b5ef425.fdae0c",
        "name": "ON",
        "topic": "",
        "payload": "{\"on\":true,\"brightness\":0,\"color\":\"#FFFFFF00\"}",
        "payloadType": "json",
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "x": 530,
        "y": 160,
        "wires": [
            [
                "f62bae61.99ffe"
            ]
        ]
    },
    {
        "id": "4e1f16da.9c9178",
        "type": "inject",
        "z": "1b5ef425.fdae0c",
        "name": "CYAN",
        "topic": "",
        "payload": "{\"on\":true,\"brightness\":0,\"color\":\"#00FFFF00\"}",
        "payloadType": "json",
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "x": 530,
        "y": 120,
        "wires": [
            [
                "f62bae61.99ffe"
            ]
        ]
    },
    {
        "id": "42104ce1.4159f4",
        "type": "inject",
        "z": "1b5ef425.fdae0c",
        "name": "YELLOW",
        "topic": "",
        "payload": "{\"on\":true,\"brightness\":0,\"color\":\"#FFFF0000\"}",
        "payloadType": "json",
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "x": 540,
        "y": 80,
        "wires": [
            [
                "f62bae61.99ffe"
            ]
        ]
    },
    {
        "id": "eed16218.c8ded",
        "type": "inject",
        "z": "1b5ef425.fdae0c",
        "name": "MAGENTA",
        "topic": "",
        "payload": "{\"on\":true,\"brightness\":0,\"color\":\"#FF00FF00\"}",
        "payloadType": "json",
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "x": 540,
        "y": 40,
        "wires": [
            [
                "f62bae61.99ffe"
            ]
        ]
    },
    {
        "id": "85df424e.f59f5",
        "type": "blynk-ws-client",
        "z": "",
        "name": "",
        "path": "ws://xxx.xxx.xxx.xxx/websockets",
        "key": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx5eb45",
        "dbg_all": false,
        "dbg_read": false,
        "dbg_write": false,
        "dbg_notify": false,
        "dbg_mail": false,
        "dbg_prop": false,
        "dbg_sync": false,
        "dbg_bridge": false,
        "dbg_low": false,
        "dbg_pins": "",
        "multi_cmd": false,
        "proxy_type": "no",
        "proxy_url": ""
    }
]

#51

This Alexa Flow and Function is working OK for Colors but no for White and Brightness

11/4/2018, 9:20:45 AM[node: 586a8d11.ef2b64](http://192.168.xxx.xxx:1880/#)msg : Object
object
topic: ""
name: "Room"
_messageId: "bc595a52-24cc-43be-814d-8ac856783470"
_applianceId: "35277"
_confId: "bc4b6845.74d4e8"
command: "SetColorRequest"                       <<<<<<<<<<<<<<<<<<<<<<<<<<
extraInfo: object
payload: "#00ff00"
_msgid: "8046755.c081988"
hex: "#00ff00"
rgb: "00;ff;00"
r: 0
g: 255
b: 0

11/4/2018, 9:20:48 AM[node: 586a8d11.ef2b64](http://192.168.xxx.xxx:1880/#)msg : Object
object
payload: object
on: true
brightness: 0
color: "#00ff0000"
_msgid: "fec1a70.360eb58"
11/4/2018, 9:21:58 AM[node: 586a8d11.ef2b64](http://192.168.xxx.xxx:1880/#)msg : Object
object
topic: ""
name: "Room"
_messageId: "ebfccb3b-4fdc-47da-af13-df0a9dcfb29d"
_applianceId: "35277"
_confId: "bc4b6845.74d4e8"
command: "SetPercentageRequest"              <<<<<<<<<<<<<<<<<<<<<<<<
extraInfo: object
payload: "#NaNNaNNaN"
_msgid: "eb99a3ed.3880e"
hex: "#NaNNaNNaN"
rgb: "NaN;NaN;NaN"
r: NaN
g: NaN
b: NaN

Here is the Magic Home application for color selection and preset colors, there is also another page for White LEDs (color Temperature)

Alexa Voice Commands

I am adding here my Blynk app controlling RGB with Alexa


#52

What happens if you you change one of your inject nodes (blue in this case) so that the JSON string is like this:

{"color":"#0000FF00"}

With the MagicHome lights already on, does this successfully change the colour to Blue?

The limited documentation for the MgicHome UFO node implies that a color command will work on its own, provided that the node is on.

If the JSON above does work, could you try it without the “00” that;s been tagged on the end (just 0000FF)?

And, could you also try a JSON string with just an on/off command like this:
{“on”:true"}
{“on”:false}

If these work, does the MagicHome strip retain it’s existing color settings when you turn it off then on again?

Having run your demo flow with the inject nodes, I realised that the structure of the output from my two nodes that send data to Magichome is wrong.
It’s very easy to fix if the MagicHome node will accept just a color or on/off command on their own. It’s not too difficult to do if it needs the full command each time, but not quite as elegant.

As I said in my last post yesterday, there’s some difference between the way my flow works on my machine and on yours, as the display of the colours on the dimmed node are different, we need to get to the bottom of that before my flow will work for you.
I guess that the code in one of the function nodes has become corrupted, maybe as a result of you having to manually edit the flows file.
I’m going to paste the code for each of the functions below, to avoid any problems like last time…

Store RGB values:

// store the red green and blue values to flow-level variables so thatwe can use them
// later in the brightness calculation

flow.set('rr',msg.r);  // store the red value  
flow.set('gg',msg.g);  // store the green value  
flow.set('bb',msg.b);  // store the blue value 

return msg;

Process Alexa Output:

if (msg.command =="TurnOffRequest")
{
    node.status({text: "Off"});
    return [null, null, {'payload': "0"}];
}
    node.status({text: "On"});
if (msg.command =="TurnOnRequest")
{
    
    return [null, null, {'payload': "1"}]; 
}

if (msg.command =="SetPercentageRequest")
{
node.status({text: "Brightness " + msg.payload});    
    return [null, {'payload': msg.payload}, null]; 
}


if (msg.command =="SetColorRequest")
{

var hue = msg.payload.hue /360;
var sat = msg.payload.saturation;
var bri = msg.payload.brightness;

RGB=HSVtoRGB(hue, sat, bri) // Call the function below to convert Alexa output to RGB

// Split the result from the function into its constituent parts...
var RED = RGB.r; 
var BLUE = RGB.b;
var GREEN = RGB.g;

// Convert the parts into Hex values...
var RED_HEX = (RGB.r).toString(16);
if (RED_HEX == "0")
{
    RED_HEX="00"
}    

var GREEN_HEX = (RGB.g).toString(16);
if (GREEN_HEX == "0")
{
    GREEN_HEX="00"
}  

var BLUE_HEX = (RGB.b).toString(16);
if (BLUE_HEX == "0")
{
    BLUE_HEX="00"
}   


// Build a message called hex with the RGB Hex value, to mimic the zeRGBa Widget output
msg.hex = "#" +  RED_HEX + GREEN_HEX + BLUE_HEX;

// Replace msg.payload with the same RGB Hex value, to mimic the zeRGBa Widget output
msg.payload = "#" +  RED_HEX + GREEN_HEX + BLUE_HEX;

// Build a message called rgb with the RGB Hex value in a different format, to mimic the zeRGBa Widget output
msg.rgb = RED_HEX + ";" + GREEN_HEX + ";" + BLUE_HEX;

 
// Add the r, g & b objects to the message, to mimic the zeRGBa Widget output
msg.r=RED;
msg.g=GREEN;
msg.b=BLUE;

// Update the text on the node to show the RGB colour
node.status({text: "[" + RED + ", " + GREEN + ", " + BLUE + "]"});


// Output all the new message objects
return [msg, null, null]; 
}


// Function code taken from:
// https://stackoverflow.com/questions/17242144/javascript-convert-hsb-hsv-color-to-rgb-accurately
/* accepts parameters
 * h  Object = {h:x, s:y, v:z}
 * OR 
 *h, s, v
*/
function HSVtoRGB(h, s, v) {
    var r, g, b, i, f, p, q, t;
    if (arguments.length === 1) {
        s = h.s, v = h.v, h = h.h;
    }
    i = Math.floor(h * 6);
    f = h * 6 - i;
    p = v * (1 - s);
    q = v * (1 - f * s);
    t = v * (1 - (1 - f) * s);
    switch (i % 6) {
        case 0: r = v, g = t, b = p; break;
        case 1: r = q, g = v, b = p; break;
        case 2: r = p, g = v, b = t; break;
        case 3: r = p, g = q, b = v; break;
        case 4: r = t, g = p, b = v; break;
        case 5: r = v, g = p, b = q; break;
    }
    return {
        r: Math.round(r * 255),
        g: Math.round(g * 255),
        b: Math.round(b * 255)
    };
}

Calc Brightness - Note that I’ve changes the code so it now shows the brightness and new RGB value on the node text:

// initialise PingFailCount_1 to 0 if it doesn't exist already
var rr = flow.get('rr')||0; //existing red value
var gg = flow.get('gg')||0; //existing green value
var bb = flow.get('bb')||0; //existing blue value

var V = msg.payload; // Brightness value

var rrr = Math.round(rr*V/100); // dimmed red value
var ggg = Math.round(gg*V/100); // dimmed green value
var bbb = Math.round(bb*V/100); // dimmed blue value

node.status({text: V + "% " + "[" + rrr + ", " + ggg + ", " + bbb + "]"});  

// Convert the parts into Hex values...
var RED_HEX = (rrr).toString(16);
if (RED_HEX == "0")
{
    RED_HEX="00"
}    

var GREEN_HEX = (ggg).toString(16);
if (GREEN_HEX == "0")
{
    GREEN_HEX="00"
}  

var BLUE_HEX = (bbb).toString(16);
if (BLUE_HEX == "0")
{
    BLUE_HEX="00"
}   

// Build a message called hex with the RGB Hex value, to mimick the zeRGBa Widget output
msg.hex = "#" +  RED_HEX + GREEN_HEX + BLUE_HEX;

return msg;

Output Dimmed RGB values to MagicHome - Note JSON format corrected:

return [{'color': msg.hex + "00"}]; 

Output On/Off command to MagicHome - Note JSON output format corrected

if (msg.payload =="0")
{
   return [{'on': "false"}]; 
}

if (msg.payload =="1")
{
   return [{'on': "true"}]; 
}

As well as trying the different inject nodes, could you paste this code into the corresponding functions and try it. Kep an eye on the node text on “Calc Brightness” to see if you get the correct values, or if you’re still getting illegal values (greater than 255 for any colour).

Pete.


#53

Yes.
{"on":true,"brightness":null,"color":"#0000ff00"}

when I tested before it was not working but today YES it works.

Yes.
{"on":false,"brightness":0,"color":"#0000ff00"}

sorry, It was my fault I forget to adjust the slider range from 0 - 100 .


#54

So it’s now working as it should?

Pete.


#55

No Pete as before.


#56

And this is with the updated functions?

Also, I’m a bit confused about your response to my question about whether changing the inject node on your previous sketch to just send colour information - without on/off or brightness actually works. I don’t understand the brightness:null and colour 0000ff00 data in these comments:

Pete.


#57

Yes, without on/off or brightness only the Color.

{“on”:true,“brightness”:null,“color”:"#0000ff00"} this was the payload.


#58

But what happens if you leave brightness and colour out of the JSON altogether, does just on: true turn it on?

And, does just colour: 0000ff turn it to Blue when it’s already on?

Pete.


#59

if it is off (on: false) and you inject only color it remains off.
on: must be true for magic home to work.
also if on: is true and you inject a “#000000” it turns off (visual).

Yes.


#60

In that case, I cant see why its nor working (assuming that you’ve updated the “Output Dimmed RGB values to MagicHome” and “Output On/Off command to MagicHome” functions with the code I supplied earlier today.

Maybe we should knock-off the dummybrightness data and just go for:

Output Dimmed RGB values to MagicHome

return [{'color': msg.hex}]; 

Output On/Off command to MagicHome

if (msg.payload =="0")
{
   return [{'on': "false"}]; 
}

if (msg.payload =="1")
{
   return [{'on': "true"}]; 
}

I read the bit about " brightness - Set the brightness of the LEDs, note LEDs must be on for this to have an effect." in the limited documentation.
I’ve worked on the principal that any Alexa commands to change the colour while the lights are off will be used to update Blynk, and when an On command is sent then the previously stored values from Blynk will be used.
However, as I’m writing this, I realise that I need to do the equivalent of a BlynkSyncVirtual on the ZeRGBa widget once the power on command is sent, so that the RGB strip is updated with the values that might have changes while it was off, and been ignored because it was off.

Doing this should fix that:
image

Also, if you’re using two different MagicHome UFO nodes on your flows, can you check that they’re configured exactly the same please?

If this doesn’t work, then can you send me some PuTTY output compariung the same commands ffrom your test flow and this flow?

Pete.