How to access the hostname of the machine running HA?

How can I access the hostname of the machine running 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.

Nothing? Nobody can help with this?

Anyone? Bueller?

I know the information exists, because in the Supervisor → System area, it shows the hostname and allows you to change it. Surely then, there’s an interface that allows access to it.

I don’t know the codebase of HA at all, so trying to navigate the source code feels like it’s beyond my abilities. Although…if someone could point me to the specific module that implements this (Supervisor → System), I could probably take it from there.

Any level of help would be appreciated!

Should this issue still be relevant, or for other people who are trying to accomplish this; put this in your configuration.yaml. Replace IP with your your IP address. Make sure that IP resolves to a hostname by putting it in your DNS, host file, or other method of DNS registration.
In this example I assume your local doman is .local

# Look up the hostname of this server
  - sensor:
      name: Hostname
      command: 'nslookup <IP> | sed -n -e "s/.*name = \(.*\)\.local\..*/\1/p"'