Tuning halide perovskite energy levels