try this filterByFormula method
Also read this guide
Both. Using device id get the status, If the status is yes proceed further Else do the no process