Help with a bit of code - sync devices brightness

Hi,
I’m trying to copy the brightness from one device to another one. It’s been an hour of trying and I keep not being able to pass the parameter to the higher level.
image
I’m sadly very bad with coding.

What am I doing wrong? Thanks for the help.

[{"id":"e90bf93c.3ccf88","type":"server-state-changed","z":"cbd6d85d.24f998","name":"","server":"a0eea9da.0fe1d8","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"light.office_ikea_panel","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":false,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"x":210,"y":360,"wires":[["3b1c40d4.3f547"]]},{"id":"3b1c40d4.3f547","type":"api-current-state","z":"cbd6d85d.24f998","name":"State","server":"a0eea9da.0fe1d8","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"light.office_ikea_panel","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":410,"y":300,"wires":[["ccecbe5d.78f09"]]},{"id":"ccecbe5d.78f09","type":"change","z":"cbd6d85d.24f998","name":"change","rules":[{"t":"set","p":"data.brightness","pt":"msg","to":"officebrightness","tot":"global"}],"action":"","property":"","from":"","to":"","reg":false,"x":540,"y":360,"wires":[["1bb2734.f289a8d"]]},{"id":"1bb2734.f289a8d","type":"api-call-service","z":"cbd6d85d.24f998","name":"","server":"a0eea9da.0fe1d8","version":1,"debugenabled":true,"service_domain":"light","service":"turn_on","entityId":"light.office_light_1, light.office_light_2, sensor.office_sensor_3","data":"","dataType":"json","mergecontext":"officebrightness","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":730,"y":360,"wires":[["530d449b.decb0c"]]},{"id":"530d449b.decb0c","type":"debug","z":"cbd6d85d.24f998","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":910,"y":360,"wires":[]},{"id":"a0eea9da.0fe1d8","type":"server","name":"Home Assistant New","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

Shouldn’t that be payload?

image

I tried and tried again and I’m not getting it.
The service node from hassio uses Merge Context
So in order to pass this, I need to change my state
data.attributes.brightness: 167
to
global.officebrightness [json code to make it pass “brightness: 167”]

I tried several times but I don’t know how to call the value within the json code

{
    "brightness": "what do I put here???"
}

if the nodes are connected with wires, you don’t need to use global or flow context (usually). something like this:

[{"id":"1bb2734.f289a8d","type":"api-call-service","z":"2d553bd.44a3dc4","name":"","server":"9999f305.d47be","version":1,"debugenabled":true,"service_domain":"light","service":"turn_on","entityId":"light.office","data":"data.event.new_state.attributes.brightness","dataType":"jsonata","mergecontext":"officebrightness","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":570,"y":400,"wires":[["530d449b.decb0c"]]},{"id":"530d449b.decb0c","type":"debug","z":"2d553bd.44a3dc4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":830,"y":400,"wires":[]},{"id":"6670a94f.2ca568","type":"server-state-changed","z":"2d553bd.44a3dc4","name":"","server":"9999f305.d47be","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"light.entrance","entityidfiltertype":"exact","outputinitially":true,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":false,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"x":270,"y":400,"wires":[["1bb2734.f289a8d"]]},{"id":"9999f305.d47be","type":"server","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

Just tried but the data is not passed


The top msg is the one turning on the second light.

The only way I found this to use was to pass the data in a global flow. Once again, here’s my trouble: I don’t know how to populate that global flow from data coming from a state node before.

SOLVED :slight_smile:
I suspect this is what @serkank was reffering to, but I found a nice answer that I adapted in this post.

I’m sharing my final code. It was actually very simple (of course).

[{"id":"e90bf93c.3ccf88","type":"server-state-changed","z":"cbd6d85d.24f998","name":"Light 1","server":"a0eea9da.0fe1d8","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"light.office_ikea_panel","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":false,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"x":170,"y":640,"wires":[["ce8cfe44.8a014"]]},{"id":"ce8cfe44.8a014","type":"api-current-state","z":"cbd6d85d.24f998","name":"State","server":"a0eea9da.0fe1d8","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"light.office_ikea_panel","state_type":"str","state_location":"","override_payload":"none","entity_location":"officebrightness","override_data":"msg","blockInputOverrides":false,"x":310,"y":660,"wires":[["203d893c.f65876"]]},{"id":"203d893c.f65876","type":"api-call-service","z":"cbd6d85d.24f998","name":"Light 2","server":"a0eea9da.0fe1d8","version":1,"debugenabled":true,"service_domain":"light","service":"turn_on","entityId":"light.office_light_1, light.office_light_2, light.office_light_3","data":"{\"brightness\":\"{{officebrightness.attributes.brightness}}\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":470,"y":640,"wires":[["3cb8d13b.b307be"]]},{"id":"3cb8d13b.b307be","type":"debug","z":"cbd6d85d.24f998","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":610,"y":640,"wires":[]},{"id":"a0eea9da.0fe1d8","type":"server","name":"Home Assistant New","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

A quick writeup:
Use the brightness of light #1 to synchronize to the same brightness, light #2

  • Notice I used a “state” node of the same light which was used for “trigger”. For some obscure reasons, this proved to be much more reliable.
  • Node one: your event state (leave as is)
  • Node two: current state node of the same entity. In here, put state location to “none”, and give a name of your choosing to entity location. In my example, it’s officebrightness
  • Node 3 is your call services for lights, turn on, with your second entity. Under “data”, add this JSON code
{"brightness":"{{officebrightness.attributes.brightness}}"}
  • Notice the first bit in red is the name of your choosing from the 2nd node - which was for me officebrightness
  • Voilà!

You can use this for any of the other attributes (color, etc) - and you only need to edit the last node for that.

What can you do with this?

  • Make several lights “follow suit” when a single one is turned on, or changed in brightness etc
  • Set remotely in room #1 its brightness based on a lamp in room #2 (grandpa screaming he wants more light)
  • in my case - I have an ikea light panel and ikea lightbulbs in the same room. Because the lightbulbls didn’t have a “color” capability, my ikea remote woudn’t work on all of them. So I just set the remove to the light panel, then using this code, I made the other lightbulbs the “minions” of that light panel.
  • Etc…