Sharing state_topic in sensor with multiple entities

Brand new user to Home Assistant and i’ve run into a problem that i can quite seems to solve.

I have an mqtt sensor that looks like this:

sensor:
  - &watts_live
    device:
      name: Watts Live
      identifiers: 11D1045220005678
      manufacturer: Watts
      model: Watts Live
  - <<: *watts_live
    name: Positive Active Energy
    device_class: energy
    state_class: total
    unit_of_measurement: Wh
    value_template: "{{ value_json.positive_active_energy }}"
    state_topic: watts/SERIAL_NUMBER/measurement
    unique_id: positive_active_energy
  - <<: *watts_live
    name: Negative Active Energy
    device_class: energy
    state_class: total
    unit_of_measurement: Wh
    value_template: "{{ value_json.negative_active_energy }}"
    state_topic: watts/SERIAL_NUMBER/measurement
    unique_id: negative_active_energy
  - <<: *watts_live
    name: Positive Reactive Energy
    device_class: energy
    state_class: total
    unit_of_measurement: varh
    value_template: "{{ value_json.positive_reactive_energy }}"
    state_topic: watts/SERIAL_NUMBER/measurement
    unique_id: positive_reactive_energy
  - <<: *watts_live
    name: Negative Reactive Energy
    device_class: energy
    state_class: total
    unit_of_measurement: varh
    value_template: "{{ value_json.negative_reactive_energy }}"
    state_topic: watts/SERIAL_NUMBER/measurement
    unique_id: negative_reactive_energy
  - <<: *watts_live
    name: Positive Active Power
    device_class: power
    state_class: measurement
    unit_of_measurement: W
    value_template: "{{ value_json.positive_active_power }}"
    state_topic: watts/SERIAL_NUMBER/measurement
    unique_id: positive_active_power
  - <<: *watts_live
    name: Negative Active Power
    device_class: power
    state_class: measurement
    unit_of_measurement: W
    value_template: "{{ value_json.negative_active_power }}"
    state_topic: watts/SERIAL_NUMBER/measurement
    unique_id: negative_active_power
  - <<: *watts_live
    name: Positive Active Power L1
    device_class: power
    state_class: measurement
    unit_of_measurement: W
    value_template: "{{ value_json.positive_active_power_l1 }}"
    state_topic: watts/SERIAL_NUMBER/measurement
    unique_id: positive_active_power_l1
  - <<: *watts_live
    name: Positive Active Power L2
    device_class: power
    state_class: measurement
    unit_of_measurement: W
    value_template: "{{ value_json.positive_active_power_l2 }}"
    state_topic: watts/SERIAL_NUMBER/measurement
    unique_id: positive_active_power_l2
  - <<: *watts_live
    name: Positive Active Power L3
    device_class: power
    state_class: measurement
    unit_of_measurement: W
    value_template: "{{ value_json.positive_active_power_l3 }}"
    state_topic: watts/SERIAL_NUMBER/measurement
    unique_id: positive_active_power_l3
  - <<: *watts_live
    name: Negative Active Power L1
    device_class: power
    state_class: measurement
    unit_of_measurement: W
    value_template: "{{ value_json.negative_active_power_l1 }}"
    state_topic: watts/SERIAL_NUMBER/measurement
    unique_id: negative_active_power_l1
  - <<: *watts_live
    name: Negative Active Power L2
    device_class: power
    state_class: measurement
    unit_of_measurement: W
    value_template: "{{ value_json.negative_active_power_l2 }}"
    state_topic: watts/SERIAL_NUMBER/measurement
    unique_id: negative_active_power_l2
  - <<: *watts_live
    name: Negative Active Power L3
    device_class: power
    state_class: measurement
    unit_of_measurement: W
    value_template: "{{ value_json.negative_active_power_l3 }}"
    state_topic: watts/SERIAL_NUMBER/measurement
    unique_id: negative_active_power_l3
  - <<: *watts_live
    name: Positive Reactive Power
    device_class: reactive_power
    state_class: measurement
    unit_of_measurement: var
    value_template: "{{ value_json.positive_reactive_power }}"
    state_topic: watts/SERIAL_NUMBER/measurement
    unique_id: positive_reactive_power
  - <<: *watts_live
    name: Negative Reactive Power
    device_class: reactive_power
    state_class: measurement
    unit_of_measurement: var
    value_template: "{{ value_json.negative_reactive_power }}"
    state_topic: watts/SERIAL_NUMBER/measurement
    unique_id: negative_reactive_power
  - <<: *watts_live
    name: Voltage L1
    device_class: voltage
    state_class: measurement
    unit_of_measurement: V
    value_template: "{{ value_json.voltage_l1 }}"
    state_topic: watts/SERIAL_NUMBER/measurement
    unique_id: voltage_l1
  - <<: *watts_live
    name: Voltage L2
    device_class: voltage
    state_class: measurement
    unit_of_measurement: V
    value_template: "{{ value_json.voltage_l2 }}"
    state_topic: watts/SERIAL_NUMBER/measurement
    unique_id: voltage_l2
  - <<: *watts_live
    name: Voltage L3
    device_class: voltage
    state_class: measurement
    unit_of_measurement: V
    value_template: "{{ value_json.voltage_l3 }}"
    state_topic: watts/SERIAL_NUMBER/measurement
    unique_id: voltage_l3
  - <<: *watts_live
    name: Current L1
    device_class: current
    state_class: measurement
    unit_of_measurement: A
    value_template: "{{ value_json.current_l1 }}"
    state_topic: watts/SERIAL_NUMBER/measurement
    unique_id: current_l1
  - <<: *watts_live
    name: Current L2
    device_class: current
    state_class: measurement
    unit_of_measurement: A
    value_template: "{{ value_json.current_l2 }}"
    state_topic: watts/SERIAL_NUMBER/measurement
    unique_id: current_l2
  - <<: *watts_live
    name: Current L3
    device_class: current
    state_class: measurement
    unit_of_measurement: A
    value_template: "{{ value_json.current_l3 }}"
    state_topic: watts/SERIAL_NUMBER/measurement
    unique_id: current_l3

This configuration works perfectly. I get all my data and all is good, but i really would like to define the state_topic (which is identical for all entities) in &watts_live along with device instead of having to define it for each entity.

Problem is that if i move it into &watts_live, it does technically work, but i also get:

homeassistant.exceptions.InvalidStateError: Invalid state with length 524. State max length is 255 characters.

Because the MQTT payload is a JSON-object that contains all of the entities

How do i share the topic between all entities and not have Home Assistant complain?

Just had to shift things around a bit:

sensor:
  - name: Positive Active Energy
    device_class: energy
    state_class: total
    unit_of_measurement: Wh
    value_template: "{{ value_json.positive_active_energy }}"
    unique_id: positive_active_energy
    <<: &shared_attributes
      state_topic: "watts/SERIAL_NUMBER/measurement"
      device:
        name: Watts Live
        identifiers: SERIAL_NUMBER
        manufacturer: Watts
        model: Watts Live

  - name: Negative Active Energy
    device_class: energy
    state_class: total
    unit_of_measurement: Wh
    value_template: "{{ value_json.negative_active_energy }}"
    unique_id: negative_active_energy
    <<: *shared_attributes

  - name: Positive Reactive Energy
    device_class: energy
    state_class: total
    unit_of_measurement: varh
    value_template: "{{ value_json.positive_reactive_energy }}"
    unique_id: positive_reactive_energy
    <<: *shared_attributes

  - name: Negative Reactive Energy
    device_class: energy
    state_class: total
    unit_of_measurement: varh
    value_template: "{{ value_json.negative_reactive_energy }}"
    unique_id: negative_reactive_energy
    <<: *shared_attributes

  - name: Positive Active Power
    device_class: power
    state_class: measurement
    unit_of_measurement: W
    value_template: "{{ value_json.positive_active_power }}"
    unique_id: positive_active_power
    <<: *shared_attributes

  - name: Negative Active Power
    device_class: power
    state_class: measurement
    unit_of_measurement: W
    value_template: "{{ value_json.negative_active_power }}"
    unique_id: negative_active_power
    <<: *shared_attributes

  - name: Positive Active Power L1
    device_class: power
    state_class: measurement
    unit_of_measurement: W
    value_template: "{{ value_json.positive_active_power_l1 }}"
    unique_id: positive_active_power_l1
    <<: *shared_attributes

  - name: Positive Active Power L2
    device_class: power
    state_class: measurement
    unit_of_measurement: W
    value_template: "{{ value_json.positive_active_power_l2 }}"
    unique_id: positive_active_power_l2
    <<: *shared_attributes

  - name: Positive Active Power L3
    device_class: power
    state_class: measurement
    unit_of_measurement: W
    value_template: "{{ value_json.positive_active_power_l3 }}"
    unique_id: positive_active_power_l3
    <<: *shared_attributes

  - name: Negative Active Power L1
    device_class: power
    state_class: measurement
    unit_of_measurement: W
    value_template: "{{ value_json.negative_active_power_l1 }}"
    unique_id: negative_active_power_l1
    <<: *shared_attributes

  - name: Negative Active Power L2
    device_class: power
    state_class: measurement
    unit_of_measurement: W
    value_template: "{{ value_json.negative_active_power_l2 }}"
    unique_id: negative_active_power_l2
    <<: *shared_attributes

  - name: Negative Active Power L3
    device_class: power
    state_class: measurement
    unit_of_measurement: W
    value_template: "{{ value_json.negative_active_power_l3 }}"
    unique_id: negative_active_power_l3
    <<: *shared_attributes

  - name: Positive Reactive Power
    device_class: reactive_power
    state_class: measurement
    unit_of_measurement: var
    value_template: "{{ value_json.positive_reactive_power }}"
    unique_id: positive_reactive_power
    <<: *shared_attributes

  - name: Negative Reactive Power
    device_class: reactive_power
    state_class: measurement
    unit_of_measurement: var
    value_template: "{{ value_json.negative_reactive_power }}"
    unique_id: negative_reactive_power
    <<: *shared_attributes

  - name: Voltage L1
    device_class: voltage
    state_class: measurement
    unit_of_measurement: V
    value_template: "{{ value_json.voltage_l1 }}"
    unique_id: voltage_l1
    <<: *shared_attributes

  - name: Voltage L2
    device_class: voltage
    state_class: measurement
    unit_of_measurement: V
    value_template: "{{ value_json.voltage_l2 }}"
    unique_id: voltage_l2
    <<: *shared_attributes

  - name: Voltage L3
    device_class: voltage
    state_class: measurement
    unit_of_measurement: V
    value_template: "{{ value_json.voltage_l3 }}"
    unique_id: voltage_l3
    <<: *shared_attributes

  - name: Current L1
    device_class: current
    state_class: measurement
    unit_of_measurement: A
    value_template: "{{ value_json.current_l1 }}"
    unique_id: current_l1
    <<: *shared_attributes

  - name: Current L2
    device_class: current
    state_class: measurement
    unit_of_measurement: A
    value_template: "{{ value_json.current_l2 }}"
    unique_id: current_l2
    <<: *shared_attributes

  - name: Current L3
    device_class: current
    state_class: measurement
    unit_of_measurement: A
    value_template: "{{ value_json.current_l3 }}"
    unique_id: current_l3
    <<: *shared_attributes

:man_shrugging: