Automation broken

Hey guys. I have had this automation for a while and a couple of days ago it has stopped working as intended. Can anyone shed some light as to why it isn’t working? The only part that isn’t functioning is the turning off when the sensor is clear for 2 mins

Alias: "theatre room light on "
description: ""
triggers:
  - trigger: state
    entity_id:
      - binary_sensor.dining_room_motion_sensor_occupancy_5
    to:
      - "on"
conditions:
  - condition: device
    type: is_off
    device_id: b23886dff56f1d14f8e76089887c26b0
    entity_id: 69926941889662a3038aab0ba375abfd
    domain: remote
  - condition: and
    conditions:
      - condition: time
        after: "06:30:00"
        before: "23:00:00"
actions:
  - action: light.turn_on
    metadata: {}
    target:
      device_id: ba8836d33c7a74e6fbbeb3dc3aaaef83
    data:
      transition: 2
      brightness_pct: 100
  - condition: not
    conditions:
      - condition: state
        state:
          - com.google.android.youtube.tv
        entity_id: media_player.theatre_room_tv
  - wait_for_trigger:
      - trigger: state
        entity_id:
          - binary_sensor.dining_room_motion_sensor_occupancy_5
        to:
          - "off"
        for:
          hours: 0
          minutes: 2
          seconds: 0
  - action: light.turn_off
    metadata: {}
    target:
      device_id: ba8836d33c7a74e6fbbeb3dc3aaaef83
    data:
      transition: 1
mode: single

Please edit your post and format it correctly. Don’t use the quote button. Use the </> button (sometimes in settings/cog icon menu on small screens). Or do this: https://community.home-assistant.io/t/how-to-help-us-help-you-or-how-to-ask-a-good-question/114371#oneone-format-it-properly-16

thank you. i was on my phone and couldnt do it lol

You should avoid using device automations. See: Why and how to avoid device_ids in automations and scripts

You should avoid waiting in automations. It’s too easy to interrupt them, leading to unpredictable results. Try two triggers and a choose action instead.

Your conditions are not quite correct. You have an AND block with only one condition in it. You don’t need this. Conditions are AND by default. Also your conditions seem to only allow turning the light on during the day. Is this really what you want?

Lastly you should add an or condition to ensure the light always turns off if it is outside this time range.

A much simpler way to do this would be with two automations, one for on and one for off.

Yes, use a line of ``` before and after your code. It’s important because indentation is important and you may have something wrong there

There is a section which I don’t think does anything:

  - condition: not
    conditions:
      - condition: state
        state:
          - com.google.android.youtube.tv
        entity_id: media_player.theatre_room_tv

and may be stopping your script.

Without that that section, I think your automation will turn on your light when the motion sensor turns on only if some device is off OR it is between 06h30 and 23h00. Then it will wait for the motion sensor to be off for 2 minutes and turn off the light.

Try creating this script in the visual editor. Note that if you want to do an AND you have to put the AND block first, followed by the conditions (which will be further indented)

And if you think that’s confusing, you should try to program in FORTH!

1 Like