Using a global variable in the data/json

Hello,

I'm trying to create a flow to change the brightness of my light, I can set the brightness directly however I can't figure out how to use a global variable I've set elsewhere in the flow. I'm sure I'm just not using the right syntax.

currently my json looks like this

{
    "entity_id": "light.living_room_main_light_light",
    "brightness": 22
}

instead of the number 22 I want to use a variable global.brightness put I dom not know how to import the variable into the json correctly.

Thanks in advince

There are several ways.

The easiest is to pass the msg through a change node and set msg.payload.brightness to global.brightness

Assuming you mean a JS Object (JSON is a string), then the above will work.

Sorry if JSON is not the correct term.

I'm using a service call node and editing the data field.

I need to be able to pull in the global variable.

I've created a payload message as you suggested, how do I use the payload instead of the 22 value?

I have no idea what that is.

does the nodes field support JSONata? You could use JSONata to grab context values. Or perhaps there is a msg fired into this " service call node" in which case you can use the switch node BEFORE it to grab the global value and add it to the payload?

If this is a home assistant node, then please tag the post with home-assistant so that others are not tripped up too.

It is a home assistant node, sorry for the confusion.

I'll try and figure out how to tag the post

1 Like

Select J: (jsonata expression) rather than JSON type input.
Then

{
    "entity_id": "light.living_room_main_light_light",
    "brightness": globalContext("brightness")
}
{
    "entity_id": "light.living_room_main_light_light",
    "brightness": msg.payload
}

many thinkas , this was what I needed , It's all working now :slight_smile:

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