Unexpected template behaviour wrt unique_id

I use command line sensors to get TFL train info.
TFL have recently split one line into five so I need five new sensors.

I have been using this successfully for years:

command_line:
  - sensor:
      name: Metropolitan Line
      unique_id: tfl_line_status_metropolitan
      command: >
        curl https://api.tfl.gov.uk/Line/metropolitan/Status?true 2> /dev/null
        | jq '{"name": .[].name, "lineStatuses": [.[].lineStatuses[] | {"description": .statusSeverityDescription, "reason": .reason}], "lineTypes": [.[].serviceTypes[] | {"name": .name}]}'
      value_template: *line_state
      json_attributes: *line_attributes
      command_timeout: 55

So it should be simple to add new lines using exactly the same format like this, right?
Wrong. :wink:

  - sensor:
      name: Mildmay Line
      unique_id: tfl_line_status_mildmay
      command: >
        curl https://api.tfl.gov.uk/Line/mildmay/Status?true 2> /dev/null 
        | jq '{"name": .[].name, "lineStatuses": [.[].lineStatuses[] | {"description": .statusSeverityDescription, "reason": .reason}], "lineTypes": [.[].serviceTypes[] | {"name": .name}]}'
      value_template: *line_state
      json_attributes: *line_attributes
      command_timeout: 55

The unexpected behaviour is that the original sensors create entities in HA with the ‘correct’ name/unique_id i.e.
sensor.tfl_line_status_[line_name]_line

Whereas the new sensors in identical format don’t.
sensor.[line_name]_line

What is going on here?
Thanks.

PS Note that as the entity_id is ‘wrong’ my customised entity_picture isn’t applied.

The sensor name of the new entity is correct. It’s derived from the name.
My guess is that you renamed the first one but forgot about it :wink:

I’m not sure I follow.
Those configs I posted are the configs I’m using with results shown in the screen shots.

Your gripe is that the new sensor entity_id is not sensor.tfl_line_status_mildmay, right?

That is expected.

The fact that the “old” sensor is named sensor.tfl_line_status_metropolitan is not, actually. It should be named sensor.metropolitan_line, based on its name.

So my guess is that you renamed the first one through the UI

Oh yes, I see. Sorry that was obvious.
And an entirely plausible possibility I guess.

Yes that is why I was so confused. It doesn’t feel like something I would have done; have complete control over a sensor’s creation and then rename it in the GUI.

But thanks for the answer and I’ll just rename the new ones and live with the uncertainty of my memory.
Like I said it was several years ago.

EDIT: just as I pressed save on this reply I remembered that even more years ago I used the built-in integration for these sensors but it didn’t keep up with changes to the Underground network or provide as much information as I could get using the api directly. So yes, probably the original sensors from the integration had the ‘correct’ name as you say.
Thanks again for the nudge.