How to get a device name inside a rule

As mentioned above, the device variable refers to the trigger event. A conditional will never affect the value of this variable. Further, if the trigger is not a device, the value may not be very useful or set at all (in your case, it's a location/hub event, not a device event, and the value is apparently your hub name).

I haven't checked out the app mentioned above, but I also wrote an app to solve this problem for me. It is possible to do in a rule if you want to do it that way, too--it's just a lot of work and manual string concatenation. I have an example of a rule (from Rule 4.x, but it would still work more or less the same now) that this app replaced in the thread where I announced the app in case you want to explore either option: