Hi All,
I need your help. I am pretty much a novice with Node Red, HA, and MQTT. However, I have set up several flows to turn on and off lights based on motion and door sensors. I am using HA, Node Red, and Mosquitto in a Docker container. I have used MQTT Explored, and I am able to see messages, and I also know that in the data object there is an attribute brightness or brightness_pct. I’ve read the Shelly documentation which gets me no where.I’ve looked on this forum. I’ve looked at various YouTubes with some help. I have used the MQTT in and out nodes for subscribe and publish. I just don’t understand the Shelly API documentation.
It’s something like ShellyId/events/rpc/command, but after that I’m stuck.
TIA,
Steve
I did this once before I was using HASS when I was trying to get the wall dimmer into HomeKit. It worked well but I have since moved on and no longer use node red.
I went back to an email exchange with someone at the time and I have included my complete flow that I came up with. I hope it helps you get on track.
[
{
"id": "f86e55ab0740a4ba",
"type": "mqtt out",
"z": "400bc6822dea397a",
"name": "MQTT Control",
"topic": "GreenRoom/rpc",
"qos": "1",
"retain": "",
"respTopic": "",
"contentType": "",
"userProps": "",
"correl": "",
"expiry": "",
"broker": "4981d51eace3b4be",
"x": 500,
"y": 280,
"wires": []
},
{
"id": "ba3a7e4559ae2a7b",
"type": "mqtt in",
"z": "400bc6822dea397a",
"name": "MQTT Status",
"topic": "GreenRoom/status/light:0",
"qos": "1",
"datatype": "auto-detect",
"broker": "4981d51eace3b4be",
"nl": false,
"rap": true,
"rh": 0,
"inputs": 0,
"x": 90,
"y": 100,
"wires": [
[
"012f353a0b44ce6c"
]
]
},
{
"id": "0b0e4e10c1c5cd86",
"type": "function",
"z": "400bc6822dea397a",
"name": "translate",
"func": "if (msg.payload.output == true) {\n msg.payload = {\"On\": 1, \"Brightness\": msg.payload.brightness};\n return msg;\n} else {\n msg.payload = {\"On\": 0, \"Brightness\": msg.payload.brightness};\n return msg;\n}",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 400,
"y": 100,
"wires": [
[
"d858da0bef12c43c"
]
]
},
{
"id": "c4b46c5de05d51c4",
"type": "homekit-service",
"z": "400bc6822dea397a",
"isParent": true,
"hostType": "0",
"bridge": "89283e495d5d1ab0",
"accessoryId": "",
"parentService": "",
"name": "GreenRoom",
"serviceName": "Lightbulb",
"topic": "",
"filter": false,
"manufacturer": "NRCHKB",
"model": "1.4.3",
"serialNo": "Default Serial Number",
"firmwareRev": "1.4.3",
"hardwareRev": "1.4.3",
"softwareRev": "1.4.3",
"cameraConfigVideoProcessor": "ffmpeg",
"cameraConfigSource": "",
"cameraConfigStillImageSource": "",
"cameraConfigMaxStreams": 2,
"cameraConfigMaxWidth": 1280,
"cameraConfigMaxHeight": 720,
"cameraConfigMaxFPS": 10,
"cameraConfigMaxBitrate": 300,
"cameraConfigVideoCodec": "libx264",
"cameraConfigAudioCodec": "libfdk_aac",
"cameraConfigAudio": false,
"cameraConfigPacketSize": 1316,
"cameraConfigVerticalFlip": false,
"cameraConfigHorizontalFlip": false,
"cameraConfigMapVideo": "0:0",
"cameraConfigMapAudio": "0:1",
"cameraConfigVideoFilter": "scale=1280:720",
"cameraConfigAdditionalCommandLine": "-tune zerolatency",
"cameraConfigDebug": false,
"cameraConfigSnapshotOutput": "disabled",
"cameraConfigInterfaceName": "",
"characteristicProperties": "{\"Brightness\": true}",
"waitForSetupMsg": false,
"outputs": 2,
"x": 110,
"y": 220,
"wires": [
[],
[
"580049e4bb115080",
"411416eafaf3dafd"
]
]
},
{
"id": "1c6fa6c19c2d8660",
"type": "function",
"z": "400bc6822dea397a",
"name": "build MQTT string",
"func": "var light = flow.get(\"gr_on\");\nvar brightness = flow.get(\"gr_brightness\");\nmsg.payload = { \"id\": 123, \"src\": \"node_red\", \"method\": \"Light.Set\", \"params\": { \"id\": 0, \"on\": light, \"brightness\": brightness } };\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 150,
"y": 280,
"wires": [
[
"9c7c2d1e2af175ef"
]
]
},
{
"id": "012f353a0b44ce6c",
"type": "change",
"z": "400bc6822dea397a",
"name": "Set.Env.Vars",
"rules": [
{
"t": "set",
"p": "gr_on",
"pt": "flow",
"to": "payload.output",
"tot": "msg"
},
{
"t": "set",
"p": "gr_brightness",
"pt": "flow",
"to": "payload.brightness",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 250,
"y": 100,
"wires": [
[
"0b0e4e10c1c5cd86"
]
]
},
{
"id": "580049e4bb115080",
"type": "switch",
"z": "400bc6822dea397a",
"name": "block undefined",
"property": "payload.On",
"propertyType": "msg",
"rules": [
{
"t": "nnull"
}
],
"checkall": "true",
"repair": false,
"outputs": 1,
"x": 280,
"y": 200,
"wires": [
[
"bb3975d068e4e39c"
]
]
},
{
"id": "bb3975d068e4e39c",
"type": "change",
"z": "400bc6822dea397a",
"name": "Set.Env.On",
"rules": [
{
"t": "set",
"p": "gr_on",
"pt": "flow",
"to": "payload.On",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 450,
"y": 200,
"wires": [
[
"1c6fa6c19c2d8660"
]
]
},
{
"id": "411416eafaf3dafd",
"type": "switch",
"z": "400bc6822dea397a",
"name": "block undefined",
"property": "payload.Brightness",
"propertyType": "msg",
"rules": [
{
"t": "nnull"
}
],
"checkall": "true",
"repair": false,
"outputs": 1,
"x": 280,
"y": 240,
"wires": [
[
"6b722e53e8a8cc03"
]
]
},
{
"id": "6b722e53e8a8cc03",
"type": "change",
"z": "400bc6822dea397a",
"name": "Set.Env.Brightness",
"rules": [
{
"t": "set",
"p": "gr_brightness",
"pt": "flow",
"to": "payload.Brightness",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 470,
"y": 240,
"wires": [
[
"1c6fa6c19c2d8660"
]
]
},
{
"id": "d858da0bef12c43c",
"type": "rbe",
"z": "400bc6822dea397a",
"name": "limit dupes",
"func": "rbe",
"gap": "",
"start": "",
"inout": "out",
"septopics": false,
"property": "payload",
"topi": "topic",
"x": 550,
"y": 100,
"wires": [
[
"c4b46c5de05d51c4"
]
]
},
{
"id": "9c7c2d1e2af175ef",
"type": "rbe",
"z": "400bc6822dea397a",
"name": "limit dupes",
"func": "rbe",
"gap": "",
"start": "",
"inout": "out",
"septopics": false,
"property": "payload",
"topi": "topic",
"x": 330,
"y": 280,
"wires": [
[
"f86e55ab0740a4ba"
]
]
},
{
"id": "5368d2bf9b9b7119",
"type": "comment",
"z": "400bc6822dea397a",
"name": "MQTT Status sets NR HomeKit Object to current device state.",
"info": "",
"x": 240,
"y": 60,
"wires": []
},
{
"id": "2d5105027c3c5d34",
"type": "comment",
"z": "400bc6822dea397a",
"name": "NR HomeKit Object sets device state via MQTT",
"info": "",
"x": 200,
"y": 160,
"wires": []
},
{
"id": "cb8830c759c56ef7",
"type": "comment",
"z": "400bc6822dea397a",
"name": "Flow Environment variables hold current or target state between MQTT messages",
"info": "",
"x": 300,
"y": 20,
"wires": []
},
{
"id": "4981d51eace3b4be",
"type": "mqtt-broker",
"name": "Mosquitto",
"broker": “192.168.1.xx",
"port": "1883",
"clientid": "",
"autoConnect": true,
"usetls": false,
"protocolVersion": "5",
"keepalive": "60",
"cleansession": true,
"birthTopic": "",
"birthQos": "0",
"birthRetain": "false",
"birthPayload": "",
"birthMsg": {},
"closeTopic": "",
"closeQos": "0",
"closeRetain": "false",
"closePayload": "",
"closeMsg": {},
"willTopic": "",
"willQos": "0",
"willRetain": "false",
"willPayload": "",
"willMsg": {},
"userProps": "",
"sessionExpiry": ""
},
{
"id": "89283e495d5d1ab0",
"type": "homekit-bridge",
"bridgeName": "Green Room",
"pinCode": "989-17-441",
"port": "",
"advertiser": "bonjour-hap",
"allowInsecureRequest": false,
"manufacturer": "NRCHKB",
"model": "1.4.3",
"serialNo": "Default Serial Number",
"firmwareRev": "1.4.3",
"hardwareRev": "1.4.3",
"softwareRev": "1.4.3",
"customMdnsConfig": false,
"mdnsMulticast": true,
"mdnsInterface": "",
"mdnsPort": "",
"mdnsIp": "",
"mdnsTtl": "",
"mdnsLoopback": true,
"mdnsReuseAddr": true,
"allowMessagePassthrough": true
}
]