JS template to split on first of multiple '_'

using a lot of buttons, Id like to use a template to not have to create hardcoded names for all of these buttons…

all of my counter sensors have the an entity_id like this:

sensor.count_input_selects, sensor.count_groups, sensor.count_input_booleans etc etc.

I want to do the name template like this:

      - type: custom:button-card
        template: button_body_no_action
        entity: sensor.count_input_selects
        name: >
          [[[ return entity.entity_id.split('_')[1] ]]]

but completely forgot how to split but not leave the second section after a second _ out…

of course id need to capitalize the first capital, but thats easy :wink:

    [[[
    function capitalizeFirstLetter(string) {
    return string.charAt(0).toUpperCase() + string.slice(1).toLowerCase();
    }
    var id = entity.entity_id.split('.')[1].slice(6);
    return capitalizeFirstLetter(id);
    ]]]

above could also be a valid method, but this is for another type of sensors.
Please help me with my brain-flush…
thanks

I think you want:

entity.entity_id.split('_', 1)[1]

thanks, but that renders nothing:
50
while my slice(6) method does this
16

must of course also replace the _ with a space,

      - type: custom:button-card
        template: button_body_no_action
        entity: sensor.count_input_selects
        name: >
          [[[
          function capitalizeFirstLetter(string) {
          return string.charAt(0).toUpperCase() + string.slice(1).toLowerCase();
          }
          var id = entity.entity_id.split('.')[1].slice(6).replace('_',' ');
          return capitalizeFirstLetter(id);
          ]]]

but first need to get this right…

Ok, never mind. I missed you’re talking about JavaScript.