Announcement

Collapse
No announcement yet.

How to send a HS value

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

    How to send a HS value

    I want to send the following msg.payload to Node-RED. The highlighted part "100" should be a variable and based on the value of the HomeSeer device. The other part of the payload is fixed.

    Click image for larger version

Name:	Capture dps.PNG
Views:	314
Size:	6.9 KB
ID:	1508949
    ---
    John

    #2
    Instead of setting a JSON value, get the value from a HomeSeer device node and use two lines set msg.payload.set to the value coming out of the HomeSeer node, msg.payload.value
    set msg.payload.dps to a numeric value of 3.

    If your following nodes cannot deal with all the other properties the HomeSeer node sets in msg.payload, you can first move msg.payload to a different name.

    I can provide examples when I'm at a computer if needed.

    If the flow is initiated on the change of the HomeSeer device holding the set value (100 in your example) then it can be the first node in your flow. Otherwise send the HomeSeer node message with msg.topic set to update to get the current value.

    ​​​​​​
    Karl S
    HS4Pro on Windows 10
    1070 Devices
    56 Z-Wave Nodes
    104 Events
    HSTouch Clients: 3 Android, 1 iOS
    Google Home: 3 Mini units, 1 Pair Audios, 2 Displays

    Comment


      #3
      Originally posted by ksum View Post
      Instead of setting a JSON value, get the value from a HomeSeer device node and use two lines set msg.payload.set to the value coming out of the HomeSeer node, msg.payload.value
      set msg.payload.dps to a numeric value of 3.

      If your following nodes cannot deal with all the other properties the HomeSeer node sets in msg.payload, you can first move msg.payload to a different name.

      I can provide examples when I'm at a computer if needed.

      If the flow is initiated on the change of the HomeSeer device holding the set value (100 in your example) then it can be the first node in your flow. Otherwise send the HomeSeer node message with msg.topic set to update to get the current value.

      ​​​​​​
      Any example will be appreciated.

      ---
      John

      Comment


        #4
        At the end of this post I will attempt to explain why setting the values as shown below and setting msg.payload to the JSON of {"set:100,"dps":3} as originally requested are the same.

        The You will only use the first two nodes in this flow. The debug is, of course, to show the result and will be replaced with the rest of your flow. In this first example, when my HomeSeer device (a door sensor) changes the HomeSeer node sends out a message, initiating the flow. Normal behavior for the HomeSeer nodes.
        Click image for larger version

Name:	HS1.png
Views:	351
Size:	8.4 KB
ID:	1508999


        The Change node sets msg.payload.set and msg.payload.dps as shown below. We are using the value sent from the HomeSeer node, which is a number. In this MySensor case it is either 0 or 255. The dps property is set to a constant.
        Click image for larger version

Name:	HS2.png
Views:	279
Size:	21.3 KB
ID:	1509000


        When the sensor changes, the resulting message contains the two requested Properties of the msg.payload object as well as the Properties set via the HomeSeer node:
        Click image for larger version

Name:	HS3.png
Views:	275
Size:	21.1 KB
ID:	1509001


        IF whatever you are controlling thorws an error because it is getting too much in the payload object (msg.payload) as a result of still retaining the HomeSeer properties, we need to first Move msg.payload to a different property. We then reference that new property and set msg.payload to contain only the desired values. This has the bonus of maintaining the HomeSeer device's information through the entire flow if needed later.
        Click image for larger version

Name:	HS7.png
Views:	274
Size:	25.2 KB
ID:	1509002


        The resulting output becomes:
        Click image for larger version

Name:	HS8.png
Views:	280
Size:	23.2 KB
ID:	1509003



        Setting JSON vs Object Properties

        To show you are getting the same thing, let's look at the flow below. I am using an Inject node to initiate the flow, only for simplicity. I could use the above HomeSeer node and set the requested value to the HomeSeer value but that gets unnecessarily complicated.
        Click image for larger version

Name:	HS4.png
Views:	277
Size:	6.8 KB
ID:	1509004


        The Change node is set to the requested JSON with the exception that I changed the value of the set property to 0 to match my HomeSeer device output:
        Click image for larger version

Name:	HS5.png
Views:	275
Size:	14.9 KB
ID:	1509005


        Running this provides the following debug message. Note that it shows the set and dps values consistent with the outputs above:
        Click image for larger version

Name:	HS6.png
Views:	283
Size:	9.3 KB
ID:	1509006



        Why is this?
        JSON is JavaScript Object Notation. A way of notating an Object which is used as a way of sending Object data to different programs and languages and/or saving them to a file.

        An Object is a variable type which holds one or more "sub" variables, which can be other Objects or other Variable types such as a string. Normally these are considered to be like items. A Car is an object. t he Make, Model, Color, Mileage, etc. are Properties of the Car Object. A Property has Keys and Values. The Key is the sub variable name and the value is what that is set to. For our needs msg is an Object and payload is a Sub Object. This is written as msg.payload. The payload Property can be a simple variable (string, number, etc.) or an Object itself. So in our above example, and all HomeSeer node output, the payload Property is an Object.

        In Node-RED when you set a Property to a JSON type (making the to the value dropdown {} - JSON) it reads the JSON value and saves it as an actual Object and not a text string.

        Why doesn't my receiving node like this???
        SOME (poorly written, IMHO) nodes do not take Objects but require a JSON Text String. In these cases you need to set the Property, typically msg.payload, to a String and not a JSON type, as shown below. Note that the to the value dropdown is set to az and not {}.
        Click image for larger version

Name:	9.png
Views:	267
Size:	5.7 KB
ID:	1509007



        I am sure all this is mind numbing. Feel free to ask questions...

        Karl
        Karl S
        HS4Pro on Windows 10
        1070 Devices
        56 Z-Wave Nodes
        104 Events
        HSTouch Clients: 3 Android, 1 iOS
        Google Home: 3 Mini units, 1 Pair Audios, 2 Displays

        Comment


          #5
          Originally posted by ksum View Post
          At the end of this post I will attempt to explain why setting the values as shown below and setting msg.payload to the JSON of {"set:100,"dps":3} as originally requested are the same.

          The You will only use the first two nodes in this flow. The debug is, of course, to show the result and will be replaced with the rest of your flow. In this first example, when my HomeSeer device (a door sensor) changes the HomeSeer node sends out a message, initiating the flow. Normal behavior for the HomeSeer nodes.
          Click image for larger version  Name:	HS1.png Views:	0 Size:	8.4 KB ID:	1508999



          The Change node sets msg.payload.set and msg.payload.dps as shown below. We are using the value sent from the HomeSeer node, which is a number. In this MySensor case it is either 0 or 255. The dps property is set to a constant.
          Click image for larger version  Name:	HS2.png Views:	0 Size:	21.3 KB ID:	1509000



          When the sensor changes, the resulting message contains the two requested Properties of the msg.payload object as well as the Properties set via the HomeSeer node:
          Click image for larger version  Name:	HS3.png Views:	0 Size:	21.1 KB ID:	1509001



          IF whatever you are controlling thorws an error because it is getting too much in the payload object (msg.payload) as a result of still retaining the HomeSeer properties, we need to first Move msg.payload to a different property. We then reference that new property and set msg.payload to contain only the desired values. This has the bonus of maintaining the HomeSeer device's information through the entire flow if needed later.
          Click image for larger version  Name:	HS7.png Views:	0 Size:	25.2 KB ID:	1509002



          The resulting output becomes:
          Click image for larger version  Name:	HS8.png Views:	0 Size:	23.2 KB ID:	1509003




          Setting JSON vs Object Properties

          To show you are getting the same thing, let's look at the flow below. I am using an Inject node to initiate the flow, only for simplicity. I could use the above HomeSeer node and set the requested value to the HomeSeer value but that gets unnecessarily complicated.
          Click image for larger version  Name:	HS4.png Views:	0 Size:	6.8 KB ID:	1509004



          The Change node is set to the requested JSON with the exception that I changed the value of the set property to 0 to match my HomeSeer device output:
          Click image for larger version  Name:	HS5.png Views:	0 Size:	14.9 KB ID:	1509005



          Running this provides the following debug message. Note that it shows the set and dps values consistent with the outputs above:
          Click image for larger version  Name:	HS6.png Views:	0 Size:	9.3 KB ID:	1509006




          Why is this?
          JSON is JavaScript Object Notation. A way of notating an Object which is used as a way of sending Object data to different programs and languages and/or saving them to a file.

          An Object is a variable type which holds one or more "sub" variables, which can be other Objects or other Variable types such as a string. Normally these are considered to be like items. A Car is an object. t he Make, Model, Color, Mileage, etc. are Properties of the Car Object. A Property has Keys and Values. The Key is the sub variable name and the value is what that is set to. For our needs msg is an Object and payload is a Sub Object. This is written as msg.payload. The payload Property can be a simple variable (string, number, etc.) or an Object itself. So in our above example, and all HomeSeer node output, the payload Property is an Object.

          In Node-RED when you set a Property to a JSON type (making the to the value dropdown {} - JSON) it reads the JSON value and saves it as an actual Object and not a text string.

          Why doesn't my receiving node like this???
          SOME (poorly written, IMHO) nodes do not take Objects but require a JSON Text String. In these cases you need to set the Property, typically msg.payload, to a String and not a JSON type, as shown below. Note that the to the value dropdown is set to az and not {}.
          Click image for larger version  Name:	9.png Views:	0 Size:	5.7 KB ID:	1509007




          I am sure all this is mind numbing. Feel free to ask questions...

          Karl
          Hi Karl,

          Thanks a lot for the solution, much appreciated. But especially many thanks for the explanation. This helps me a lot.

          This is worth a sticky.

          Do you know a good Node-RED manual?

          ---
          John




          Comment


            #6
            Originally posted by John245 View Post
            Hi Karl,

            Thanks a lot for the solution, much appreciated. But especially many thanks for the explanation. This helps me a lot.

            This is worth a sticky.

            Do you know a good Node-RED manual?

            ---
            John



            I am glad it helps.

            I had many hours of JavaScript programming time prior to HomeSeer incorporating Node-RED so much of it was quick for me to pick up. I did find these, in no particular order, to be helpful when starting Node-RED, though:
            • The official Node-RED tutorials
            • Opto Video's Node-RED tutorials on YouTube
            • Steve's Node-RED Guide, although he does use function nodes to do things more than I believe he should. I understand that he is often using them to allow you to focus on the parts he is teaching. My problem is that Function Nodes are slower and use more resources than other nodes to do the same thing and the examples used do some very basic things inside Function Nodes, promoting one thing you should avoid.
            Recognize that when possible, even if these tutorials show their use, the Function Nodes should be avoided whenever possible and you should be fine.
            Karl S
            HS4Pro on Windows 10
            1070 Devices
            56 Z-Wave Nodes
            104 Events
            HSTouch Clients: 3 Android, 1 iOS
            Google Home: 3 Mini units, 1 Pair Audios, 2 Displays

            Comment


              #7
              I bet ksum could produce some amazing tutorial videos on Node-Red.. Just sayin'...
              RJ_Make On YouTube

              Comment


                #8
                Originally posted by ServiceXp View Post
                I bet ksum could produce some amazing tutorial videos on Node-Red.. Just sayin'...
                It was put on hold, but still planning to do so...
                Karl S
                HS4Pro on Windows 10
                1070 Devices
                56 Z-Wave Nodes
                104 Events
                HSTouch Clients: 3 Android, 1 iOS
                Google Home: 3 Mini units, 1 Pair Audios, 2 Displays

                Comment

                Working...
                X