# How to access the hostname of the machine running Home Assistant?

**URL:** <https://discourse.nodered.org/t/how-to-access-the-hostname-of-the-machine-running-home-assistant/47055>\
**Category:** General\
**Created:** [11 June 2021 23:59 UTC](https://discourse.nodered.org/t/how-to-access-the-hostname-of-the-machine-running-home-assistant/47055 "2021-06-11T23:59:19Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![steve2020](https://avatars.discourse-cdn.com/v4/letter/s/bbce88/32.png) [@steve2020](https://discourse.nodered.org/u/steve2020)\
**Post date:** [11 June 2021 23:59 UTC](https://discourse.nodered.org/t/how-to-access-the-hostname-of-the-machine-running-home-assistant/47055/1 "2021-06-11T23:59:19Z")

</div>

How can I access the hostname of the machine running Home Assistant from within HA? I have a dashboard showing the status of all the computers on my network, so I’d like to have my HA host provide the hostname via MQTT. Ideally, I’d like to access the hostname through the HA Node-RED installation.

I wasn’t able to find any kind of built-in support for this (nothing in System Monitor, for example), so I tried using a Node-RED exec node to execute the “hostname” command; unfortunately the result is just the name of the Docker container, which isn’t terribly helpful in this situation.

I tried posting this in the HA forums (twice, even), but haven't gotten any responses. I know the information is there -- a recent addition to the Supervisor allows changing the hostname from the UI.

Any help or guidance would be appreciated.

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [12 June 2021 04:52 UTC](https://discourse.nodered.org/t/how-to-access-the-hostname-of-the-machine-running-home-assistant/47055/2 "2021-06-12T04:52:05Z")

</div>

You cannot access the system from within the docker container. You can specify `docker run --hostname myhostname` when creating the container, after which you can use the exec node with `hostname` within the container.

---

<div class="post-metadata">

**Author:** ![H3llsing](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/h3llsing/32/40624_2.png) [@H3llsing](https://discourse.nodered.org/u/H3llsing)\
**Post date:** [12 June 2021 04:58 UTC](https://discourse.nodered.org/t/how-to-access-the-hostname-of-the-machine-running-home-assistant/47055/3 "2021-06-12T04:58:25Z")

</div>

Normally i would say you should locate your settings.js file and add to the functionGlobalContext to the os module.  
After this you can use it in a function node.  
But not sure if this works inside docker.

**Edit:**  
-\> its only giving the container hostname. Not the one from the underlaying os.  
But to complete this snippet here-\> you have to locate in **hassio** the **/config/node-red/settings.js** file and search for

```auto
functionGlobalContext: {
    os:require('os'),
    // jfive:require("johnny-five"),
    // j5board:require("johnny-five").Board({repl:false})
  },

```

just comment in the first line with os and restart the container.  
then you could drop a function node and write

```auto
var os=global.get('os')
msg.payload = os.hostname()
return msg

```

---

<div class="post-metadata">

**Author:** ![steve2020](https://avatars.discourse-cdn.com/v4/letter/s/bbce88/32.png) [@steve2020](https://discourse.nodered.org/u/steve2020)\
**Post date:** [12 June 2021 05:11 UTC](https://discourse.nodered.org/t/how-to-access-the-hostname-of-the-machine-running-home-assistant/47055/4 "2021-06-12T05:11:29Z")

</div>

Thanks for the responses. Getting the hostname is no problem at all in NR _without_ Docker: just use an `exec` node and run the `hostname` command. And I know that Docker is designed not to provide access to its host system; this is why I I'm hoping there is a mechanism provided by Home Asst that would expose the information. It's looking like that might not be the case. SOMEBODY out there knows 100% for sure (even if the answer is no), since HA only just started providing facilities for changing the hostname from within the HA user interface. 🙂

---

<div class="post-metadata">

**Author:** ![steve2020](https://avatars.discourse-cdn.com/v4/letter/s/bbce88/32.png) [@steve2020](https://discourse.nodered.org/u/steve2020)\
**Post date:** [12 June 2021 05:13 UTC](https://discourse.nodered.org/t/how-to-access-the-hostname-of-the-machine-running-home-assistant/47055/5 "2021-06-12T05:13:00Z")

</div>

I'm not quite sure how to go about doing that, but I will give it a try. Thanks!

---

<div class="post-metadata">

**Author:** ![EmilWesselink](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/emilwesselink/32/65829_2.png) [@EmilWesselink](https://discourse.nodered.org/u/EmilWesselink)\
**Post date:** [12 June 2021 06:24 UTC](https://discourse.nodered.org/t/how-to-access-the-hostname-of-the-machine-running-home-assistant/47055/6 "2021-06-12T06:24:55Z")

</div>

I have fixed this with s little ugly hack: If you are running the HA container on a Linux system, mount /etc as a read only volume as /hostetc, Now you can access the file /hostetc/hostname within the container.

Good luck

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [12 June 2021 06:26 UTC](https://discourse.nodered.org/t/how-to-access-the-hostname-of-the-machine-running-home-assistant/47055/7 "2021-06-12T06:26:52Z")

</div>

See my reply - set the hostname of the container and then you can request it.

---

<div class="post-metadata">

**Author:** ![steve2020](https://avatars.discourse-cdn.com/v4/letter/s/bbce88/32.png) [@steve2020](https://discourse.nodered.org/u/steve2020)\
**Post date:** [12 June 2021 07:50 UTC](https://discourse.nodered.org/t/how-to-access-the-hostname-of-the-machine-running-home-assistant/47055/8 "2021-06-12T07:50:39Z")

</div>

I did see that, @bakman2 , and thanks for the tip -- I can see that that will work. In a practical sense, I don't really have full access to Home Assistant's containers, and creating a new one would take more time and computational resources than I'm willing to put in for such a small bit of information (I'm not particularly facile with Docker). Mostly right now I want to know if HA exposes that information somewhere...if not, I'll stop looking 😃

For the time being, my workaround is just to hard-code the hostname and graft it onto all outgoing MQTT requests -- took all of two minutes to put into place. That will tide me over until there's a more "official" solution.

---

<div class="post-metadata">

**Author:** ![steve2020](https://avatars.discourse-cdn.com/v4/letter/s/bbce88/32.png) [@steve2020](https://discourse.nodered.org/u/steve2020)\
**Post date:** [12 June 2021 08:39 UTC](https://discourse.nodered.org/t/how-to-access-the-hostname-of-the-machine-running-home-assistant/47055/9 "2021-06-12T08:39:06Z")

</div>

I'm running HA as HassOS on a dedicated Raspberry Pi, not as a separate container on an existing system. HA doesn't really want you messing with the main containers, which is where I would need to have access to the hostname.

---

<div class="post-metadata">

**Author:** ![H3llsing](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/h3llsing/32/40624_2.png) [@H3llsing](https://discourse.nodered.org/u/H3llsing)\
**Post date:** [13 June 2021 22:32 UTC](https://discourse.nodered.org/t/how-to-access-the-hostname-of-the-machine-running-home-assistant/47055/10 "2021-06-13T22:32:03Z")

</div>

in the sources of hassio they make an api call to show the hostname info from the supervisor tab.

> <https://github.com/home-assistant/frontend/blob/6b10eeb1e91542bf299988968c03acb9f16ca8b8/hassio/src/system/hassio-host-info.js#L128>

Maybe you could make an API call with one of the hassio nodes or with a simple http-request node.

---

<div class="post-metadata">

**Author:** ![steve2020](https://avatars.discourse-cdn.com/v4/letter/s/bbce88/32.png) [@steve2020](https://discourse.nodered.org/u/steve2020)\
**Post date:** [14 June 2021 01:46 UTC](https://discourse.nodered.org/t/how-to-access-the-hostname-of-the-machine-running-home-assistant/47055/11 "2021-06-14T01:46:45Z")

</div>

@H3llsing -- Amazing....I wouldn't have been able to hone in on that in a hundred years...thanks so much! This is definitely more of the approach that I'm looking for, since it exposes the information from within Home Asst. I'll see what I can dig up now.

---

<div class="post-metadata">

**Author:** ![Jean-Luc](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jean-luc/32/89996_2.png) [@Jean-Luc](https://discourse.nodered.org/u/Jean-Luc)\
**Post date:** [16 June 2021 19:43 UTC](https://discourse.nodered.org/t/how-to-access-the-hostname-of-the-machine-running-home-assistant/47055/12 "2021-06-16T19:43:50Z")

</div>

Hello steve2020  
For my part, I had solved this problem in this [way](https://discourse.nodered.org/t/issue-commands-from-a-docker-container-on-the-host-where-it-run/46492). Maybe you are interested.  
Well it's to get the IP address of the host, but same idea to get the name of the host

---

<div class="post-metadata">

**Author:** ![H3llsing](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/h3llsing/32/40624_2.png) [@H3llsing](https://discourse.nodered.org/u/H3llsing)\
**Post date:** [25 June 2021 16:19 UTC](https://discourse.nodered.org/t/how-to-access-the-hostname-of-the-machine-running-home-assistant/47055/13 "2021-06-25T16:19:21Z")

</div>

@steve2020 is it working like you were expecting ?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [24 August 2021 16:19 UTC](https://discourse.nodered.org/t/how-to-access-the-hostname-of-the-machine-running-home-assistant/47055/14 "2021-08-24T16:19:37Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
