Automatically assigning colors to state timeline values

I have got a machine (in this case: Washing Machine). Different parts of this washing machine enter different states, let’s say the amount of different states are 40+. How can I automatically add colors to every unique state within the state timeline ?

When you do this manually you’ll first need to know all the state names and will take an awfully long while.

Does anyone have ideas?

Thanks in advance!!