Custom timed event entity state please help

Please edit your post and format your pasted code correctly. Point 11: How to help us help you - or How to ask a good question