Combining two coloured light states to create a new one

I have two lamps either side of the TV, this is the ‘front’ of the room, I have another at the ‘back’ of the room. I want the lamp at the back to use the colour between the two at the front, e.g. if the front lamps are red and yellow, the one at the back will be orange-ish. All I think this requires is to take each of the the three RGB values, add them for each of the lamps at the front of the room and divide by two.

The tricky bit is extracting and transforming the RGB values as they are stored in an array, so require some kind of parsing perhaps? I have vanilla HA automation and Node Red at my disposal if anyone has any good ideas as to how to do this?

I suggest not to use RGB but Hue and saturation (hs).

See here how nicely they sit in the hs wheel?

So red has the hue value of 0 and the saturation of 100 (full saturation of color, 0 = white light).
Yellow has the hue value 60.
Orange is 30 hue.

So all you need to do is template the hue value as ((left + right)%360)/2 and saturation 100.

Thanks for this, that’s interesting, but looks like hs_color attribute is still stored as an array and that’s the bit I’m struggling to parse out to manipulate as you suggest…if I figure it out I will test this vs. Rgb.

service: light.turn_on
data:
  hs_color:
    - '{{ ((state_attr(''light.left'', ''hs_color'')[0] | int) + (state_attr(''light.right'', ''hs_color'')[0]| int) % 360) / 2 }}'
    - 100
target:
  entity_id: light.back