Comments about "My home automation projects built with MQTT and Node Red" topic

Why is your MagicHome UFO node showing as Offline? Is it correctly configured?

Pete.

Yes, I just tried it.

because I don’t know js I can’t help you.
few days ago I found something interesting for you.
how to backup original firmware from ESP8266 or ESP8255 before flashing a new sketch.
you could have done it before flashing your Magic Home.

I’ve spent most of the evening trying to get the RGB controller that I hacked to work with Blynk re-flashed with Tasmota and working as a MagicHome device (which it’s supposed to support).
Although I can control it through Tasmota using MQTT, I can’t connect to it with either the MagicHome UFO node or the Magic home app on an iPhone.

What I have discovered is that while the MagicHome UFO node is in Disconnected state, Node-Red will keep restarting. If you open a Putty console and type node-red it will show the Node-Red console messages and as soon as the connection to the IP address of the MagicHome device is refused it throws an unhandled error and Node-Red restarts and tries again.

I’m not sure how to take this any further, as I wont be able to get hold of any working Node-Red hardware in the next couple of days and after that I’l be in Spain for a while.

I control my RGB devices by sending separate MQTT messages containing colour information for each channel. After what I’ve learned with this exercise, I’m going to change the way that I do this, with a single RRGGBB message instead. I’ll adopt the code that I’ve developed here so that I have full Alexa control out of the box, without the need to do any more processing on it.
Once I’ve got this working I’ll share the ESP sketch and if you want to re-flash your devices then you could do that. In the meantime, it would probably be worth you dong a bit more testing with the code to see if you can get any further and make sense of what’s happening when the messages are sent to the MagicHome device.

Pete.

Pete.

@PeteKnight Well Done Pete

IT IS WORKING now :laughing:

I adjusted the output to the same format I am receiving from the injected nodes.

Clipboard Copy

[
    {
        "id": "18134620.f45efa",
        "type": "blynk-ws-zergba",
        "z": "15e37b6b.837485",
        "name": "",
        "pin": "40",
        "client": "85df424e.f59f5",
        "x": 150,
        "y": 140,
        "wires": [
            [
                "55f7817.a5af98"
            ]
        ]
    },
    {
        "id": "2edf8d81.029a92",
        "type": "alexa-home",
        "z": "15e37b6b.837485",
        "conf": "bc4b6845.74d4e8",
        "device": "35277",
        "acknoledge": true,
        "name": "Room",
        "topic": "",
        "x": 110,
        "y": 280,
        "wires": [
            [
                "2cda05a9.7061ea"
            ]
        ]
    },
    {
        "id": "2cda05a9.7061ea",
        "type": "function",
        "z": "15e37b6b.837485",
        "name": "Process Alexa Output",
        "func": "if (msg.command ==\"TurnOffRequest\")\n{\n    node.status({ text: 'OFF' });\n    return [null, null, {'payload': '0' }];\n}\n\nif (msg.command ==\"TurnOnRequest\")\n{\n    node.status({ text: \"ON\" });  \n    return [null, null, {'payload': '1' }]; \n}\n\nif (msg.command ==\"SetPercentageRequest\")\n{\nnode.status({text: \"Brightness \" + msg.payload});    \n    return [null, {'payload': msg.payload}, null]; \n}\n\n\nif (msg.command ==\"SetColorRequest\")\n{\n\nvar hue = msg.payload.hue /360;\nvar sat = msg.payload.saturation;\nvar bri = msg.payload.brightness;\n\nRGB=HSVtoRGB(hue, sat, bri) // Call the function below to convert Alexa output to RGB\n\n// Split the result from the function into its constituent parts...\nvar RED = RGB.r; \nvar BLUE = RGB.b;\nvar GREEN = RGB.g;\n\n// Convert the parts into Hex values...\nvar RED_HEX = (RGB.r).toString(16);\nif (RED_HEX == \"0\")\n{\n    RED_HEX=\"00\"\n}    \n\nvar GREEN_HEX = (RGB.g).toString(16);\nif (GREEN_HEX == \"0\")\n{\n    GREEN_HEX=\"00\"\n}  \n\nvar BLUE_HEX = (RGB.b).toString(16);\nif (BLUE_HEX == \"0\")\n{\n    BLUE_HEX=\"00\"\n}   \n\n\n// Build a message called hex with the RGB Hex value, to mimic the zeRGBa Widget output\nmsg.hex = \"#\" +  RED_HEX + GREEN_HEX + BLUE_HEX;\n\n// Replace msg.payload with the same RGB Hex value, to mimic the zeRGBa Widget output\nmsg.payload = \"#\" +  RED_HEX + GREEN_HEX + BLUE_HEX;\n\n// Build a message called rgb with the RGB Hex value in a different format, to mimic the zeRGBa Widget output\nmsg.rgb = RED_HEX + \";\" + GREEN_HEX + \";\" + BLUE_HEX;\n\n \n// Add the r, g & b objects to the message, to mimic the zeRGBa Widget output\nmsg.r=RED;\nmsg.g=GREEN;\nmsg.b=BLUE;\n\n// Update the text on the node to show the RGB colour\nnode.status({text: \"[\" + RED + \", \" + GREEN + \", \" + BLUE + \"]\"});\n\n\n// Output all the new message objects\nreturn [msg, null, null]; \n}\n\n\n// Function code taken from:\n// https://stackoverflow.com/questions/17242144/javascript-convert-hsb-hsv-color-to-rgb-accurately\n/* accepts parameters\n * h  Object = {h:x, s:y, v:z}\n * OR \n *h, s, v\n*/\nfunction HSVtoRGB(h, s, v) {\n    var r, g, b, i, f, p, q, t;\n    if (arguments.length === 1) {\n        s = h.s, v = h.v, h = h.h;\n    }\n    i = Math.floor(h * 6);\n    f = h * 6 - i;\n    p = v * (1 - s);\n    q = v * (1 - f * s);\n    t = v * (1 - (1 - f) * s);\n    switch (i % 6) {\n        case 0: r = v, g = t, b = p; break;\n        case 1: r = q, g = v, b = p; break;\n        case 2: r = p, g = v, b = t; break;\n        case 3: r = p, g = q, b = v; break;\n        case 4: r = t, g = p, b = v; break;\n        case 5: r = v, g = p, b = q; break;\n    }\n    return {\n        r: Math.round(r * 255),\n        g: Math.round(g * 255),\n        b: Math.round(b * 255)\n    };\n}",
        "outputs": 3,
        "noerr": 0,
        "x": 300,
        "y": 280,
        "wires": [
            [
                "55f7817.a5af98",
                "45697ad0.4b5514"
            ],
            [
                "46db1b3.03d04e4",
                "5174c31b.a215ac"
            ],
            [
                "2f03c1d6.64b66e",
                "6fde450e.6fb65c"
            ]
        ],
        "inputLabels": [
            "Input from Alexa or zeRGBa"
        ],
        "outputLabels": [
            "RGB Data",
            "Brightness Data",
            "On/Off Command"
        ]
    },
    {
        "id": "55f7817.a5af98",
        "type": "function",
        "z": "15e37b6b.837485",
        "name": "Store RGB values",
        "func": "// store the red green and blue values to flow-level variables so thatwe can use them\n// later in the brightness calculation\n\nflow.set('rr',msg.r);  // store the red value  \nflow.set('gg',msg.g);  // store the green value  \nflow.set('bb',msg.b);  // store the blue value \n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "x": 390,
        "y": 140,
        "wires": [
            [
                "1c673b95.812c54"
            ]
        ]
    },
    {
        "id": "46db1b3.03d04e4",
        "type": "function",
        "z": "15e37b6b.837485",
        "name": "Calc Brightness",
        "func": "// initialise PingFailCount_1 to 0 if it doesn't exist already\nvar rr = flow.get('rr')||0; //existing red value\nvar gg = flow.get('gg')||0; //existing green value\nvar bb = flow.get('bb')||0; //existing blue value\n\nvar V = msg.payload; // Brightness value\n\nvar rrr = Math.round(rr*V/100); // dimmed red value\nvar ggg = Math.round(gg*V/100); // dimmed green value\nvar bbb = Math.round(bb*V/100); // dimmed blue value\n\nnode.status({text: V + \"% \" + \"[\" + rrr + \", \" + ggg + \", \" + bbb + \"]\"});  \n\n// Convert the parts into Hex values...\nvar RED_HEX = (rrr).toString(16);\nif (RED_HEX == \"0\")\n{\n    RED_HEX=\"00\"\n}    \n\nvar GREEN_HEX = (ggg).toString(16);\nif (GREEN_HEX == \"0\")\n{\n    GREEN_HEX=\"00\"\n}  \n\nvar BLUE_HEX = (bbb).toString(16);\nif (BLUE_HEX == \"0\")\n{\n    BLUE_HEX=\"00\"\n}   \n\n// Build a message called hex with the RGB Hex value, to mimick the zeRGBa Widget output\nmsg.hex = \"#\" +  RED_HEX + GREEN_HEX + BLUE_HEX;\n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "x": 600,
        "y": 360,
        "wires": [
            [
                "60e885a6.fe926c"
            ]
        ],
        "outputLabels": [
            "On/Off"
        ]
    },
    {
        "id": "21169dbc.504a62",
        "type": "blynk-ws-in-write",
        "z": "15e37b6b.837485",
        "name": "Slider Widget on V70  (0-100)",
        "pin": "70",
        "pin_all": 0,
        "client": "85df424e.f59f5",
        "x": 180,
        "y": 360,
        "wires": [
            [
                "46db1b3.03d04e4"
            ]
        ]
    },
    {
        "id": "5174c31b.a215ac",
        "type": "blynk-ws-out-write",
        "z": "15e37b6b.837485",
        "name": "Slider Widget V70 - Update Brightness value",
        "pin": "70",
        "pinmode": 0,
        "client": "85df424e.f59f5",
        "x": 690,
        "y": 280,
        "wires": []
    },
    {
        "id": "2f03c1d6.64b66e",
        "type": "function",
        "z": "15e37b6b.837485",
        "name": "Output On/Off command to MagicHome",
        "func": "if (msg.payload == '0')\n{\n   return [{'payload': { on :  false }}]; \n}\n\nif (msg.payload == '1'  )\n{\n   return [{'payload': { on :  true }}]; \n}\n",
        "outputs": 1,
        "noerr": 0,
        "x": 680,
        "y": 480,
        "wires": [
            [
                "779ca125.dcda6",
                "d5aad9b5.91ef98",
                "6b39eb1d.0d9064"
            ]
        ],
        "outputLabels": [
            "On/Off"
        ]
    },
    {
        "id": "6fde450e.6fb65c",
        "type": "blynk-ws-out-write",
        "z": "15e37b6b.837485",
        "name": "Button Widget V71 - Update On/Off satus",
        "pin": "71",
        "pinmode": 0,
        "client": "85df424e.f59f5",
        "x": 680,
        "y": 420,
        "wires": []
    },
    {
        "id": "5f319640.d67c88",
        "type": "blynk-ws-in-write",
        "z": "15e37b6b.837485",
        "name": "Button Widget on V71 (0/1)",
        "pin": "71",
        "pin_all": 0,
        "client": "85df424e.f59f5",
        "x": 170,
        "y": 480,
        "wires": [
            [
                "2f03c1d6.64b66e"
            ]
        ]
    },
    {
        "id": "45697ad0.4b5514",
        "type": "blynk-ws-zergba",
        "z": "15e37b6b.837485",
        "name": "zeRGBa Widget V40 - Update Colour value",
        "pin": "40",
        "client": "85df424e.f59f5",
        "x": 680,
        "y": 220,
        "wires": [
            []
        ]
    },
    {
        "id": "779ca125.dcda6",
        "type": "debug",
        "z": "15e37b6b.837485",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "x": 1190,
        "y": 480,
        "wires": []
    },
    {
        "id": "60e885a6.fe926c",
        "type": "function",
        "z": "15e37b6b.837485",
        "name": "Output Dimmed RGB values to MagicHome",
        "func": "return [{'payload':{ color :  msg.hex + \"00\"}}];\n",
        "outputs": 1,
        "noerr": 0,
        "x": 890,
        "y": 360,
        "wires": [
            [
                "779ca125.dcda6",
                "6b39eb1d.0d9064"
            ]
        ]
    },
    {
        "id": "1c673b95.812c54",
        "type": "blynk-ws-out-sync",
        "z": "15e37b6b.837485",
        "name": "",
        "pin": "70",
        "pinmode": 0,
        "client": "85df424e.f59f5",
        "x": 600,
        "y": 140,
        "wires": []
    },
    {
        "id": "6b39eb1d.0d9064",
        "type": "MagicHome UFO",
        "z": "15e37b6b.837485",
        "name": "Living Room Strip",
        "ip": "192.168.xxx.xxx",
        "style": "RGBW",
        "x": 1230,
        "y": 360,
        "wires": [
            []
        ]
    },
    {
        "id": "d5aad9b5.91ef98",
        "type": "blynk-ws-out-sync",
        "z": "15e37b6b.837485",
        "name": "",
        "pin": "40",
        "pinmode": 0,
        "client": "85df424e.f59f5",
        "x": 990,
        "y": 580,
        "wires": []
    },
    {
        "id": "64f47c0b.236424",
        "type": "inject",
        "z": "15e37b6b.837485",
        "name": "OFF",
        "topic": "",
        "payload": "{\"on\":false,\"brightness\":0,\"color\":\"#00000000\"}",
        "payloadType": "json",
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "x": 990,
        "y": 260,
        "wires": [
            [
                "6b39eb1d.0d9064"
            ]
        ]
    },
    {
        "id": "297a5ea5.534f32",
        "type": "inject",
        "z": "15e37b6b.837485",
        "name": "BLUE",
        "topic": "",
        "payload": "{\"on\":true,\"brightness\":0,\"color\":\"#0000FF\"}",
        "payloadType": "json",
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "x": 990,
        "y": 220,
        "wires": [
            [
                "6b39eb1d.0d9064"
            ]
        ]
    },
    {
        "id": "fad78792.045ec8",
        "type": "inject",
        "z": "15e37b6b.837485",
        "name": "GREEN",
        "topic": "",
        "payload": "{ \"on\":  true,\"brightness\": 0,\"color\": \"#00FF0000\"}",
        "payloadType": "json",
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "x": 990,
        "y": 180,
        "wires": [
            [
                "6b39eb1d.0d9064",
                "9d692024.c1487"
            ]
        ]
    },
    {
        "id": "e88303d8.e579c",
        "type": "inject",
        "z": "15e37b6b.837485",
        "name": "RED",
        "topic": "",
        "payload": "{ \"on\":  true,\"brightness\": 0,\"color\": \"#FF000000\"}",
        "payloadType": "json",
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "x": 990,
        "y": 140,
        "wires": [
            [
                "6b39eb1d.0d9064"
            ]
        ]
    },
    {
        "id": "9d692024.c1487",
        "type": "debug",
        "z": "15e37b6b.837485",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "x": 1190,
        "y": 180,
        "wires": []
    },
    {
        "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": ""
    },
    {
        "id": "bc4b6845.74d4e8",
        "type": "alexa-home-conf",
        "z": "",
        "username": "xxxx"
    }
]

PuTTy output

5 Nov 17:09:04 - [info] [MagicHome UFO:Living Room Strip] #00ff0000
5 Nov 17:09:04 - [info] [MagicHome UFO:Living Room Strip] 0, 255, 0, 0, 0
5 Nov 17:09:11 - [info] [MagicHome UFO:Living Room Strip] #00ff0000
5 Nov 17:09:11 - [info] [MagicHome UFO:Living Room Strip] 0, 255, 0, 0, 0
5 Nov 17:09:25 - [info] [MagicHome UFO:Living Room Strip] #ff000000
5 Nov 17:09:25 - [info] [MagicHome UFO:Living Room Strip] 255, 0, 0, 0, 0
5 Nov 17:09:31 - [info] [MagicHome UFO:Living Room Strip] #0000ff00
5 Nov 17:09:31 - [info] [MagicHome UFO:Living Room Strip] 0, 0, 255, 0, 0
5 Nov 17:09:39 - [info] [MagicHome UFO:Living Room Strip] #00008000
5 Nov 17:09:39 - [info] [MagicHome UFO:Living Room Strip] 0, 0, 128, 0, 0
5 Nov 17:09:46 - [info] [MagicHome UFO:Living Room Strip] #00808000
5 Nov 17:09:46 - [info] [MagicHome UFO:Living Room Strip] 0, 128, 128, 0, 0

1 Like

Hey @Ze_Pico that’s great!
Well-done for sticking with it. I’m sure there’s plenty of tweaking to do to get it working the way you want with all your devices and extra Blynk sliders etc, but at least we know that the basics now work.

Pete.

1 Like

@PeteKnight
Hi
This is a Tasmota RF Receiver working on 315 / 433 MHz

17:12:14 MQT: tele/sonoff33/RESULT = {"RfReceived":{"Data":"5545C0","Bits":24,"Protocol":1,"Pulse":450}}

I tried ready made Functions but I failed.

Here are My RF Remotes sending

object
topic: "tele/sonoff33/RESULT"
payload: "{"RfReceived":{"Data":"5545C0","Bits":24,"Protocol":1,"Pulse":450}}"
qos: 0 

After json function

payload: object
RfReceived: object
Data: "5545C0"
Bits: 24
Protocol: 1
Pulse: 450
qos: 0
retain: false

Tasmota Sonoff work OK with injected nodes but I need a function to match the RF code.

Thanks.

Hi @Ze_Pico
Presumably, the Sonoff sends different “Data” values if it receives an On or an Off signal?
and your Tasmota node just needs an “ON” or “OFF” payload?
I’ll assume that the “5545C0” data value is an On signal.

Put this in your function node and give it a whirl…

if (msg.data=="5545C0")
{
    msg.payload ="ON"
}

if (msg.data=="XXXXXX") // Your Off value in here...
{
    msg.payload ="OFF"
}

return msg;

Pete.

I tried this before but no result.

if (msg.data=="5545C0")  {  msg.payload ="ON" }
if (msg.data=="554530")  { msg.payload ="OFF" }
return msg;

I am receiving same o/p as the function is not present

My json is adj to
always convert to JS object

Okay, I looked a bit closer and the value that we need is actually nested in the payload, so it’s actually msg.payload.RfReceived.Data

I tried referencing it directly with if (msg.payload.RfReceived.Data=="5545C0") but it didn’t like that. It seems that the solution is to assign the value to a variable then compare against that…

var RF = msg.payload.RfReceived.Data;
node.status({text:RF});

if (RF=="5545C0")  {  msg.payload ="ON" }
if (RF=="554530")  { msg.payload ="OFF" }
return msg;

Pete.

1 Like

YES it works.
I Have two more questions for you.

1 Like

Oh, just to add, I found this handy tip in the documentation the other day…

When you hover over any element, a set of buttons appear on the right:

* : copies the path to the selected element to your clipboard. In this example, it will copy `payload.Phone[2].type` . This allows you to quickly determine how to access a property in a Change or Function node.
* : copies the value of the element to your clipboard as a JSON string. Note that the sidebar truncates Arrays and Buffers over a certain length. Copying the value of such a property will copy the truncated version.
* : pins the selected element so it is always displayed. When another message is received from the same Debug node, it is automatically expanded to show all pinned elements.

https://nodered.org/docs/user-guide/messages

It’s a handy way to work-out how to reference data nested within arrays etc.

Pete.

Fire away…

1-For alexa “Outside Light” you use white light temperature for countdown timer, am I correct ?

2- is it possible to use more than a blynk device with different Auth.

last and not least what is the easiest way to clone my PI SD card ? :smile:

thanks Pete

I think I actually used thermostat temperature (it’s something that I set-up as an example and have since deleted). I made a comment that negative and excessively high values are allowed, so you’d need to do some common sense rules to disallow negative values and silly time durations.

I assume that should read “…than one Blynk device…” ?
Yes, just create a new connection with the new Auth code. I give the connection the same name as the name in Blynk. Just make sure to select the correct connection when you add a new Blynk node, otherwise you’ll quickly get very confused about why things aren’t working!

I turn the Pi off, pop out the card and back it up to my HDD with Win32DiskManager.
I frequently back-up my Node-Red flows using Export/Clipboard and saving them as .txt files. You can also copy the flows file using WinSCP.

@Scargill has discussed his approach quite a few times in his blog:
https://tech.scargill.net/?s=backup

Pete.

I tried it before and again today but didn’t work, it cannot see the image .
I think it is Ext 4 formatted.

also I don’t know how to run the @Scargill script . :thinking:

I don’t think it always adds an .img file extension, so you may need to remove the filter from the open file dialogue box to find the backup files. Win32DiskManager certainly works correctly with the Pi and Windows, I restored a backup file with it only yesterday (after I did something very stupid!).

“The Script” that @Scargill refers to sometimes in his blog is a great tool, but is only used for a fresh install, so you don’t need to run it (there is a step-by-step guide here though…
https://tech.scargill.net/the-script-step-by-step/ ).

If you want to run a regular shell script then take a look at this guide:
http://www.circuitbasics.com/how-to-write-and-run-a-shell-script-on-the-raspberry-pi/

Pete.

sorry, a stupid question it is Win32DiskManager or Win32DiskImager

Sorry, my mistake, should be IMAGER.

Pete.

1 Like

Thanks a lot Pete. I saw a you-tube video on Win32DiskImager and now it is OK.
I manage to copy a 8 GB PI SD image on a 32 GB SD card.
Now everything is running smoothly .

1 Like

@PeteKnight

Salut Pete
Is there a better interpretation for this flow (a simplified version) ?

I need a “Countdown function” so I can see the remaining time on blynk LCD.

Clipboard copy.

[
    {
        "id": "6367c3d6.b0177c",
        "type": "mqtt in",
        "z": "bc3b6538.ad0c48",
        "name": "PIR  @ pin D1",
        "topic": "cmnd/sonoff34/PIR/POWER2",
        "qos": "1",
        "broker": "8a72da15.bf29b8",
        "x": 250,
        "y": 600,
        "wires": [
            [
                "494cfb77.d9ccc4",
                "67a2744.4069f8c"
            ]
        ],
        "outputLabels": [
            "ON / OFF"
        ]
    },
    {
        "id": "9712ba88.f25298",
        "type": "trigger",
        "z": "bc3b6538.ad0c48",
        "op1": "1",
        "op2": "0",
        "op1type": "str",
        "op2type": "str",
        "duration": "3",
        "extend": true,
        "units": "min",
        "reset": "Auto",
        "bytopic": "all",
        "name": "",
        "x": 610,
        "y": 600,
        "wires": [
            [
                "f03a60ed.f0863"
            ]
        ],
        "outputLabels": [
            "1/0"
        ]
    },
    {
        "id": "b4ddff7b.d38d",
        "type": "mqtt out",
        "z": "bc3b6538.ad0c48",
        "name": "LIGHT Relay @ pin D6",
        "topic": "cmnd/sonoff34/POWER",
        "qos": "1",
        "retain": "true",
        "broker": "8a72da15.bf29b8",
        "x": 1220,
        "y": 600,
        "wires": []
    },
    {
        "id": "67a2744.4069f8c",
        "type": "switch",
        "z": "bc3b6538.ad0c48",
        "name": "ON",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "ON",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 1,
        "x": 430,
        "y": 600,
        "wires": [
            [
                "9712ba88.f25298"
            ]
        ]
    },
    {
        "id": "4f27669.d202598",
        "type": "function",
        "z": "bc3b6538.ad0c48",
        "name": "Override",
        "func": "var over=global.get('overrideMain');\nif (msg.topic.includes(\"OVERRIDE\") || msg.topic.includes(\"alexa\")) {\n    if (msg.payload==\"Auto\"){\n        over=\"AUTO\";\n        global.set('overrideMain',over);\n        node.status({fill:\"blue\",shape:\"dot\",text:\"Override: \"+over}); \n        return msg;\n    } else {\n        if (msg.payload==\"1\") {\n            over=\"ON\";\n            node.status({fill:\"yellow\",shape:\"dot\",text:\"Override: \"+over});\n            msg.payload=\"ON\"\n        }\n        if (msg.payload==\"0\") {\n            over=\"OFF\";\n            node.status({fill:\"grey\",shape:\"dot\",text:\"Override: \"+over});\n            msg.payload=\"OFF\"\n        }\n    global.set('overrideMain',over);\n    return msg;\n    }\n} else {\n    if (over==\"ON\") msg.payload=\"1\";\n    if (over==\"OFF\") msg.payload=\"0\";\n    return msg;\n}",
        "outputs": 1,
        "noerr": 0,
        "x": 980,
        "y": 600,
        "wires": [
            [
                "b4ddff7b.d38d",
                "d981f2c4.da54f",
                "334bd5ad.1d3a9a"
            ]
        ]
    },
    {
        "id": "494cfb77.d9ccc4",
        "type": "function",
        "z": "bc3b6538.ad0c48",
        "name": "PIR",
        "func": "if (msg.payload==\"ON\") node.status({fill:\"yellow\",shape:\"ring\",text:msg.payload});\nelse node.status({fill:\"grey\",shape:\"ring\",text:msg.payload});    \nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "x": 310,
        "y": 680,
        "wires": [
            [
                "d6d6c320.3b94"
            ]
        ]
    },
    {
        "id": "d981f2c4.da54f",
        "type": "debug",
        "z": "bc3b6538.ad0c48",
        "name": "",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "x": 1210,
        "y": 660,
        "wires": []
    },
    {
        "id": "22699b.4547a666",
        "type": "ui_button",
        "z": "bc3b6538.ad0c48",
        "name": "OFF",
        "group": "73ce4f22.05854",
        "order": 1,
        "width": 0,
        "height": 0,
        "passthru": true,
        "label": "OFF",
        "color": "",
        "bgcolor": "",
        "icon": "",
        "payload": "0",
        "payloadType": "str",
        "topic": "MAIN/OVERRIDE/",
        "x": 690,
        "y": 300,
        "wires": [
            [
                "4f27669.d202598",
                "b286bb02.436018"
            ]
        ]
    },
    {
        "id": "7727ade9.1d25f4",
        "type": "ui_button",
        "z": "bc3b6538.ad0c48",
        "name": "ON",
        "group": "73ce4f22.05854",
        "order": 2,
        "width": "3",
        "height": "1",
        "passthru": true,
        "label": "ON",
        "color": "",
        "bgcolor": "",
        "icon": "",
        "payload": "1",
        "payloadType": "str",
        "topic": "MAIN/OVERRIDE/",
        "x": 690,
        "y": 260,
        "wires": [
            [
                "4f27669.d202598"
            ]
        ]
    },
    {
        "id": "93e292b1.7b363",
        "type": "ui_button",
        "z": "bc3b6538.ad0c48",
        "name": "AUTO",
        "group": "73ce4f22.05854",
        "order": 1,
        "width": 0,
        "height": 0,
        "passthru": true,
        "label": "AUTO",
        "color": "",
        "bgcolor": "",
        "icon": "",
        "payload": "Auto",
        "payloadType": "str",
        "topic": "MAIN/OVERRIDE/",
        "x": 690,
        "y": 340,
        "wires": [
            [
                "4f27669.d202598",
                "9712ba88.f25298",
                "2a16eb9a.9d1d84"
            ]
        ]
    },
    {
        "id": "803b78b6.3b58f8",
        "type": "ui_audio",
        "z": "bc3b6538.ad0c48",
        "name": "",
        "group": "73ce4f22.05854",
        "voice": "en-GB",
        "always": true,
        "x": 1220,
        "y": 700,
        "wires": []
    },
    {
        "id": "47ab51ee.edf15",
        "type": "Sonoff device",
        "z": "bc3b6538.ad0c48",
        "mode": "0",
        "broker": "8a72da15.bf29b8",
        "device": "sonoff34",
        "name": "Tasmota sonoff-34",
        "onValue": "ON",
        "offValue": "OFF",
        "cmdPrefix": "cmnd",
        "statPrefix": "stat",
        "telePrefix": "tele",
        "x": 1170,
        "y": 300,
        "wires": [
            []
        ]
    },
    {
        "id": "f2c8bb00.2c8fd8",
        "type": "inject",
        "z": "bc3b6538.ad0c48",
        "name": "ON",
        "topic": "",
        "payload": "ON",
        "payloadType": "str",
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "x": 250,
        "y": 260,
        "wires": [
            [
                "7727ade9.1d25f4",
                "dbc3c1cc.e3062"
            ]
        ]
    },
    {
        "id": "6b40b1cb.73071",
        "type": "inject",
        "z": "bc3b6538.ad0c48",
        "name": "OFF",
        "topic": "",
        "payload": "OFF",
        "payloadType": "str",
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "x": 250,
        "y": 300,
        "wires": [
            [
                "22699b.4547a666",
                "dbc3c1cc.e3062"
            ]
        ]
    },
    {
        "id": "825f08a8.6a1848",
        "type": "inject",
        "z": "bc3b6538.ad0c48",
        "name": "AUTO",
        "topic": "",
        "payload": "AUTO",
        "payloadType": "str",
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "x": 250,
        "y": 340,
        "wires": [
            [
                "93e292b1.7b363",
                "dbc3c1cc.e3062"
            ]
        ]
    },
    {
        "id": "d14328e4.7184a8",
        "type": "blynk-ws-in-write",
        "z": "bc3b6538.ad0c48",
        "name": "PB-ON",
        "pin": "1",
        "pin_all": 0,
        "client": "554f52d0.f2beac",
        "x": 230,
        "y": 80,
        "wires": [
            [
                "30fb5265.91086e"
            ]
        ]
    },
    {
        "id": "30fb5265.91086e",
        "type": "change",
        "z": "bc3b6538.ad0c48",
        "name": "Change from 1 to ON",
        "rules": [
            {
                "t": "change",
                "p": "payload",
                "pt": "msg",
                "from": "1",
                "fromt": "str",
                "to": "ON",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 440,
        "y": 100,
        "wires": [
            [
                "1fb6c432.e8d51c"
            ]
        ]
    },
    {
        "id": "1fb6c432.e8d51c",
        "type": "switch",
        "z": "bc3b6538.ad0c48",
        "name": "",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "ON",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "OFF",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "AUTO",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 3,
        "x": 670,
        "y": 140,
        "wires": [
            [
                "dbc3c1cc.e3062",
                "7727ade9.1d25f4"
            ],
            [
                "22699b.4547a666",
                "dbc3c1cc.e3062"
            ],
            [
                "93e292b1.7b363",
                "dbc3c1cc.e3062"
            ]
        ]
    },
    {
        "id": "91b07712.6efb08",
        "type": "blynk-ws-out-write",
        "z": "bc3b6538.ad0c48",
        "name": "LED PIR",
        "pin": "4",
        "pinmode": 0,
        "client": "554f52d0.f2beac",
        "x": 760,
        "y": 680,
        "wires": []
    },
    {
        "id": "d6d6c320.3b94",
        "type": "change",
        "z": "bc3b6538.ad0c48",
        "name": "Change from ON/OFF to 255/0",
        "rules": [
            {
                "t": "change",
                "p": "payload",
                "pt": "msg",
                "from": "ON",
                "fromt": "str",
                "to": "255",
                "tot": "str"
            },
            {
                "t": "change",
                "p": "payload",
                "pt": "msg",
                "from": "OFF",
                "fromt": "str",
                "to": "0",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 530,
        "y": 680,
        "wires": [
            [
                "91b07712.6efb08"
            ]
        ]
    },
    {
        "id": "18811f83.8514d",
        "type": "blynk-ws-in-write",
        "z": "bc3b6538.ad0c48",
        "name": "PB-AUTO",
        "pin": "3",
        "pin_all": 0,
        "client": "554f52d0.f2beac",
        "x": 240,
        "y": 200,
        "wires": [
            [
                "8bc458cb.3dc628"
            ]
        ]
    },
    {
        "id": "8bc458cb.3dc628",
        "type": "change",
        "z": "bc3b6538.ad0c48",
        "name": "Change 1 to AUTO",
        "rules": [
            {
                "t": "change",
                "p": "payload",
                "pt": "msg",
                "from": "1",
                "fromt": "str",
                "to": "AUTO",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 430,
        "y": 180,
        "wires": [
            [
                "1fb6c432.e8d51c"
            ]
        ]
    },
    {
        "id": "78115651.ceaf68",
        "type": "blynk-ws-in-write",
        "z": "bc3b6538.ad0c48",
        "name": "PB-OFF",
        "pin": "2",
        "pin_all": 0,
        "client": "554f52d0.f2beac",
        "x": 240,
        "y": 140,
        "wires": [
            [
                "5a8254b6.78f15c"
            ]
        ]
    },
    {
        "id": "5a8254b6.78f15c",
        "type": "change",
        "z": "bc3b6538.ad0c48",
        "name": "Change from 1 to OFF",
        "rules": [
            {
                "t": "change",
                "p": "payload",
                "pt": "msg",
                "from": "1",
                "fromt": "str",
                "to": "OFF",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 440,
        "y": 140,
        "wires": [
            [
                "1fb6c432.e8d51c"
            ]
        ]
    },
    {
        "id": "76bfb561.69da1c",
        "type": "blynk-ws-out-write",
        "z": "bc3b6538.ad0c48",
        "name": "ON",
        "pin": "1",
        "pinmode": 0,
        "client": "554f52d0.f2beac",
        "x": 1190,
        "y": 80,
        "wires": []
    },
    {
        "id": "dbc3c1cc.e3062",
        "type": "function",
        "z": "bc3b6538.ad0c48",
        "name": "ON/OFF/AUTO Override",
        "func": "   if (msg.payload==\"ON\") {\n        over=\"ON\";\n        global.set('overrideMain',over);\n        node.status({fill:\"yellow\",shape:\"dot\",text:\"Blynk Override: \"+over});\n//        msg.payload=\"ON\"\n    return [{'payload': '1' }, {'payload': '0' }, {'payload': '0' }]; \n    }\n    if (msg.payload==\"OFF\") {\n        over=\"OFF\";\n        node.status({fill:\"grey\",shape:\"dot\",text:\"Blynk Override: \"+over});\n//        msg.payload=\"OFF\"\n    return [{'payload': '0' }, {'payload': '1' }, {'payload': '0' }]; \n    }\n    if (msg.payload==\"AUTO\"){\n        over=\"AUTO\";\n        node.status({fill:\"blue\",shape:\"dot\",text:\"Blynk Override: \"+over}); \n    return [{'payload': '0' }, {'payload': '0' }, {'payload': '1' }]; \n    }\n//return msg;\n\n\nif (msg.command ==\"TurnOnRequest\")\n{\n//    node.status({ text: \"ON\" });  \n    node.status({fill:\"yellow\",shape:\"dot\",text:\"Alexa Override: ON\"});\n    return [ {'payload': '1' }, {'payload': '0' }, {'payload': '0' }]; \n}\nif (msg.command ==\"TurnOffRequest\")\n{\n//    node.status({ text: 'OFF' });\n    node.status({fill:\"grey\",shape:\"dot\",text:\"Alexa Override: OFF\"});\n    return [ {'payload': '0' }, {'payload': '1' }, {'payload': '0' }];\n}\n\n\nvar RF = msg.payload.RfReceived.Data;\nnode.status({text:RF});\n    if (RF==\"5545C0\")  { \n        node.status({fill:\"yellow\",shape:\"dot\",text:\"RF ON \" + RF})\n        return [{'payload': '1' }, {'payload': '0' }, {'payload': '0' }]; \n    }\n    if (RF== \"554530\") { \n        node.status({fill:\"grey\",shape:\"dot\",text:\"RF OFF \" + RF}); \n        return [{'payload': '0' }, {'payload': '1' }, {'payload': '0' }];\n    }   \n    if (RF== \"55450C\")  {\n        node.status({fill:\"blue\",shape:\"dot\",text:\"RF AUTO \"+ RF}); \n        return [{'payload': '0' }, {'payload': '0' }, {'payload': '1' }]; \n    }   \n//return msg;    \n   \n",
        "outputs": 3,
        "noerr": 0,
        "x": 930,
        "y": 140,
        "wires": [
            [
                "76bfb561.69da1c"
            ],
            [
                "a2ea3fa0.860f4",
                "b286bb02.436018"
            ],
            [
                "a5ce3d36.9ba9f"
            ]
        ]
    },
    {
        "id": "a2ea3fa0.860f4",
        "type": "blynk-ws-out-write",
        "z": "bc3b6538.ad0c48",
        "name": "OFF",
        "pin": "2",
        "pinmode": 0,
        "client": "554f52d0.f2beac",
        "x": 1190,
        "y": 140,
        "wires": []
    },
    {
        "id": "a5ce3d36.9ba9f",
        "type": "blynk-ws-out-write",
        "z": "bc3b6538.ad0c48",
        "name": "AUTO",
        "pin": "3",
        "pinmode": 0,
        "client": "554f52d0.f2beac",
        "x": 1190,
        "y": 200,
        "wires": []
    },
    {
        "id": "66f39b21.8fbab4",
        "type": "alexa-home",
        "z": "bc3b6538.ad0c48",
        "conf": "198887d9.6c0cc8",
        "device": "35277",
        "acknoledge": true,
        "name": "Room",
        "topic": "sonoff34/PIR/alexa",
        "x": 230,
        "y": 400,
        "wires": [
            [
                "4f27669.d202598",
                "dbc3c1cc.e3062"
            ]
        ]
    },
    {
        "id": "4d7d5e0d.24bc2",
        "type": "mqtt in",
        "z": "bc3b6538.ad0c48",
        "name": "RF @ pin D7",
        "topic": "tele/sonoff34/RESULT",
        "qos": "1",
        "broker": "8a72da15.bf29b8",
        "x": 250,
        "y": 500,
        "wires": [
            [
                "9bf73c71.30c8c"
            ]
        ]
    },
    {
        "id": "9bf73c71.30c8c",
        "type": "json",
        "z": "bc3b6538.ad0c48",
        "name": "",
        "property": "payload",
        "action": "obj",
        "pretty": false,
        "x": 450,
        "y": 500,
        "wires": [
            [
                "dbc3c1cc.e3062",
                "44b33006.f419c"
            ]
        ]
    },
    {
        "id": "44b33006.f419c",
        "type": "function",
        "z": "bc3b6538.ad0c48",
        "name": "Data to ON/OFF/AUTO",
        "func": "var RF = msg.payload.RfReceived.Data;\nnode.status({text:RF});\n\n    if (RF==\"5545C0\")  { \n        node.status({fill:\"yellow\",shape:\"dot\",text:\"RF ON \" + RF})\n        return [ {'payload': \"ON\" },  null ,  null  ];\n    }\n    if (RF== \"554530\") { \n        node.status({fill:\"grey\",shape:\"dot\",text:\"RF OFF \" + RF}); \n        return [   null , {'payload': \"OFF\" },   null  ];\n    }   \n    if (RF== \"55450C\")  {\n        node.status({fill:\"blue\",shape:\"dot\",text:\"RF AUTO \"+ RF}); \n        return [   null ,   null , {'payload': \"AUTO\" } ];\n    }   \nreturn [   null ,   null ,   null ];\n//return msg;    \n   \n",
        "outputs": 3,
        "noerr": 0,
        "x": 670,
        "y": 500,
        "wires": [
            [
                "7727ade9.1d25f4"
            ],
            [
                "22699b.4547a666",
                "b286bb02.436018"
            ],
            [
                "93e292b1.7b363"
            ]
        ],
        "outputLabels": [
            "ON",
            "OFF",
            "AUTO"
        ]
    },
    {
        "id": "d0c8b977.e0ecb8",
        "type": "comment",
        "z": "bc3b6538.ad0c48",
        "name": "BLYNK",
        "info": "",
        "x": 70,
        "y": 140,
        "wires": []
    },
    {
        "id": "b71a0915.67ef48",
        "type": "comment",
        "z": "bc3b6538.ad0c48",
        "name": "RF 315",
        "info": "",
        "x": 70,
        "y": 500,
        "wires": []
    },
    {
        "id": "a9de0e0f.48367",
        "type": "comment",
        "z": "bc3b6538.ad0c48",
        "name": "UI",
        "info": "",
        "x": 70,
        "y": 300,
        "wires": []
    },
    {
        "id": "de1073da.e8551",
        "type": "comment",
        "z": "bc3b6538.ad0c48",
        "name": "Alexa",
        "info": "",
        "x": 70,
        "y": 400,
        "wires": []
    },
    {
        "id": "6f040b89.9b41b4",
        "type": "comment",
        "z": "bc3b6538.ad0c48",
        "name": "PIR",
        "info": "",
        "x": 70,
        "y": 600,
        "wires": []
    },
    {
        "id": "f03a60ed.f0863",
        "type": "function",
        "z": "bc3b6538.ad0c48",
        "name": "CountDown",
        "func": "\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "x": 790,
        "y": 600,
        "wires": [
            [
                "4f27669.d202598"
            ]
        ]
    },
    {
        "id": "20af90de.0afc9",
        "type": "blynk-ws-out-lcd",
        "z": "bc3b6538.ad0c48",
        "name": "",
        "pin": "7",
        "client": "554f52d0.f2beac",
        "x": 990,
        "y": 520,
        "wires": []
    },
    {
        "id": "97b7693e.ca1318",
        "type": "blynk-ws-out-write",
        "z": "bc3b6538.ad0c48",
        "name": "LED output",
        "pin": "5",
        "pinmode": 0,
        "client": "554f52d0.f2beac",
        "x": 1190,
        "y": 480,
        "wires": []
    },
    {
        "id": "845ed4e2.8bbad8",
        "type": "change",
        "z": "bc3b6538.ad0c48",
        "name": "Change from ON/OFF to 255/0",
        "rules": [
            {
                "t": "change",
                "p": "payload",
                "pt": "msg",
                "from": "ON",
                "fromt": "str",
                "to": "255",
                "tot": "str"
            },
            {
                "t": "change",
                "p": "payload",
                "pt": "msg",
                "from": "OFF",
                "fromt": "str",
                "to": "0",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1110,
        "y": 420,
        "wires": [
            [
                "97b7693e.ca1318"
            ]
        ]
    },
    {
        "id": "69a8593.a61daa8",
        "type": "mqtt in",
        "z": "bc3b6538.ad0c48",
        "name": "",
        "topic": "stat/sonoff34/POWER",
        "qos": "1",
        "broker": "8a72da15.bf29b8",
        "x": 1100,
        "y": 360,
        "wires": [
            [
                "845ed4e2.8bbad8"
            ]
        ]
    },
    {
        "id": "2a16eb9a.9d1d84",
        "type": "change",
        "z": "bc3b6538.ad0c48",
        "name": "Send ON",
        "rules": [
            {
                "t": "change",
                "p": "payload",
                "pt": "msg",
                "from": "Auto",
                "fromt": "str",
                "to": "ON",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 880,
        "y": 340,
        "wires": [
            []
        ]
    },
    {
        "id": "b286bb02.436018",
        "type": "function",
        "z": "bc3b6538.ad0c48",
        "name": "Reset",
        "func": "msg.payload ='Auto';\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "x": 870,
        "y": 300,
        "wires": [
            [
                "9712ba88.f25298"
            ]
        ]
    },
    {
        "id": "334bd5ad.1d3a9a",
        "type": "change",
        "z": "bc3b6538.ad0c48",
        "name": "change",
        "rules": [
            {
                "t": "change",
                "p": "payload",
                "pt": "msg",
                "from": "1",
                "fromt": "str",
                "to": "Motion",
                "tot": "str"
            },
            {
                "t": "change",
                "p": "payload",
                "pt": "msg",
                "from": "0",
                "fromt": "str",
                "to": " ",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1000,
        "y": 700,
        "wires": [
            [
                "bb80c38a.700dc",
                "803b78b6.3b58f8"
            ]
        ]
    },
    {
        "id": "bb80c38a.700dc",
        "type": "googlehome-notify",
        "z": "bc3b6538.ad0c48",
        "server": "8884b30e.ec758",
        "name": "Google Home",
        "x": 1200,
        "y": 760,
        "wires": []
    },
    {
        "id": "8a72da15.bf29b8",
        "type": "mqtt-broker",
        "z": "",
        "name": "Mosquito",
        "broker": "192.168.xxx.xxx",
        "port": "1883",
        "clientid": "Sonoff33",
        "usetls": false,
        "compatmode": true,
        "keepalive": "60",
        "cleansession": true,
        "birthTopic": "",
        "birthQos": "1",
        "birthRetain": "true",
        "birthPayload": "",
        "closeTopic": "",
        "closePayload": "",
        "willTopic": "",
        "willQos": "0",
        "willPayload": ""
    },
    {
        "id": "73ce4f22.05854",
        "type": "ui_group",
        "z": "",
        "name": "HALL",
        "tab": "a5b4907f.531a6",
        "disp": true,
        "width": "3",
        "collapse": false
    },
    {
        "id": "554f52d0.f2beac",
        "type": "blynk-ws-client",
        "z": "",
        "name": "PIR",
        "path": "ws://xxx.xxx.xxx.xxx/websockets",
        "key": "fa615fd8abd5444d9cce9a9aa6ec9a4b",
        "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": ""
    },
    {
        "id": "198887d9.6c0cc8",
        "type": "alexa-home-conf",
        "z": "",
        "username": "xxx"
    },
    {
        "id": "8884b30e.ec758",
        "type": "googlehome-config-node",
        "z": "",
        "ipaddress": "192.168.xxx.xxx",
        "name": "",
        "language": "en"
    },
    {
        "id": "a5b4907f.531a6",
        "type": "ui_tab",
        "z": "bc3b6538.ad0c48",
        "name": "Sonoff",
        "icon": "dashboard",
        "order": 1
    }
]