Global Context in Node

So pretty new to node-red but I've been learning a lot in the last few weeks... that being said I was using node-red with the Huemagic node to control my lights. I've recently changed to a zigbee2mqtt setup. Only problem is, the node for z2m contains the settings for the lights within the node? not sure if I'm stating it correctly, however the pictures will show what I mean.

Before with huemagic I passed on the settings with a change node then to the light. Now within the node to control the light I specify the settings. No big deal... except for the lights where I control the temperature with a global variable that changes. How do I recall the global context within that message? I'm sure I'm not stating it correctly, so hopefully the pictures will help...


Old way with the change node


New way with the new node

Thanks for any help!

What options do you have in the type field for payload, other than json {}?

Hi.

I'm not an expert and don't use those nodes.

Something to maybe help though is:
rather than post screen shots of the nodes, also include the actual node. (Export it)

Yes, that means people will have to have that node installed and - yes I am one of them - people may not be keen on installing nodes.

But I think it will help get the bigger message through to people who are interested.

msg., flow., global., string, number, and then JSON

I believe I'm using the JSON to set all the parameters instead of just one? To be completely honest the documentation on the node is quite lacking... found the format I needed in Issues on the github rather than in the readme...

Sure thing!

[{"id":"3763d256.7bb84e","type":"zigbee2mqtt-out","z":"42731f5d.a5d2f","name":"Closet Bright","server":"a9e92c14.0a08e","friendly_name":"Closet Ceiling","device_id":"0x0017880108e450d9","command":"payload","commandType":"msg","payload":"{\"state\":\"ON\",\"brightness\":254,\"color_temp\":233,\"transition\":2}","payloadType":"json","transition":0,"x":710,"y":180,"wires":[]},{"id":"a9e92c14.0a08e","type":"zigbee2mqtt-server","name":"zigbee2mqtt","host":"localhost","mqtt_port":"1883","mqtt_username":"echo29mqtt","mqtt_password":"","tls":"","usetls":false,"base_topic":"zigbee2mqtt"}]```

So the only option is to use msg and a change or function node to construct the object.

So how I was doing it before then, with Huemagic? I was just confused because the node wanted the parameters within the node itself...

Yes but, there are some slight differences to the property names i.e transtion.time becomes transition.

Right... I got that. Just not the variable color change. Alright I'll tinker with that. Thank you!

Function node was it, thanks so much! Think I got confused with the lack of documentation and considering it was all inside the node itself.

You can also use a template node, here is an example

[{"id":"21f5866d.471d3a","type":"inject","z":"b779de97.b1b46","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":180,"y":780,"wires":[["2341e933.f676e6"]]},{"id":"2341e933.f676e6","type":"template","z":"b779de97.b1b46","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\n\"state\":\"ON\",\n\"brightness\":254,\n\"color_temp\": {{global.colorTemp}},\n\"transition\": 2\n}","output":"str","x":370,"y":740,"wires":[["fa3c27d1.9fbb8"]]},{"id":"fa3c27d1.9fbb8","type":"debug","z":"b779de97.b1b46","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":450,"y":640,"wires":[]}]

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