I'm trying to send a short MP3 file to a Google Mini to play a custom sound. I use a static IP (assigned by my router) for my Hub: 192.168.1.61. The hub name on my LAN is "hubitat-c8p-house". I'm on a C-8 Pro, latest beta firmware.
I'd like to make the action use an invariant (alias) URL so that if I change the static IP of the hub to another value, I don't have to remember to update my rule.
This action works:
playTrack('http://192.168.1.61/local/beep-08b.mp3') on Speaker - Office GO
These 2 versions of that action do not work:
playTrack('http://127.0.0.1/local/beep-08b.mp3') on Speaker - Office GO
playTrack('http://hubitat-c8p-house/local/beep-08b.mp3') on Speaker - Office GO
I'd like to make the action use an invariant (alias) URL so that if I change the static IP of the hub to another value, I don't have to remember to update my rule.
That is the very definition of the purpose of a hostname. Simply use the name of target device, and let the router do mapping to an IP address, whether static or dynamic.
In general, I believe you’d do this with a DNS server that runs locally.
For example, I can browse to https://hubitatc7.lan because I’m using pi-hole running on a raspberry pi for DNS on my network.
From the pi-hole interface, I can map a hostname to an IP address. My router tells DHCP clients that DNS is provided by pi-hole. So anytime a client on the LAN asks for that hostname, it asks pi-hole, and pi-hole supplies the IP address.
All that would assume google minis will use a DHCP-assigned DNS server. Some IoT devices will ignore that and only reach out to a hardcoded DNS, like 8.8.8.8 (Google’s public DNS).
In the original poster's case, their router (providing hostname/IP info via DHCP) most likely is also acting as a DNS server, or can be configured as such.
If (when) DNS is active on the router, the address of the router should be the first DNS server provided by the router to DHCP clients. This means that queries by the Google Mini speaker for local hostnames (ie., hubitat-c8p-house) will result in local IP addresses (192.168.1.61) when it is given a URL (http://hubitat-c8p-house/local/beep-08b.mp3)