Exclude other automations while one specific is running

Hey all, so as the topic states, im looking for a simple way to exclude other automations to run or at least don’t mess with the important one while one specific automation is running. In my case I need the iRobot automation to have the light on, and then them to be turned off when he docks, what works flawlessly, but the problem is, that there are other automations that get triggered, for example the movement sensor light on and off, and that messes with the iRobot automation witch results in lights being of at the end…

https://dpaste.org/fvJRy

UPDATE:

The idea on its own wasn’t working here, but since its like exactly the same topic, im just updating it…

Looking for a template for → If the iRobot Script isn’t working, when a movement is detected and the Brightness is below 50 lux turn on the light, if there has been no movement for 20 sec, and the robot script isn’t running, turn off the light

iRobot script: irobot_with_automatic_lights
Light entity: switch.0x54ef4410003b3633
Movement detection entity: binary_sensor.motion_sensor_storage_room_occupancy
Brightness Entity: sensor.motion_sensor_storage_room_illuminance_lux

Since you didn’t post the “iRobot automation” I’m going to assume that the automation triggers then performs the action and finishes with no built-in delays.

If that’s the case then you could put a condition in your other automations that checks the state of the iRobot and if it’s in a “running” state (whatever that is since I don’t use one) to prevent the other unwanted automations from running during that time.

I did put in the iRobot automation, it’s the first thing there, it’s just a simple clock automation, the only thing it does is start the script ( second thing ) each day at 18:00. And the idea sounds good but kinda wouldn’t work, one of the automations will be powering off all lights when last person leaves home, but at the same time, iRobot lights should stay on…

Sorry, I didn’t click the link.

I’m trying to understand this…

you want the lights off after the vacuum docks. But you don’t want the lights to be turned off during the vacuum cycle by motion detectors sensing no motion. Is that correct?

if so then (based on the automations you provided in the link) add a condition to the “Movement Sensor Off” automation to have the vacuum docked in order for it to run and turn off the lights.

You don’t show that one in the link but why couldn’t you put in the same vacuum condition for that automation too?

the kinda problem is, I would have to do it with almost each automation later on also, can I just create a new thing / rule / automation that says, the robot script is the king, don’t mess with him while he’s running ?.. instead of correcting each automation that could run in the same time as the irobot one ?

Sorry, no that’s not possible.

each automation is it’s own thing and it relies on the triggers and conditions defined within it to control it’s behavior.

1 Like

Oh now that’s a bummer… ok, then ill just rephrase my question on top, could you be able to help here now ?..

Is there a reason you can’t just turn off the light automation when the script is running?

The reason could be I’m really new to all this and I just don’t know how :smiley: that’s why I’m asking for a template / blueprint here…

automation.turn_off is a service you can call so add that to the beginning of the script and turn it back on again when it is finished.

I already did in post 2 above but i’ll make it more specific.

Using your existing “movement off” automation in your link just add the condition:

- id: '1655769740983'
  alias: Storage Room Motion Light Off
  description: ''
  trigger:
  - type: no_motion
    platform: device
    device_id: a7c16b625014e54702a0eb60f899c17b
    entity_id: binary_sensor.motion_sensor_storage_room_occupancy
    domain: binary_sensor
    for:
      hours: 0
      minutes: 0
      seconds: 3
  condition:
    - condition: state
      entity_id: vacuum.darth_vader
      state: docked ## <--this is the part I'm not sure about since i don't have one to know the state required
  action:
  - type: turn_off
    device_id: 1b063fe6b9f5a6f80e4a64227a8056ce
    entity_id: switch.0x54ef4410003b3633
    domain: switch
  mode: single

in the above the automation to turn off the lights won’t run unless the robot is docked.

While it is possible to do that it’s usually not the best practice because you could get into a state that you aren’t sure if the automations are on or off and it makes troubleshooting those non-running automations more difficult. “is the automation not running because of the trigger or condition not being met or did I completely forget that I turned the automation off last week?” (yes speaking from experience here… :man_facepalming:)

Makes sense and seems to be good for my case but what about the brightness part there ? :slight_smile: and do I need to use both device ID and entity ID in such an automation ? :slight_smile:

I’m sorry I do t see anything about brightness. Unless I’m missing that too somewhere. :slightly_smiling_face:

Not unless you create it with the UI then it will get included automatically. If you write it in yaml then you won’t need the device id.

good to know, and I’ve updated the original post, there is a big UPDATE: written there now and the news are under the UPDATE: :slight_smile:

That’s how far I’ve gotten, the problem now is That the light isn’t turning off…

- id: '1657057535125'
  alias: storage room
  description: ''
  trigger:
  - type: motion
    platform: device
    device_id: a7c16b625014e54702a0eb60f899c17b
    entity_id: binary_sensor.motion_sensor_storage_room_occupancy
    domain: binary_sensor
  condition:
  - condition: device
    device_id: f90f35f2e71552c358118c5f0350673f
    domain: vacuum
    entity_id: vacuum.darth_vader
    type: is_docked
  - type: is_illuminance
    condition: device
    device_id: a7c16b625014e54702a0eb60f899c17b
    entity_id: sensor.motion_sensor_storage_room_illuminance_lux
    domain: sensor
    below: 10
  - condition: state
    entity_id: group.device_tracker
    state: home
  action:
  - type: turn_on
    device_id: 1b063fe6b9f5a6f80e4a64227a8056ce
    entity_id: switch.0x54ef4410003b3633
    domain: switch
  - if:
    - type: is_no_motion
      condition: device
      device_id: a7c16b625014e54702a0eb60f899c17b
      entity_id: binary_sensor.motion_sensor_storage_room_occupancy
      domain: binary_sensor
      for:
        hours: 0
        minutes: 0
        seconds: 10
    then:
    - type: turn_off
      device_id: 1b063fe6b9f5a6f80e4a64227a8056ce
      entity_id: switch.0x54ef4410003b3633
      domain: switch
  mode: single

The problem is that you are only triggering the automation once on motion detected.

The way you have it now the sequence is:

  • motion detected
  • check conditions
  • if conditions are all true
    • turn on the light
    • ** check to see if there was no motion detected for more than 10 seconds
    • if no motion for 10 seconds then turn off the light.

the problem is in the ** portion.

you triggered the automation by motion detected so that no motion for 10 seconds section fails immediately. So the light doesn’t get turned off.

you can solve it by creating a second automation to turn the light off or you can use a wait_for_trigger instead of the if/then construct.

that way it will wait for the no motion for 10 seconds to occur then turn off the light.

The one big issue with the wait_for_trigger is that if the trigger takes a long to time to happen (continuous motion for a long time) and automations get reloaded then the automation gets reset and the light never turns off then either.

if that is acceptable then this should work (I wrote the change in yaml since I never use the UI):

action:
  - type: turn_on
    device_id: 1b063fe6b9f5a6f80e4a64227a8056ce
    entity_id: switch.0x54ef4410003b3633
    domain: switch
  - wait_for_trigger:
    - platform: state
      entity_id: binary_sensor.motion_sensor_storage_room_occupancy
      to: 'off'
      for:
        hours: 0
        minutes: 0
        seconds: 10
  - type: turn_off
    device_id: 1b063fe6b9f5a6f80e4a64227a8056ce
    entity_id: switch.0x54ef4410003b3633
    domain: switch

It takes like a minute to turn off…

alias: Storage Room Light On TRYOUTS
description: ''
trigger:
  - type: motion
    platform: device
    device_id: a7c16b625014e54702a0eb60f899c17b
    entity_id: binary_sensor.motion_sensor_storage_room_occupancy
    domain: binary_sensor
condition: []
action:
  - type: turn_on
    device_id: 1b063fe6b9f5a6f80e4a64227a8056ce
    entity_id: switch.0x54ef4410003b3633
    domain: switch
  - wait_for_trigger:
      - type: no_motion
        platform: device
        device_id: a7c16b625014e54702a0eb60f899c17b
        entity_id: binary_sensor.motion_sensor_storage_room_occupancy
        domain: binary_sensor
        for:
          hours: 0
          minutes: 0
          seconds: 10
    continue_on_timeout: false
  - condition: state
    entity_id: vacuum.darth_vader
    state: docked
  - type: turn_off
    device_id: 1b063fe6b9f5a6f80e4a64227a8056ce
    entity_id: switch.0x54ef4410003b3633
    domain: switch
mode: single