Maybe this can help, it a bit different from what you asked cause this one writes room data to the ceilings but the most important logic is there