Create sensor for automatic contrasting color?

Would there be an easy way to create a sensor that auto sets a color to the outcome of another sensors state, being a color.

As it stands, I have a presence sensor that sets a corresponding color:
[‘grey’,‘steelblue’,‘saddlebrown’,‘gold’,‘darkorange’,‘red’,‘green’] for 0 to 6 persons presence. I use this in a notification field on a button for the background.

styles:
  icon:
    - color: >
        [[[ return states['sensor.family_home'].attributes.icon_color; ]]]
  custom_fields:
    notification:
      - background-color: >
          [[[ return states['sensor.family_home'].attributes.icon_color; ]]]
      - color: white

Other than having a fixed color black or white I can use now, Id love it to create an automatic contrasting color. Either in the js of the button code, or use another template sensor.
thanks for having a look

update

resorting to this go-between for now:

type: custom:button-card
template: button_summary
entity: sensor.family_home
variables:
  color: >
    [[[ return states['sensor.family_home'].attributes.icon_color; ]]]
name: Home
hold_action:
  action: navigate
  navigation_path: /ui-data/phones_tablets
icon: >
  [[[ return states['sensor.presence_icon'].state; ]]]
styles:
  icon:
    - color: >
        [[[ return variables.color; ]]]
  custom_fields:
    notification:
      - background-color: >
          [[[ return variables.color; ]]]
      - color: >
          [[[ return variables.color  = 'gold' ? 'saddlebrown' : 'ivory'; ]]]