Toggle doesn’t take other commands into account

Toggle light - light comes on
Toggle light - light goes off
Toggle light - light goes on
Set brightness to zero - light goes off

Toggle light
Expected: light goes on
Actual: light stays off and another toggle is required to bring it on.

Is this a Rule Machine rule? It would be helpful to state what app you are using.

In any case, "toggle" isn't a built-in command for any standard device/driver capability; it's an app-level feature provided as an action by certain apps, Rule Machine being one (hence my guess). To do this, all it does should be: look at the current switch state, send an "on" command if it's off, or send an "off" command if it's on. Therefore, the problem you're encountering is likely that your device just isn't reporting its "switch" state correctly, apparently only after a "Set Level" to 0, rather than anything specific to the app you're using.

You should be able to replicate this behavior by manually sending the same commands from the device detail page. You can verify my suspicion of the underlying problem by looking at the value of the "switch" attribute under "Current States" in the top right of the page. You'll likely see it update correctly in every case except when you do a "Set Level" to 0, based on your description.

Zero is somewhat of an odd choice for "Set Level." Most drivers treat it as equivalent to "Off," but sometimes you'll run into oddities. You can likely avoid this behavior by just using an "Off" instead. Is there a reason you can't do that instead?

Otherwise, looking into this problem (which is still weird and might be able to be fixed...) would involve knowing more about your setup, like what device this is (manufacturer and model) and what driver you are using.

Toggle - light on
Set brightness to zero - light is still technically on.. just with a brightness of zero.
Toggle - now we are actually turning the light off
Toggle - Light is back on (second toggle in your example)

I think what you want to do is adjust the brightness back to the "on" level.