MQTT Request from a node
-
On my pi2 I have installed node-red and do all the 'wiring' of messages between different nodes there. Maybe this could be a solution for you too.
-
That interesting way of doing things...
But I believe that having native support for MQTT subscription by a node would be the ideal way to go... No wiring, no special code, just make a request, and it sent to you via the gateway. You only need to know is name string...
-
For me it is important not to wire nodes directly, because I want to be able to change any node without having to make firmware changes to others. I like this abstraction level, e.g. I can change my netatmo devices to mysensor devices without changing anything in openhab. Openhab doesn't know,what type of device is behind an item.
-
On my pi2 I have installed node-red and do all the 'wiring' of messages between different nodes there. Maybe this could be a solution for you too.
@FotoFieber said:
On my pi2 I have installed node-red and do all the 'wiring' of messages between different nodes there. Maybe this could be a solution for you too.
Would you like to share the details of your setup and the flow? It would really be interesting to explore...
-
It is a prototype and not finished yet.
I use a namespace for the different technologies for the MQTT Topic:
MyMQTT for MySensors
Netatmo for netatmo devices
homegear for Homematic
nodered for messages generated fom node-red
openHAB for the openHAB eventbusMost of the wiring is defined in a hashtable. As this is more of a hack, I want to clean it up before I publish it.
Here an example for an RGB Led (MySensors) wired to openhab colorpicker and a homematic wall switch. Note: the wiring is bidirectional, I see the RGB Color in openHAB of the MySensors LED independent of the method I used to set it and openHAB doesn't know anything about Homematic or MySensors. I can evan add another UI (openHAB 2?) and other switches (MySensors Motion or Lux nodes) and everything would be in sync.
[{"id":"ba386057.845d3","type":"mqtt-broker","broker":"192.168.92.4","port":"1883","clientid":"NodeRed"},{"id":"c1a0dd11.3e5f2","type":"mqtt in","name":"RGB Colorpicker","topic":"openHAB/out/RGBLight/command","broker":"ba386057.845d3","x":152.33332061767578,"y":179.66666412353516,"z":"914d079b.6eb2f8","wires":[["46c3882f.b93c78","c1246f87.3edb9"]]},{"id":"1ab94043.e546c","type":"mqtt out","name":"MyRGBLed","topic":"MyMQTT/30/1/S_LIGHT_LEVEL","qos":"","retain":"","broker":"ba386057.845d3","x":617.3333231608073,"y":98.66666412353516,"z":"914d079b.6eb2f8","wires":[]},{"id":"46c3882f.b93c78","type":"function","name":"HSV convert","func":"if (msg.payload == 'OFF') {\n msg.payload = 'RGB 0,0,0';\n return msg;\n} \n\nif (msg.payload == 'ON') {\n msg.payload = 'RGB 255,255,255';\n return msg;\n} \n\n\nvar res = msg.payload.split(\",\");\n\nh = res[0];\ns = res[1];\nv = res[2];\n\nvar r, g, b;\n\tvar i;\n\tvar f, p, q, t;\n \n\t// Make sure our arguments stay in-range\n\th = Math.max(0, Math.min(360, h));\n\ts = Math.max(0, Math.min(100, s));\n\tv = Math.max(0, Math.min(100, v));\n \n\t// We accept saturation and value arguments from 0 to 100 because that's\n\t// how Photoshop represents those values. Internally, however, the\n\t// saturation and value are calculated from a range of 0 to 1. We make\n\t// That conversion here.\n\ts /= 100;\n\tv /= 100;\n \n\tif(s == 0) {\n\t\t// Achromatic (grey)\n\t\tr = g = b = v;\n\t\t\n\t} else\n\t{\n \n\th /= 60; // sector 0 to 5\n\ti = Math.floor(h);\n\tf = h - i; // factorial part of h\n\tp = v * (1 - s);\n\tq = v * (1 - s * f);\n\tt = v * (1 - s * (1 - f));\n \n\tswitch(i) {\n\t\tcase 0:\n\t\t\tr = v;\n\t\t\tg = t;\n\t\t\tb = p;\n\t\t\tbreak;\n \n\t\tcase 1:\n\t\t\tr = q;\n\t\t\tg = v;\n\t\t\tb = p;\n\t\t\tbreak;\n \n\t\tcase 2:\n\t\t\tr = p;\n\t\t\tg = v;\n\t\t\tb = t;\n\t\t\tbreak;\n \n\t\tcase 3:\n\t\t\tr = p;\n\t\t\tg = q;\n\t\t\tb = v;\n\t\t\tbreak;\n \n\t\tcase 4:\n\t\t\tr = t;\n\t\t\tg = p;\n\t\t\tb = v;\n\t\t\tbreak;\n \n\t\tdefault: // case 5:\n\t\t\tr = v;\n\t\t\tg = p;\n\t\t\tb = q;\n\t}\n\t\n\t}\n\tr = Math.round(r * 255);\n\tg = Math.round(g * 255);\n\tb = Math.round(b * 255);\n\t\n //var erg = {hue:h,saturation:s,value:v, red:r, green:g, blue:b};\n \n msg.payload = 'RGB ' + r + ',' + g + ',' + b;\n\n\n\n\nreturn msg;","outputs":1,"valid":true,"x":395.3333231608073,"y":126.66666412353516,"z":"914d079b.6eb2f8","wires":[["1ab94043.e546c","c1246f87.3edb9"]]},{"id":"c1246f87.3edb9","type":"debug","name":"","active":true,"console":"false","complete":"false","x":621.3333129882812,"y":255.6666488647461,"z":"914d079b.6eb2f8","wires":[]},{"id":"e8effb31.171008","type":"mqtt in","name":"RGBLED Returncode Lichwert","topic":"MyMQTT/30/2/V_LIGHT_LEVEL","broker":"ba386057.845d3","x":195.99996948242188,"y":240.66665649414062,"z":"914d079b.6eb2f8","wires":[["a5d4d602.5a2b28"]]},{"id":"a5d4d602.5a2b28","type":"function","name":"RGB to HSV","func":"b = msg.payload % 256 ;\ng = ((msg.payload - b) / 256) % 256;\nr = (msg.payload - b - g*256) / 256 / 256;\n\n\t\n r = r/255, g = g/255, b = b/255;\n var max = Math.max(r, g, b), min = Math.min(r, g, b);\n var h, s, v = max;\n\n var d = max - min;\n s = max == 0 ? 0 : d / max;\n\n if(max == min){\n h = 0; // achromatic\n }else{\n switch(max){\n case r: h = (g - b) / d + (g < b ? 6 : 0); break;\n case g: h = (b - r) / d + 2; break;\n case b: h = (r - g) / d + 4; break;\n }\n h /= 6;\n }\n\n h *=360;\n s*=100;\n v*=100;\n\n\t\n// var erg = {hue:h,saturation:s,value:v, red:r, green:g, blue:b};\n \nmsg.payload = h + ',' + s + ',' + v;\n\n\nreturn msg;","outputs":1,"valid":true,"x":505.3333231608073,"y":343.66666412353516,"z":"914d079b.6eb2f8","wires":[["c1246f87.3edb9","792d7484.86d28c"]]},{"id":"792d7484.86d28c","type":"mqtt out","name":"RGB in Openhab setzen","topic":"openHAB/in/RGBLight/state","qos":"","retain":"","broker":"ba386057.845d3","x":736.3333231608073,"y":339.66666412353516,"z":"914d079b.6eb2f8","wires":[]},{"id":"85a991b0.7a567","type":"mqtt in","name":"Laura Fernbedienung","topic":"homegear/1234-5678-9abc/event/10/#","broker":"ba386057.845d3","x":129,"y":36,"z":"914d079b.6eb2f8","wires":[["e913dcc9.16ec2","c1246f87.3edb9"]]},{"id":"e913dcc9.16ec2","type":"function","name":"Fernbedienung auf RGB Licht","func":"if (msg.payload != '[true]') return;\n\n\nif (msg.topic == 'homegear/1234-5678-9abc/event/10/1/PRESS_SHORT') {\n msg.payload ='OFF'; \n} \nelse if (msg.topic == 'homegear/1234-5678-9abc/event/10/2/PRESS_SHORT') {\n msg.payload = 'RGB 255,187,0';\n}\nelse if (msg.topic == 'homegear/1234-5678-9abc/event/10/3/PRESS_SHORT') {\n msg.payload = 'RGB 255,0,0';\n}\nelse if (msg.topic == 'homegear/1234-5678-9abc/event/10/4/PRESS_SHORT') {\n msg.payload = 'RGB 255,6,226';\n}\nelse if (msg.topic == 'homegear/1234-5678-9abc/event/10/5/PRESS_SHORT') {\n msg.payload = 'RGB 177,10,255';\n}\nelse if (msg.topic == 'homegear/1234-5678-9abc/event/10/6/PRESS_SHORT') {\n msg.payload = 'RGB 0,255,0';\n}\n\nreturn msg;","outputs":1,"valid":true,"x":388,"y":57,"z":"914d079b.6eb2f8","wires":[["1ab94043.e546c","c1246f87.3edb9"]]}] -
It is a prototype and not finished yet.
I use a namespace for the different technologies for the MQTT Topic:
MyMQTT for MySensors
Netatmo for netatmo devices
homegear for Homematic
nodered for messages generated fom node-red
openHAB for the openHAB eventbusMost of the wiring is defined in a hashtable. As this is more of a hack, I want to clean it up before I publish it.
Here an example for an RGB Led (MySensors) wired to openhab colorpicker and a homematic wall switch. Note: the wiring is bidirectional, I see the RGB Color in openHAB of the MySensors LED independent of the method I used to set it and openHAB doesn't know anything about Homematic or MySensors. I can evan add another UI (openHAB 2?) and other switches (MySensors Motion or Lux nodes) and everything would be in sync.
[{"id":"ba386057.845d3","type":"mqtt-broker","broker":"192.168.92.4","port":"1883","clientid":"NodeRed"},{"id":"c1a0dd11.3e5f2","type":"mqtt in","name":"RGB Colorpicker","topic":"openHAB/out/RGBLight/command","broker":"ba386057.845d3","x":152.33332061767578,"y":179.66666412353516,"z":"914d079b.6eb2f8","wires":[["46c3882f.b93c78","c1246f87.3edb9"]]},{"id":"1ab94043.e546c","type":"mqtt out","name":"MyRGBLed","topic":"MyMQTT/30/1/S_LIGHT_LEVEL","qos":"","retain":"","broker":"ba386057.845d3","x":617.3333231608073,"y":98.66666412353516,"z":"914d079b.6eb2f8","wires":[]},{"id":"46c3882f.b93c78","type":"function","name":"HSV convert","func":"if (msg.payload == 'OFF') {\n msg.payload = 'RGB 0,0,0';\n return msg;\n} \n\nif (msg.payload == 'ON') {\n msg.payload = 'RGB 255,255,255';\n return msg;\n} \n\n\nvar res = msg.payload.split(\",\");\n\nh = res[0];\ns = res[1];\nv = res[2];\n\nvar r, g, b;\n\tvar i;\n\tvar f, p, q, t;\n \n\t// Make sure our arguments stay in-range\n\th = Math.max(0, Math.min(360, h));\n\ts = Math.max(0, Math.min(100, s));\n\tv = Math.max(0, Math.min(100, v));\n \n\t// We accept saturation and value arguments from 0 to 100 because that's\n\t// how Photoshop represents those values. Internally, however, the\n\t// saturation and value are calculated from a range of 0 to 1. We make\n\t// That conversion here.\n\ts /= 100;\n\tv /= 100;\n \n\tif(s == 0) {\n\t\t// Achromatic (grey)\n\t\tr = g = b = v;\n\t\t\n\t} else\n\t{\n \n\th /= 60; // sector 0 to 5\n\ti = Math.floor(h);\n\tf = h - i; // factorial part of h\n\tp = v * (1 - s);\n\tq = v * (1 - s * f);\n\tt = v * (1 - s * (1 - f));\n \n\tswitch(i) {\n\t\tcase 0:\n\t\t\tr = v;\n\t\t\tg = t;\n\t\t\tb = p;\n\t\t\tbreak;\n \n\t\tcase 1:\n\t\t\tr = q;\n\t\t\tg = v;\n\t\t\tb = p;\n\t\t\tbreak;\n \n\t\tcase 2:\n\t\t\tr = p;\n\t\t\tg = v;\n\t\t\tb = t;\n\t\t\tbreak;\n \n\t\tcase 3:\n\t\t\tr = p;\n\t\t\tg = q;\n\t\t\tb = v;\n\t\t\tbreak;\n \n\t\tcase 4:\n\t\t\tr = t;\n\t\t\tg = p;\n\t\t\tb = v;\n\t\t\tbreak;\n \n\t\tdefault: // case 5:\n\t\t\tr = v;\n\t\t\tg = p;\n\t\t\tb = q;\n\t}\n\t\n\t}\n\tr = Math.round(r * 255);\n\tg = Math.round(g * 255);\n\tb = Math.round(b * 255);\n\t\n //var erg = {hue:h,saturation:s,value:v, red:r, green:g, blue:b};\n \n msg.payload = 'RGB ' + r + ',' + g + ',' + b;\n\n\n\n\nreturn msg;","outputs":1,"valid":true,"x":395.3333231608073,"y":126.66666412353516,"z":"914d079b.6eb2f8","wires":[["1ab94043.e546c","c1246f87.3edb9"]]},{"id":"c1246f87.3edb9","type":"debug","name":"","active":true,"console":"false","complete":"false","x":621.3333129882812,"y":255.6666488647461,"z":"914d079b.6eb2f8","wires":[]},{"id":"e8effb31.171008","type":"mqtt in","name":"RGBLED Returncode Lichwert","topic":"MyMQTT/30/2/V_LIGHT_LEVEL","broker":"ba386057.845d3","x":195.99996948242188,"y":240.66665649414062,"z":"914d079b.6eb2f8","wires":[["a5d4d602.5a2b28"]]},{"id":"a5d4d602.5a2b28","type":"function","name":"RGB to HSV","func":"b = msg.payload % 256 ;\ng = ((msg.payload - b) / 256) % 256;\nr = (msg.payload - b - g*256) / 256 / 256;\n\n\t\n r = r/255, g = g/255, b = b/255;\n var max = Math.max(r, g, b), min = Math.min(r, g, b);\n var h, s, v = max;\n\n var d = max - min;\n s = max == 0 ? 0 : d / max;\n\n if(max == min){\n h = 0; // achromatic\n }else{\n switch(max){\n case r: h = (g - b) / d + (g < b ? 6 : 0); break;\n case g: h = (b - r) / d + 2; break;\n case b: h = (r - g) / d + 4; break;\n }\n h /= 6;\n }\n\n h *=360;\n s*=100;\n v*=100;\n\n\t\n// var erg = {hue:h,saturation:s,value:v, red:r, green:g, blue:b};\n \nmsg.payload = h + ',' + s + ',' + v;\n\n\nreturn msg;","outputs":1,"valid":true,"x":505.3333231608073,"y":343.66666412353516,"z":"914d079b.6eb2f8","wires":[["c1246f87.3edb9","792d7484.86d28c"]]},{"id":"792d7484.86d28c","type":"mqtt out","name":"RGB in Openhab setzen","topic":"openHAB/in/RGBLight/state","qos":"","retain":"","broker":"ba386057.845d3","x":736.3333231608073,"y":339.66666412353516,"z":"914d079b.6eb2f8","wires":[]},{"id":"85a991b0.7a567","type":"mqtt in","name":"Laura Fernbedienung","topic":"homegear/1234-5678-9abc/event/10/#","broker":"ba386057.845d3","x":129,"y":36,"z":"914d079b.6eb2f8","wires":[["e913dcc9.16ec2","c1246f87.3edb9"]]},{"id":"e913dcc9.16ec2","type":"function","name":"Fernbedienung auf RGB Licht","func":"if (msg.payload != '[true]') return;\n\n\nif (msg.topic == 'homegear/1234-5678-9abc/event/10/1/PRESS_SHORT') {\n msg.payload ='OFF'; \n} \nelse if (msg.topic == 'homegear/1234-5678-9abc/event/10/2/PRESS_SHORT') {\n msg.payload = 'RGB 255,187,0';\n}\nelse if (msg.topic == 'homegear/1234-5678-9abc/event/10/3/PRESS_SHORT') {\n msg.payload = 'RGB 255,0,0';\n}\nelse if (msg.topic == 'homegear/1234-5678-9abc/event/10/4/PRESS_SHORT') {\n msg.payload = 'RGB 255,6,226';\n}\nelse if (msg.topic == 'homegear/1234-5678-9abc/event/10/5/PRESS_SHORT') {\n msg.payload = 'RGB 177,10,255';\n}\nelse if (msg.topic == 'homegear/1234-5678-9abc/event/10/6/PRESS_SHORT') {\n msg.payload = 'RGB 0,255,0';\n}\n\nreturn msg;","outputs":1,"valid":true,"x":388,"y":57,"z":"914d079b.6eb2f8","wires":[["1ab94043.e546c","c1246f87.3edb9"]]}]@FotoFieber said:
[{"id":"ba386057.845d3","type":"mqtt-broker","broker":"192.168.92.4","port":"1883","clientid":"NodeRed"},{"id":"c1a0dd11.3e5f2","type":"mqtt in","name":"RGB Colorpicker","topic":"openHAB/out/RGBLight/command","broker":"ba386057.845d3","x":152.33332061767578,"y":179.66666412353516,"z":"914d079b.6eb2f8","wires":[["46c3882f.b93c78","c1246f87.3edb9"]]},{"id":"1ab94043.e546c","type":"mqtt out","name":"MyRGBLed","topic":"MyMQTT/30/1/S_LIGHT_LEVEL","qos":"","retain":"","broker":"ba386057.845d3","x":617.3333231608073,"y":98.66666412353516,"z":"914d079b.6eb2f8","wires":[]},{"id":"46c3882f.b93c78","type":"function","name":"HSV convert","func":"if (msg.payload == 'OFF') {\n msg.payload = 'RGB 0,0,0';\n return msg;\n} \n\nif (msg.payload == 'ON') {\n msg.payload = 'RGB 255,255,255';\n return msg;\n} \n\n\nvar res = msg.payload.split(\",\");\n\nh = res[0];\ns = res[1];\nv = res[2];\n\nvar r, g, b;\n\tvar i;\n\tvar f, p, q, t;\n \n\t// Make sure our arguments stay in-range\n\th = Math.max(0, Math.min(360, h));\n\ts = Math.max(0, Math.min(100, s));\n\tv = Math.max(0, Math.min(100, v));\n \n\t// We accept saturation and value arguments from 0 to 100 because that's\n\t// how Photoshop represents those values. Internally, however, the\n\t// saturation and value are calculated from a range of 0 to 1. We make\n\t// That conversion here.\n\ts /= 100;\n\tv /= 100;\n \n\tif(s == 0) {\n\t\t// Achromatic (grey)\n\t\tr = g = b = v;\n\t\t\n\t} else\n\t{\n \n\th /= 60; // sector 0 to 5\n\ti = Math.floor(h);\n\tf = h - i; // factorial part of h\n\tp = v * (1 - s);\n\tq = v * (1 - s * f);\n\tt = v * (1 - s * (1 - f));\n \n\tswitch(i) {\n\t\tcase 0:\n\t\t\tr = v;\n\t\t\tg = t;\n\t\t\tb = p;\n\t\t\tbreak;\n \n\t\tcase 1:\n\t\t\tr = q;\n\t\t\tg = v;\n\t\t\tb = p;\n\t\t\tbreak;\n \n\t\tcase 2:\n\t\t\tr = p;\n\t\t\tg = v;\n\t\t\tb = t;\n\t\t\tbreak;\n \n\t\tcase 3:\n\t\t\tr = p;\n\t\t\tg = q;\n\t\t\tb = v;\n\t\t\tbreak;\n \n\t\tcase 4:\n\t\t\tr = t;\n\t\t\tg = p;\n\t\t\tb = v;\n\t\t\tbreak;\n \n\t\tdefault: // case 5:\n\t\t\tr = v;\n\t\t\tg = p;\n\t\t\tb = q;\n\t}\n\t\n\t}\n\tr = Math.round(r * 255);\n\tg = Math.round(g * 255);\n\tb = Math.round(b * 255);\n\t\n //var erg = {hue:h,saturation:s,value:v, red:r, green:g, blue:b};\n \n msg.payload = 'RGB ' + r + ',' + g + ',' + b;\n\n\n\n\nreturn msg;","outputs":1,"valid":true,"x":395.3333231608073,"y":126.66666412353516,"z":"914d079b.6eb2f8","wires":[["1ab94043.e546c","c1246f87.3edb9"]]},{"id":"c1246f87.3edb9","type":"debug","name":"","active":true,"console":"false","complete":"false","x":621.3333129882812,"y":255.6666488647461,"z":"914d079b.6eb2f8","wires":[]},{"id":"e8effb31.171008","type":"mqtt in","name":"RGBLED Returncode Lichwert","topic":"MyMQTT/30/2/V_LIGHT_LEVEL","broker":"ba386057.845d3","x":195.99996948242188,"y":240.66665649414062,"z":"914d079b.6eb2f8","wires":[["a5d4d602.5a2b28"]]},{"id":"a5d4d602.5a2b28","type":"function","name":"RGB to HSV","func":"b = msg.payload % 256 ;\ng = ((msg.payload - b) / 256) % 256;\nr = (msg.payload - b - g*256) / 256 / 256;\n\n\t\n r = r/255, g = g/255, b = b/255;\n var max = Math.max(r, g, b), min = Math.min(r, g, b);\n var h, s, v = max;\n\n var d = max - min;\n s = max == 0 ? 0 : d / max;\n\n if(max == min){\n h = 0; // achromatic\n }else{\n switch(max){\n case r: h = (g - b) / d + (g < b ? 6 : 0); break;\n case g: h = (b - r) / d + 2; break;\n case b: h = (r - g) / d + 4; break;\n }\n h /= 6;\n }\n\n h *=360;\n s*=100;\n v*=100;\n\n\t\n// var erg = {hue:h,saturation:s,value:v, red:r, green:g, blue:b};\n \nmsg.payload = h + ',' + s + ',' + v;\n\n\nreturn msg;","outputs":1,"valid":true,"x":505.3333231608073,"y":343.66666412353516,"z":"914d079b.6eb2f8","wires":[["c1246f87.3edb9","792d7484.86d28c"]]},{"id":"792d7484.86d28c","type":"mqtt out","name":"RGB in Openhab setzen","topic":"openHAB/in/RGBLight/state","qos":"","retain":"","broker":"ba386057.845d3","x":736.3333231608073,"y":339.66666412353516,"z":"914d079b.6eb2f8","wires":[]},{"id":"85a991b0.7a567","type":"mqtt in","name":"Laura Fernbedienung","topic":"homegear/1234-5678-9abc/event/10/#","broker":"ba386057.845d3","x":129,"y":36,"z":"914d079b.6eb2f8","wires":[["e913dcc9.16ec2","c1246f87.3edb9"]]},{"id":"e913dcc9.16ec2","type":"function","name":"Fernbedienung auf RGB Licht","func":"if (msg.payload != '[true]') return;\n\n\nif (msg.topic == 'homegear/1234-5678-9abc/event/10/1/PRESS_SHORT') {\n msg.payload ='OFF'; \n} \nelse if (msg.topic == 'homegear/1234-5678-9abc/event/10/2/PRESS_SHORT') {\n msg.payload = 'RGB 255,187,0';\n}\nelse if (msg.topic == 'homegear/1234-5678-9abc/event/10/3/PRESS_SHORT') {\n msg.payload = 'RGB 255,0,0';\n}\nelse if (msg.topic == 'homegear/1234-5678-9abc/event/10/4/PRESS_SHORT') {\n msg.payload = 'RGB 255,6,226';\n}\nelse if (msg.topic == 'homegear/1234-5678-9abc/event/10/5/PRESS_SHORT') {\n msg.payload = 'RGB 177,10,255';\n}\nelse if (msg.topic == 'homegear/1234-5678-9abc/event/10/6/PRESS_SHORT') {\n msg.payload = 'RGB 0,255,0';\n}\n\nreturn msg;","outputs":1,"valid":true,"x":388,"y":57,"z":"914d079b.6eb2f8","wires":[["1ab94043.e546c","c1246f87.3edb9"]]}]```Seems to be some simple syntax error here. Is there a way to find out these kind of errors in some editor or visual tools? NodeRED import from clipboard doesnt even let it go any further.
-
Please try again. Lesson learned: Don't answer posts on holiday with a tablet... :+1:
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login