The system.device.setDeviceHostname
function just changes the IP of a device, so it won't work with the Siemens 400H, where you have different rack between the master and the slave (one is rack 0, the other is rack 1, and there's no function in Ignition to change that property at runtime).
Check this post for a solution:
Redundancy configuration for Siemens 400 PLC
Be careful, if I remember correctly there are cases where both devices (rack 0 and rack 1, independently on who is master) will be connected, but only the master will give you the running values. To handle this cases, you should read a always changing tag (i.e. PLC datetime seconds) on both devices: the master is the one with the tag that changes value.