Controlling HVAC and lighting systems