How to create a switch (on/off) on my flow

If the incoming messages are from a mqtt node. You could use dynamic subscription to subscribe and unsubsrcibe at will.
examples here Dynamic MQTT LWT birth, Close & Will Property - #2 by Steve-Mcl