Trying to create a hostname variable that is linked to an IP address variable

I have a variable that I use for promql queries called $device which is the devices IP address 1.1.1.1, 2.2.2.2, or 3.3.3.3. However, when I use Loki the logql query starts like this: host={“router1”}, so I cannot use the same variable $device. since I need to query the hostname “router1”. However, in my dashboards I would like the drop-down variable 1.1.1.1 to be “linked”, so when I click on 1.1.1.1 from the drop-down it automatically queries the hostname router1. I investigated chaining variables but I believe this just chains the dependent variable to the parent.

So far, I have 2 separate custom variables created:
$device with values of 1.1.1.1, 2.2.2.2, 3.3.3.3
$hostname with values of router1, router2, router3

I would recommend you to consider just adding IP to a label or structured metadata when forwarding logs from your devices.