# How use flow variable?

**URL:** <https://discourse.nodered.org/t/how-use-flow-variable/55686>\
**Category:** General\
**Created:** [25 December 2021 17:01 UTC](https://discourse.nodered.org/t/how-use-flow-variable/55686 "2021-12-25T17:01:32Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![diyIoT](https://avatars.discourse-cdn.com/v4/letter/d/67e7ee/32.png) [@diyIoT](https://discourse.nodered.org/u/diyIoT)\
**Post date:** [25 December 2021 17:01 UTC](https://discourse.nodered.org/t/how-use-flow-variable/55686/1 "2021-12-25T17:01:32Z")

</div>

I get the id of a Tunein station that I memorize

 ![flow](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/9/b9060d164ec3ddcfe01df1e13cbb6e4e3a142a14.png)

````auto
{
    if(data[i]["data-nextguideitem"] != null 
        && data[i]["data-testid"] === "guideItem-0")
    {
        msg.payload = data[i]["data-nextguideitem"];

        if(flow.get("franceInter") !== msg.payload) 
        {
            flow.set("franceInter", msg.payload);
        }
        return msg;
    }
}```

and I want to inject into a node Sonos : 

$env(flow.get("franceInter"))

but I get : 

```group.play.tunein: radio id (payload) >>$env(flow.get("franceInter")) wrong syntax. Regular expr. - see documentation :: Details: none```

Thank for your help
:
````

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [25 December 2021 20:10 UTC](https://discourse.nodered.org/t/how-use-flow-variable/55686/2 "2021-12-25T20:10:28Z")

</div>

`$env(flow.get("franceInter"))`

I don't think that is correct syntax.

`$env` gets the environment variable.

So you are doing to `get` things.

I also don't get what that you are wanting to do with the code you posted.

I didn't import the bigger code you posted because I don't think I have that second node and so won't be able to test it anyway.

---

<div class="post-metadata">

**Author:** ![diyIoT](https://avatars.discourse-cdn.com/v4/letter/d/67e7ee/32.png) [@diyIoT](https://discourse.nodered.org/u/diyIoT)\
**Post date:** [25 December 2021 20:37 UTC](https://discourse.nodered.org/t/how-use-flow-variable/55686/3 "2021-12-25T20:37:13Z")

</div>

I would like to call my variable from this node

 ![node](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/9/39127e547a30da90ee78af65b1d7fdf65c2ea718.png)

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [25 December 2021 20:39 UTC](https://discourse.nodered.org/t/how-use-flow-variable/55686/4 "2021-12-25T20:39:18Z")

</div>

Sorry. I have no knowledge of that node or how it works.

Just the code you posted doesn't look right.

---

<div class="post-metadata">

**Author:** ![diyIoT](https://avatars.discourse-cdn.com/v4/letter/d/67e7ee/32.png) [@diyIoT](https://discourse.nodered.org/u/diyIoT)\
**Post date:** [25 December 2021 21:02 UTC](https://discourse.nodered.org/t/how-use-flow-variable/55686/6 "2021-12-25T21:02:22Z")

</div>

Only "string" or "number" ?

package "node-red-contrib-sonos-plus" - "Universal" node

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [25 December 2021 21:10 UTC](https://discourse.nodered.org/t/how-use-flow-variable/55686/7 "2021-12-25T21:10:45Z")

</div>

You will have to retrieve the context **before** the sonos node and pass it in as a payload. You cannot retrieve it as your screenshot because its expecting a string or a number.  
Have you read the link `see documentation`?

---

<div class="post-metadata">

**Author:** ![diyIoT](https://avatars.discourse-cdn.com/v4/letter/d/67e7ee/32.png) [@diyIoT](https://discourse.nodered.org/u/diyIoT)\
**Post date:** [25 December 2021 21:20 UTC](https://discourse.nodered.org/t/how-use-flow-variable/55686/8 "2021-12-25T21:20:32Z")

</div>

Yes but I don't see the solution ...

> **[A.1 Universal Node · hklages/node-red-contrib-sonos-plus Wiki](https://github.com/hklages/node-red-contrib-sonos-plus/wiki/A.1-Universal-Node#groupplaytunein)**
>
> A set of Node-RED nodes to control SONOS player in your local network. - A.1 Universal Node · hklages/node-red-contrib-sonos-plus Wiki

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [25 December 2021 21:30 UTC](https://discourse.nodered.org/t/how-use-flow-variable/55686/9 "2021-12-25T21:30:09Z")

</div>

If you are saving the radio station id to `flow.context` in the format described in `see documentation` -

> REGEX check. the TuneIn radio station id such as 's97033'. Don't add additional blanks or whitespace.

then add a `change node` before the sonos node to retrieve that data, and feed it into sonos as a payload

![flow](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/d/fd6efef85c5b54681a5c13c5d584265e4847a6b0.jpeg)

I don't use this node, so can't help you further, but hopefully another user may be able to.

---

<div class="post-metadata">

**Author:** ![diyIoT](https://avatars.discourse-cdn.com/v4/letter/d/67e7ee/32.png) [@diyIoT](https://discourse.nodered.org/u/diyIoT)\
**Post date:** [25 December 2021 21:47 UTC](https://discourse.nodered.org/t/how-use-flow-variable/55686/10 "2021-12-25T21:47:54Z")

</div>

Ok thank. I tried without success

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [25 December 2021 22:12 UTC](https://discourse.nodered.org/t/how-use-flow-variable/55686/11 "2021-12-25T22:12:14Z")

</div>

> [@diyIoT](#):
>
> `flow.get("franceInter")`

What is the value of that ?

---

<div class="post-metadata">

**Author:** ![diyIoT](https://avatars.discourse-cdn.com/v4/letter/d/67e7ee/32.png) [@diyIoT](https://discourse.nodered.org/u/diyIoT)\
**Post date:** [25 December 2021 22:14 UTC](https://discourse.nodered.org/t/how-use-flow-variable/55686/12 "2021-12-25T22:14:59Z")

</div>

The value is : s24875

---

<div class="post-metadata">

**Author:** ![diyIoT](https://avatars.discourse-cdn.com/v4/letter/d/67e7ee/32.png) [@diyIoT](https://discourse.nodered.org/u/diyIoT)\
**Post date:** [26 December 2021 15:35 UTC](https://discourse.nodered.org/t/how-use-flow-variable/55686/13 "2021-12-26T15:35:15Z")

</div>

I found out how to do it  
I load the variable from a function before injecting it into the node, leaving the payload field empty  
Thanks to everyone who took the time

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [9 January 2022 15:35 UTC](https://discourse.nodered.org/t/how-use-flow-variable/55686/14 "2022-01-09T15:35:28Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
