I could not add image
You can try do something like this:
Select machinestate,
Lead(machinestate,1) OVER (PARTITION BY machinename ORDER BY time) as
next_machinestate,
Lead(time,1) OVER (PARTITION BY machinename ORDER BY time) - time as
time_range
from your_table