Solved NODE-RED Join push variable

Discussion in 'Join' started by MAaron, Jul 26, 2020.

  1. MAaron

    MAaron New Member

    Joined:
    Apr 7, 2019
    Messages:
    9
    Likes Received:
    0
    Hi there!

    I would like to ask, how to integrate a variable into a join push message, so that the join push node only sends a variable?

    Using the % in the node's 'message" doesn't seem to work.

    Thank you!
     
  2. joaomgcd

    joaomgcd Administrator Staff Member

    Joined:
    Feb 3, 2015
    Messages:
    9,421
    Likes Received:
    792
  3. MAaron

    MAaron New Member

    Joined:
    Apr 7, 2019
    Messages:
    9
    Likes Received:
    0
    Sorrily, it does not help

    If I make a function node, populating it with the following

    msg.text = '%AirCondOn';
    msg.devices = "Galaxy Note9";
    return msg;

    Where %AirCondOn is a global variable within nodered, it just sends %AirCondOn, not the value.
     
  4. joaomgcd

    joaomgcd Administrator Staff Member

    Joined:
    Feb 3, 2015
    Messages:
    9,421
    Likes Received:
    792
    If it's a variable you should simply use msg.text = AirCondOn; :)
     
  5. MAaron

    MAaron New Member

    Joined:
    Apr 7, 2019
    Messages:
    9
    Likes Received:
    0
    Tried that too, nodered gives me this error:

    "ReferenceError: AirCondOn is not defined (line 1, col 12)"
     
  6. joaomgcd

    joaomgcd Administrator Staff Member

    Joined:
    Feb 3, 2015
    Messages:
    9,421
    Likes Received:
    792
    Seems like the variable is not defined then. Do you know how to usually access that variable from a function node?
     
  7. MAaron

    MAaron New Member

    Joined:
    Apr 7, 2019
    Messages:
    9
    Likes Received:
    0
    Yes I overlooked something, and just found out thats not how I access that variable...

    I use a function node:

    var ObtainedData = global.get("AirCondOn")
    msg.payload = ObtainedData;
    return msg;

    and then another function node

    msg.text = msg.payload;
    msg.devices = "Galaxy Note9";
    return msg;

    this way, it works.

    Thanks anyways :)
     
  8. joaomgcd

    joaomgcd Administrator Staff Member

    Joined:
    Feb 3, 2015
    Messages:
    9,421
    Likes Received:
    792
    Cool! :) Glad it works!
     
  9. MAaron

    MAaron New Member

    Joined:
    Apr 7, 2019
    Messages:
    9
    Likes Received:
    0
    I can't believe what's happening. Literally

    I made this mentioned flow as a test flow, with a simple inject at the start.

    var ObtainedData = global.get("AirCondOn")
    msg.payload = ObtainedData;
    return msg;

    and then another function node

    msg.text = msg.payload;
    msg.devices = "Galaxy Note9";
    return msg;


    It worked by itself.

    When I copied it into the desired place, it now gives me another error:
    msg : string[20]
    "text needs to be set"

    What the hekk is going on? :D
     
  10. joaomgcd

    joaomgcd Administrator Staff Member

    Joined:
    Feb 3, 2015
    Messages:
    9,421
    Likes Received:
    792
    Maybe you could use msg.text = global.get("AirCondOn")?
     
  11. MAaron

    MAaron New Member

    Joined:
    Apr 7, 2019
    Messages:
    9
    Likes Received:
    0
    Yea tried that too, gives the same error, and doesn't send anything.

    What I don't get is how is it even possible, that it worked (I didn't only looked at the flow, I checked my phone, where the flow sent the variable, and it did send the variable value), I copied, and suddenly it doesn't work.

    Tried rewriting the every node, tried restarting node-red itself, no success...
    Maybe tomorroww by itself, it will work again.
     
  12. MAaron

    MAaron New Member

    Joined:
    Apr 7, 2019
    Messages:
    9
    Likes Received:
    0
    Works again, using () - which I don't even understand...

    msg.devices = "Galaxy Note9";
    msg.text = (msg.payload);
    return msg;
     

Share This Page