Announcement

Collapse
No announcement yet.

mqtt question

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    mqtt question


    Hello Michael,

    Well i'm using your plugin mcsmqtt.
    i receive all mqtt topics from Multi1/Livingroom:heatIndex, Multi1/Livingroom:temperature and so on.

    when i try to receive them in mosquitto i get nothing, not even a change..
    using this line:

    mosquitto_sub -h 192.168.1.12 -t Multi1/Livingroom:ldr

    if i do:

    mosquitto_sub -h 192.168.1.12 -t Multi1/Livingroom i get a json strong of all devices:

    {"state":"OFF","color":{"r":255,"g":255,"b":255},"brightn ess ":255,"humidity":"49","motion":"motion detected","ldr":"657","temperature":"23","heatIndex":"24.89" }


    any idea how to sub to it ?

    i'm using node-red and the tutorial from influx db and your plugin, but can't subscribe with mosquitto.

    regards and have a nice day

    Preferred -> Jon's Plugins, Pushover, Phlocation, Easy-trigger,
    Rfxcom, Blade Plugins, Pushbullet, homekit, Malosa Scripts




    HS3Pro 4.0.8.0 on windows 10 enterprise X64 on hp quadcore laptop 8 GB.

    #2
    what I think you have is some client sending multi1/Livingtoom topic with json payload. mcsMQTT decides the payload into individual keys and suffixes each with a colon separation.

    you then want to send these decoded items individually to node red and graphangra.

    the colon. nomenclature is used only internally by mcsMQTT so will never be visible via MQTT to a mosquito client.

    you need to associate in mcsMQTT on the Association tab and item you want to publish from mcsMQTT and then give it a publish topic. this topic will not have colon but can have slash.

    the intent of mcsMQTT is to allow HS to use MQTT. for what I described above HS has no involvement other than decoding json and this decoding could be done with node red.

    if you have a HS device that you want to send to graphana each time it. changed then what I described above makes sense.

    Comment


      #3
      Thanks for your answer, but i kinda don't know how i can change it ?

      this is how it looks like now,



      Click image for larger version

Name:	mqttQ.png
Views:	78
Size:	79.8 KB
ID:	1392639

      Click image for larger version

Name:	mqttQ1.png
Views:	76
Size:	87.3 KB
ID:	1392640
      Preferred -> Jon's Plugins, Pushover, Phlocation, Easy-trigger,
      Rfxcom, Blade Plugins, Pushbullet, homekit, Malosa Scripts




      HS3Pro 4.0.8.0 on windows 10 enterprise X64 on hp quadcore laptop 8 GB.

      Comment


        #4
        You have some entity that is publishing Topic Multi1/Livingroom with a Payload such as {"state":"OFF","color":{"r":255,"g":255,"b":255},"brightn ess ":255,"humidity":"49","motion":"motion detected","ldr":"657","temperature":"23","heatIndex":"24.89" }. Node-Red can subscribe to this topic and Node-Red can extract the data for each JSON key. Node-Red flow can send this extracted data to Graphana. I do not see where mcsMQTT and HS come into the discussion.

        If you had something like a Zwave device with HS devices containing ldr, brightness etc, then you would use mcsMQTT to associate each of these HS devices to MQTT topics so that when the device changes a MQTT message would be sent and Node-Red would see it and forward to Graphana. For this sequence then you would have the topic entered in the mcsMQTT Pub text box on the Association (or Edit) tab. The Publish Payload Template on the Edit tab would be blank.

        I do not think mcsMQTT will publish the data for topics that it received. i.e. mcsMQTT will not act as a router. It will receive messages and update HS device. It will accept commands from HS to send messages. If it did this then your setup would have Multi/Livingroom/Temperature entered in the Publish Topic and not the Publish Payload text boxes on the Edit tab.

        Comment


          #5
          Well the reason HS and this plugin comes in discussion is that i receive it in homeseer and your plugin.
          i was testing with node-red and i could not subscribe or receive anything, besides the whole json string at once.

          thats why i did ask you if there is an other way to do it..

          regards
          Preferred -> Jon's Plugins, Pushover, Phlocation, Easy-trigger,
          Rfxcom, Blade Plugins, Pushbullet, homekit, Malosa Scripts




          HS3Pro 4.0.8.0 on windows 10 enterprise X64 on hp quadcore laptop 8 GB.

          Comment


            #6
            I am not a node-red user, but using JSON with node-red is very common. Node-red can receive the full JSON payload and then filter just the items of interest to forward to Grafana.

            Comment


              #7
              Nodered can easily parse all these atributes :

              {"state":"OFF","color":{"r":255,"g":255,"b":255},"brightn ess ":255,"humidity":"49","motion":"motion detected","ldr":"657","temperature":"23","heatIndex":"24.89" }.





              If you want an exemple I can give you one tomorrow, or after tomorrow.

              edit : (I am sure I forgot something I have to do tomorow at this moment lol).

              Anyways, If you want to see one...let me know.

              Comment


                #8
                But from memory,

                add a json node after you mqtt input . It will parse the json. Sometimes you have to parse a yalm and there is a node for this.

                after this put a debug node.

                after that you will be able to copy the path you want from the parsed json you will see in the debug tab on the right , to a set/change node .

                ex of a set/change node :
                set msg.state
                to msg.payload .


                That means the values (or wtv you want )from the attribute you are interested in will be transferred into msg.payload(which is the one you will send to grafana(not a grafana user here).


                Nb:msg.payload is the general topic in node red. Everything pass by this one when you are using simple flows. In general you send the msg.payload at the output of your flow.

                Not always true... But let’s start with the basics.

                Comment


                  #9
                  here is an exemple of flow that you can import into node red

                  :

                  Code:
                  [
                  {
                  "id": "756b33c1.44e70c",
                  "type": "tab",
                  "label": "Flow 1",
                  "disabled": false,
                  "info": ""
                  },
                  {
                  "id": "de3de6c4.d8af68",
                  "type": "inject",
                  "z": "756b33c1.44e70c",
                  "name": "",
                  "topic": "",
                  "payload": "{\"state\":\"OFF\",\"color\":{\"r\":255,\"g\":255,\"b\":255 },\"brightn ess \":255,\"humidity\":\"49\",\"motion\":\"motion detected\",\"ldr\":\"657\",\"temperature\":\"23\",\"heatInde x\":\"24.89\"}",
                  "payloadType": "str",
                  "repeat": "",
                  "crontab": "",
                  "once": false,
                  "onceDelay": 0.1,
                  "x": 270,
                  "y": 120,
                  "wires": [
                  [
                  "af9e3201.3918c"
                  ]
                  ]
                  },
                  {
                  "id": "5616434.6bf53bc",
                  "type": "debug",
                  "z": "756b33c1.44e70c",
                  "name": "",
                  "active": true,
                  "tosidebar": true,
                  "console": false,
                  "tostatus": false,
                  "complete": "payload",
                  "targetType": "msg",
                  "x": 870,
                  "y": 140,
                  "wires": []
                  },
                  {
                  "id": "af9e3201.3918c",
                  "type": "json",
                  "z": "756b33c1.44e70c",
                  "name": "",
                  "property": "payload",
                  "action": "",
                  "pretty": false,
                  "x": 460,
                  "y": 140,
                  "wires": [
                  [
                  "417f0d9.2e73df4",
                  "5616434.6bf53bc",
                  "7abfa39c.a35fdc",
                  "a269687f.c18698"
                  ]
                  ]
                  },
                  {
                  "id": "417f0d9.2e73df4",
                  "type": "change",
                  "z": "756b33c1.44e70c",
                  "name": "state",
                  "rules": [
                  {
                  "t": "set",
                  "p": "payload",
                  "pt": "msg",
                  "to": "payload.state",
                  "tot": "msg"
                  }
                  ],
                  "action": "",
                  "property": "",
                  "from": "",
                  "to": "",
                  "reg": false,
                  "x": 590,
                  "y": 40,
                  "wires": [
                  [
                  "5616434.6bf53bc"
                  ]
                  ]
                  },
                  {
                  "id": "7abfa39c.a35fdc",
                  "type": "change",
                  "z": "756b33c1.44e70c",
                  "name": "color red",
                  "rules": [
                  {
                  "t": "set",
                  "p": "payload",
                  "pt": "msg",
                  "to": "payload.color.r",
                  "tot": "msg"
                  }
                  ],
                  "action": "",
                  "property": "",
                  "from": "",
                  "to": "",
                  "reg": false,
                  "x": 640,
                  "y": 280,
                  "wires": [
                  [
                  "5616434.6bf53bc"
                  ]
                  ]
                  },
                  {
                  "id": "a269687f.c18698",
                  "type": "change",
                  "z": "756b33c1.44e70c",
                  "name": "motion",
                  "rules": [
                  {
                  "t": "set",
                  "p": "payload",
                  "pt": "msg",
                  "to": "payload.motion",
                  "tot": "msg"
                  }
                  ],
                  "action": "",
                  "property": "",
                  "from": "",
                  "to": "",
                  "reg": false,
                  "x": 610,
                  "y": 180,
                  "wires": [
                  [
                  "5616434.6bf53bc"
                  ]
                  ]
                  }
                  ]
                  + a picture
                  Attached Files

                  Comment


                    #10
                    Hi guys,

                    Sorry for the late response,

                    No worries Michael McSharry , im already happy your plugin exist and i can use it for all my devices, can't live without it haha.


                    many thanks for the example MattL0 and thanks for the explanation

                    the one u posted a bove is way more better than the one i did make after searching hours on google.


                    i did it like this, but yours is much easyer.
                    Code:
                    [
                    {
                    "id": "e4b45159.10fc2",
                    "type": "tab",
                    "label": "Flow 2",
                    "disabled": false,
                    "info": ""
                    },
                    {
                    "id": "5a31e0ac.62d5",
                    "type": "function",
                    "z": "e4b45159.10fc2",
                    "name": "Convert the devices",
                    "func": "msg.payload = [\n {\n measurement: \"Livingroom_Temperature\",\n fields: {\n temperature: Number(msg.payload.temperature),\n \n },\n tags:{\n Name:\"Temperature\"\n },\n timestamp: new Date()\n },\n {\n measurement: \"Livingroom_Humidity\",\n fields: {\n humidity: Number(msg.payload.humidity),\n },\n tags:{\n Name:\"Humidity\"\n },\n timestamp: new Date()\n },\n {\n measurement: \"Livingroom_LDR\",\n fields: {\n LDR: Number(msg.payload.ldr),\n },\n tags:{\n Name:\"LDR\"\n },\n timestamp: new Date()\n }\n];\nreturn msg;",
                    "outputs": 1,
                    "noerr": 0,
                    "x": 460,
                    "y": 80,
                    "wires": [
                    [
                    "9ad72ed8.4525f",
                    "1fd75997.e8fd46"
                    ]
                    ]
                    },
                    {
                    "id": "9ad72ed8.4525f",
                    "type": "influxdb batch",
                    "z": "e4b45159.10fc2",
                    "influxdb": "b6d0b81a.7491a8",
                    "precision": "",
                    "retentionPolicy": "",
                    "name": "HomeSeerNodeRED",
                    "x": 880,
                    "y": 100,
                    "wires": []
                    },
                    {
                    "id": "d5f5aa64.cd4748",
                    "type": "mqtt in",
                    "z": "e4b45159.10fc2",
                    "name": "Livingroom1",
                    "topic": "Multi1/Livingroom",
                    "qos": "2",
                    "datatype": "json",
                    "broker": "82b06a3f.637178",
                    "x": 110,
                    "y": 80,
                    "wires": [
                    [
                    "5a31e0ac.62d5"
                    ]
                    ]
                    },
                    {
                    "id": "1fd75997.e8fd46",
                    "type": "debug",
                    "z": "e4b45159.10fc2",
                    "name": "Debugger to test",
                    "active": false,
                    "tosidebar": true,
                    "console": true,
                    "tostatus": true,
                    "complete": "payload",
                    "targetType": "msg",
                    "x": 870,
                    "y": 240,
                    "wires": []
                    },
                    {
                    "id": "a49c8783.d25158",
                    "type": "mqtt in",
                    "z": "e4b45159.10fc2",
                    "name": "Kitchen",
                    "topic": "Multi2/Kitchen",
                    "qos": "2",
                    "datatype": "json",
                    "broker": "82b06a3f.637178",
                    "x": 90,
                    "y": 140,
                    "wires": [
                    [
                    "32e83608.3898da",
                    "1fd75997.e8fd46"
                    ]
                    ]
                    },
                    {
                    "id": "32e83608.3898da",
                    "type": "function",
                    "z": "e4b45159.10fc2",
                    "name": "Convert the devices",
                    "func": "msg.payload = [\n {\n measurement: \"Kitchen_Temperature\",\n fields: {\n temperature: Number(msg.payload.temperature),\n \n },\n tags:{\n Name:\"Temperature\"\n },\n timestamp: new Date()\n },\n {\n measurement: \"Kitchen_Humidity\",\n fields: {\n humidity: Number(msg.payload.humidity),\n },\n tags:{\n Name:\"Humidity\"\n },\n timestamp: new Date()\n },\n {\n measurement: \"Kitchen_LDR\",\n fields: {\n LDR: Number(msg.payload.ldr),\n },\n tags:{\n Name:\"LDR\"\n },\n timestamp: new Date()\n }\n];\nreturn msg;",
                    "outputs": 1,
                    "noerr": 0,
                    "x": 460,
                    "y": 140,
                    "wires": [
                    [
                    "9ad72ed8.4525f",
                    "1fd75997.e8fd46"
                    ]
                    ]
                    },
                    {
                    "id": "b6d0b81a.7491a8",
                    "type": "influxdb",
                    "z": "",
                    "hostname": "192.168.1.12",
                    "port": "8086",
                    "protocol": "http",
                    "database": "HomeSeerNodeRED",
                    "name": "",
                    "usetls": false,
                    "tls": "baa5e682.7bd758"
                    },
                    {
                    "id": "82b06a3f.637178",
                    "type": "mqtt-broker",
                    "z": "",
                    "name": "Homeseer",
                    "broker": "192.168.1.12",
                    "port": "1883",
                    "clientid": "",
                    "usetls": false,
                    "compatmode": false,
                    "keepalive": "60",
                    "cleansession": true,
                    "birthTopic": "",
                    "birthQos": "0",
                    "birthPayload": "",
                    "closeTopic": "",
                    "closeQos": "0",
                    "closePayload": "",
                    "willTopic": "",
                    "willQos": "0",
                    "willPayload": ""
                    },
                    {
                    "id": "baa5e682.7bd758",
                    "type": "tls-config",
                    "z": "",
                    "name": "local-tls",
                    "cert": "",
                    "key": "",
                    "ca": "",
                    "certname": "",
                    "keyname": "",
                    "caname": "",
                    "verifyservercert": false
                    }
                    ]
                    regards and have a nice day
                    Preferred -> Jon's Plugins, Pushover, Phlocation, Easy-trigger,
                    Rfxcom, Blade Plugins, Pushbullet, homekit, Malosa Scripts




                    HS3Pro 4.0.8.0 on windows 10 enterprise X64 on hp quadcore laptop 8 GB.

                    Comment


                      #11
                      MattL0

                      i did try yours, but when i use directly from my mqtt it does not work.
                      the data is identical as the one in the "inject"
                      but the one in inject is in string format, and the one what i receive trough this plugin is in json.

                      The device livingroom1 i receive trough mcsmqtt plugin


                      Click image for larger version  Name:	MqttNodered.png Views:	0 Size:	217.8 KB ID:	1393010
                      Preferred -> Jon's Plugins, Pushover, Phlocation, Easy-trigger,
                      Rfxcom, Blade Plugins, Pushbullet, homekit, Malosa Scripts




                      HS3Pro 4.0.8.0 on windows 10 enterprise X64 on hp quadcore laptop 8 GB.

                      Comment


                        #12
                        Michael McSharry

                        i have again a question

                        How exactly does the Encode Payload per template work ?

                        what i did was create from every window sensor a mqtt topic like this:

                        windowsensors/firstfloor/livingroom/back
                        windowsensors/firstfloor/livingroom/front
                        windowsensors/secondfloor/masterbedroom/left etc


                        Well when i use this topic windowsensors# instead of windowsensors/firstfloor/livingroom/back i get every sensor open-closed state.
                        it only shows the value 100 and 0 but not from what device it is.

                        so i thought the encode payload was for making your own output like json, i did give it a try but failed..

                        i did try like this :

                        {"LivingroomWindow":$$VALUE,"Location":Back}
                        this does not work as i get a error on the value
                        if i remove $$VALUE it works but ofcourse no value


                        i just want that it shows up like a json string with my own added data instead of only a value of a random device in that topic, i don't know if its possible ?
                        like if thats possible i don't have to code everything seperate

                        regards and have a wonderfull day .

                        Preferred -> Jon's Plugins, Pushover, Phlocation, Easy-trigger,
                        Rfxcom, Blade Plugins, Pushbullet, homekit, Malosa Scripts




                        HS3Pro 4.0.8.0 on windows 10 enterprise X64 on hp quadcore laptop 8 GB.

                        Comment


                          #13
                          The payload template you are using is close to correct for a JSON payload. The substitution variable is $$VALUE: (i.e. colon at the end). Text in JSON needs to be enclosed in quotes so "Location":"Back".

                          Where are you using windowsensors# ? Something like this is normally done when subscribing to topics. mcsMQTT handles subscriptions based upon the topics that have been associated. I understand the problem you are trying to resolve with the JSON payload, but I suspect you are introducing the problem and you do not need to. It is possible to put identification information in the payload and I have seen done with various devices, but it really is not a good practice as that defeats the purpose of the topic being used to identify the end point.

                          Comment


                            #14
                            Thanks for your explanation Michael McSharry , and thanks for the reply MattL0

                            Well i'm understanding json now and also the mqtt flows after checking all examples and tons of youtube video's.

                            i did try it and i got it, i just wanted that the device change the payload to json so i can extract all data at once, instead per device .
                            otherwise i need to subscribe to all devices seperatly.

                            i did add this here: Encode Payload per template (for each windows device)
                            {"Device":"Windowsensor","Floor":"Firstfloor","Room":"Liv ing room","WhatWindow":"Backwindow","State":$$STATUS:

                            Well in node-red i perfectly receive the devices from your mqtt plugin, but i wanted to make it a bit more advance so i can code a script that i can retrieve all devices in 1 flow, and decode them seperatly.

                            and i got it working really well.
                            Preferred -> Jon's Plugins, Pushover, Phlocation, Easy-trigger,
                            Rfxcom, Blade Plugins, Pushbullet, homekit, Malosa Scripts




                            HS3Pro 4.0.8.0 on windows 10 enterprise X64 on hp quadcore laptop 8 GB.

                            Comment

                            Working...
                            X