Switch or binary sensor that returns the status of a command

Hello, I am in the process of migrating from openHAB to HA. I have used the EXEC binding in OH to execute SSH commands, which it returns me the status of a command as a switch.
So when I set the switch to “ON”, it stays “ON” until the command is executed and then automatically goes back to “OFF”.
I use this for example to do monthly automatic updates on my Raspi cluster.

I have autmatized this according to the following setup in OH:

  • 9PM start trigger
  • “Command Switch” "ON
  • wait for execution
  • “Command Switch” goes to “OFF” again
  • If “OFF”, set the next switch to “ON”.
  • etc.

And now to my actual question, how can I create a switch or binary sensor in HA that detects the status of the command and automatically goes back to “OFF” when the command is executed?
I have tried different solutions… Command Line Switch, Command Line Binary Sensor, Buttons and Autmatizations… but none of them let me conclude how to get the status of the SSH command back automatically.

Maybe I just can’t see the forest for the trees? Or I think too complicated and have lost the overview.

By the way, the command that is executed looks like this:ssh MyName@MyHost sudo apt update && sudo apt upgrade -y.t

Can anyone help me back out of the woods?