Repeat action until sensor shows "on"

I am creating a script to run through the sources on the stereo in my boat (because there are no discrete remote codes to go directly to AUX or DAB, which are the sources I actually use). The only thing I can use is that I know when the stereo is on CD because I have soldered a cable to the plus on the motor that spins the CD’s and I have a CD with a file of burnt silence in the slot. So when I get to that source, the motor goes from 3,5V to 6V and then stabilizes around 4,5V, which I have used a voltage divider (with two 100K ohm resistors) to get within the ESP32’s range. So when the power is below 2V the binary sensor with analog threshold is “off”, and when it’s above 2V it is “on”.

So the logic is that I send a source switch:

  - platform: template
    name: "IR: Change source"
      - remote_transmitter.transmit_pioneer:
          rc_code_1: 0xB51A

And then I want to wait for half a second to see if the CD motor sensor goes from “off” to “on”. If not, another switch and another pause, and so on. When the motor sensor is found to be “on” after half a second I will then send the number of source changes necessary to go to the DAB (one) or the AUX (three, because it has to go past both DAB and FM). I can of course to this in a very elaborate if then script, but is there a way to loop the check script until the sensor goes from “off” to “on”?

You can use the while Action to loop until condition is met.


Brilliant, thanks a lot! :+1: I didn’t find that one while looking at the documentation!