Change Balena device name on open-balena

I’d like to change BALENA_DEVICE_NAME_AT_INIT env variable.
I used balena device rename command to change device name.
It successfully updated the device name but if I check BALENA_DEVICE_NAME_AT_INIT on the device , it is not updated.
I restarted the both container and the device but it was still using an old name.
Please let me know how to update BALENA_DEVICE_NAME_AT_INIT correctly.


Hi, can you tell us your use case? BALENA_DEVICE_NAME_AT_INIT is the name of the device on first initialization, so it’s not supposed to change. You can use supervisor api to get current device name:

Hi @karaxuna , the use case for this is that we have a SaaS application where users can create applications to deploy to their edge devices. When the device come online in openBalena and therefore the saas app they have the device name = BALENA_DEVICE_NAME_AT_INIT but these are meaningless to the user.
The user will rename the device in the sass application to a meaningfull name and we need to use the API to make the change in openBalena and on the device.
We use the BALENA_DEVICE_NAME_AT_INITas tag for all MQTT message coming from the device to the cloud so we need to ensure the that is set to the new device name.

Hi Gerard,

Have you explored using service or environment variables to achieve this? You could have the renaming action set the new name as an environment variable in the API and this will have the effect of making the variable available for the services in your application which is probably what you want.

The device name is not something we currently expose to containers and modifying the this value on the cloud does not have any effect on the device configuration.

Here are some resources on environment and service variables

1 Like

Hi @pipex, we were using BALENA_DEVICE_NAME_AT_INIT and this was working well until we ran into this problem of the user needing to rename their devices.

I can see in the docs ’ for any given variable, the device service variable will always have top priority’ could we create a service variable for Telegraf also called BALENA_DEVICE_NAME_AT_INIT or is that not allow since it is a config variable?

Otherwise we may need to just create new variable that we use for device name and set it to equal the BALENA_DEVICE_NAME_AT_INIT intially and then change it when the user changes the name in saas app.

No, unfortunately you won’t be able to create a service variable with that name, because names starting with BALENA_ are reserved for configuration variables.

As you say, creating a new variable with the value of BALENA_DEVICE_NAME_AT_INIT and changing it when the user changes the name is probably the best option. It will also have the advantage of having the new value propagate immediately to the device after the change.

Please let us know how that works for you.


Hi @pipex, we did some testing and this works for our use case. Thanks for your help.