Creating a function to modify multiple badges styles

So I have a bunch of smart radiator valves plotted on a picture-element and I have a bunch of conditional styling so that it displays according to various entities on that device

type: picture-elements
elements:
  - type: state-badge
    entity: sensor.kitchen_1_current_temperature
    card_mod:
      style: |
        :host {
          --label-badge-text-color: {% if states('sensor.kitchen_1_state') == 'ON' %} black {% else %} white {% endif %};
          --label-badge-background-color: {% if states('sensor.kitchen_1_state') == 'ON' %} orange {% else %} black {% endif %};
          --label-badge-red: {% if states('sensor.kitchen_1_boost') == 'ON' %} #db3f0f {% elif states('sensor.kitchen_1_mode') == 'SCHEDULE' %} #db830f {% else %} #888888 {% endif %};
          }
    style:
      top: 70%
      left: 60%
      color: transparent
... more devices

So I want to know if theres a way I can create a function to set the logic in one place, and then pass in the device name so it will automatically figure out the entities and remove the need for duplicating this.

Is this even possible? If so can anyone point me in the right direction?