Call a service every minute when device is ON

I would like to ask for a little help.

I have a Xiaomi motion sensor which has timeout 90sec, after timeout state is OFF. If it detects motion state will be ON until no more motion is detected + timeout.

With this automation I wake up my iPad, but because of motion is registered only once I need to call other service every minute to keep my iPad screen ON.

- id: '1605108841343'
  alias: Motion Sensor Living Room - turn on iPad
  description: ''
  trigger:
  - type: motion
    platform: device
    device_id: bbf63cf89b29e5373385a6fe2bc53b67
    entity_id: binary_sensor.motion_sensor_living_room
    domain: binary_sensor
  condition: []
  action:
  - service: shell_command.unlock_ipad
    data: {}
  mode: single

How can I call another service (shell_command.touch_ipad) in every 60 seconds, when
my motion sensor (binary_sensor.motion_sensor_living_room) is ON? It is possible to combine the two or I need two automation?

Have a look at the while loop

Or just have an automation called every minute (time pattern) with a condition that your device is ‘on’

1 Like

I tried while loop, but it doesn’t work:

- id: '1605113349954'
  alias: Motion sensor Living Room keep iPad on
  description: ''
  trigger:
    platform: state
    entity_id: binary_sensor.motion_sensor_living_room
    to: 'on'
  mode: single
  action:
  - alias: Repeat the sequence UNTIL the conditions are true
    repeat:
      sequence:
        # Run command that for some reason doesn't always work
        - service: shell_command.touch_ipad
        # Give it time to complete
        - delay:
            minutes: 1
      until:
        # Did it work?
        - condition: state
          entity_id: binary_sensor.motion_sensor_living_room
          state: 'on'

At the end I did with Node Red and was very easy: