# Change Balena device name on open-balena

**URL:** <https://forums.balena.io/t/change-balena-device-name-on-open-balena/215216>\
**Category:** openBalena\
**Created:** [November 23, 2020, 10:14pm UTC](https://forums.balena.io/t/change-balena-device-name-on-open-balena/215216 "2020-11-23T22:14:38Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![l.tiesong](https://avatars.discourse-cdn.com/v4/letter/l/5f8ce5/32.png) [@l.tiesong](https://forums.balena.io/u/l.tiesong)\
**Post date:** [November 23, 2020, 10:14pm UTC](https://forums.balena.io/t/change-balena-device-name-on-open-balena/215216/1 "2020-11-23T22:14:38Z")

</div>

Hi,  
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.

Regards,

---

<div class="post-metadata">

**Author:** ![karaxuna](https://avatars.discourse-cdn.com/v4/letter/k/e480ec/32.png) [@karaxuna](https://forums.balena.io/u/karaxuna)\
**Post date:** [November 24, 2020, 9:07am UTC](https://forums.balena.io/t/change-balena-device-name-on-open-balena/215216/2 "2020-11-24T09:07:34Z")

</div>

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: [https://www.balena.io/docs/reference/supervisor/supervisor-api/#device-name](https://www.balena.io/docs/reference/supervisor/supervisor-api/#device-name)

---

<div class="post-metadata">

**Author:** ![g.corrigan](https://avatars.discourse-cdn.com/v4/letter/g/46a35a/32.png) [@g.corrigan](https://forums.balena.io/u/g.corrigan)\
**Post date:** [November 25, 2020, 7:28pm UTC](https://forums.balena.io/t/change-balena-device-name-on-open-balena/215216/4 "2020-11-25T19:28:09Z")

</div>

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_INIT`as 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.

---

<div class="post-metadata">

**Author:** ![pipex](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/pipex/32/4840_2.png) [@pipex](https://forums.balena.io/u/pipex)\
**Post date:** [November 25, 2020, 7:49pm UTC](https://forums.balena.io/t/change-balena-device-name-on-open-balena/215216/5 "2020-11-25T19:49:40Z")

</div>

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

> **[Environment and service variables - Balena Documentation](https://www.balena.io/docs/learn/manage/serv-vars/#environment-and-service-variables)**

  

> **[Resources - Balena Documentation](https://www.balena.io/docs/reference/api/resources/device_environment_variable/)**

---

<div class="post-metadata">

**Author:** ![g.corrigan](https://avatars.discourse-cdn.com/v4/letter/g/46a35a/32.png) [@g.corrigan](https://forums.balena.io/u/g.corrigan)\
**Post date:** [November 25, 2020, 8:09pm UTC](https://forums.balena.io/t/change-balena-device-name-on-open-balena/215216/7 "2020-11-25T20:09:28Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![pipex](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/pipex/32/4840_2.png) [@pipex](https://forums.balena.io/u/pipex)\
**Post date:** [November 25, 2020, 9:01pm UTC](https://forums.balena.io/t/change-balena-device-name-on-open-balena/215216/8 "2020-11-25T21:01:33Z")

</div>

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.

Cheers  
Felipe

---

<div class="post-metadata">

**Author:** ![g.corrigan](https://avatars.discourse-cdn.com/v4/letter/g/46a35a/32.png) [@g.corrigan](https://forums.balena.io/u/g.corrigan)\
**Post date:** [November 26, 2020, 9:50am UTC](https://forums.balena.io/t/change-balena-device-name-on-open-balena/215216/10 "2020-11-26T09:50:03Z")

</div>

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

Gerard.
