Rename unique ids for all entities of a specific device

Hi,

I would like to rename the unique_id for all entities of a specific device. E.g. in my Hue setup I have multiple Ceiling Lights (which is usually fine as they are grouped by room) and for automations and templating it’s hard to distinguish ceiling_light_1 from ceiling_light_17 and I would like to prefix them with the corresponding room names like bedroom_ceiling_light.

Long story short:
How can I do such bulk rename? Please give me all options (including raw database access, scripting and so on…).

What I tried so far:
I tried to rename Ceiling Light 1 to something else like Temp1 in the Frontend. A dialog pops up that asks about renaming related entities as well. Sadly there seems to be a bug. The entity friendly names get changed, but the unique ids do not.