and the excessive calls to hue hub have been removed
loads of database stuff, schedules are now dumped upon calculation
updated sql to reflect current situation