Improve sensor histroy query