First-principles investigation of divalent ion sensing with cesium lead trihalides