Announcement

Collapse
No announcement yet.

(Solved) How use the change node correctly?

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

    (Solved) How use the change node correctly?

    Beginner trying to learn a bit of Node-Red, but I'm struggling with the Change node.

    As you can see the data that comes from Home Assistant is msg.payload : number
    I'm trying to change the msg so that it can update a HS device.

    Is there anyone that can point me in the correct direction?


    Click image for larger version  Name:	image.png Views:	7 Size:	63.1 KB ID:	1627201
    Click image for larger version  Name:	image.png Views:	7 Size:	12.3 KB ID:	1627202​​

    #2
    Was able to solve it:

    Click image for larger version

Name:	image.png
Views:	126
Size:	10.4 KB
ID:	1627204

    Comment


      #3
      Since msg.payload is not object but a simple variable, you cannot change it to an object. The same is true for an object to a variable. To resolve this, use the Move to set it to something like msg.incoming by moving it to incoming. Now that msg.payload does not exist you can set msg.payload.value to msg.incoming, making msg.payload an object. To do this, get the Move above your Set line and in the Set line, change the second payload to incoming.

      The Node-Red nodes assume msg. In front of the variables. This is why you do not see it in the Change node.

      I won't be near a computer to get screen capture for a day or two. Hopefully this makes sense.
      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


        #4
        Originally posted by ksum View Post
        Since msg.payload is not object but a simple variable, you cannot change it to an object. The same is true for an object to a variable. To resolve this, use the Move to set it to something like msg.incoming by moving it to incoming. Now that msg.payload does not exist you can set msg.payload.value to msg.incoming, making msg.payload an object. To do this, get the Move above your Set line and in the Set line, change the second payload to incoming.

        The Node-Red nodes assume msg. In front of the variables. This is why you do not see it in the Change node.

        I won't be near a computer to get screen capture for a day or two. Hopefully this makes sense.
        Ah, yes that makes sense!
        Thanks for the clarification!
        I tried something similar at first with the function node, but abandoned that quickly 😅

        Comment


          #5
          Avoid the function node if possible. It has a lot of extra overhead and it's slower than running through a couple change and switch nodes to do the same thing. Meaning the flow goes through a couple of each even though there may be dozens of total nodes in the flow.
          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