Issue with Condition not stopping action

So here is my scenario and issue:

I want my garage door to shut itself if it happens to be open after 11PM. I have a Wemo maker with a reed sensor hooked up to help me with this. If the sensor is in the ‘off’ state (garage door open) then I want the action ‘automation.trigger’ to fire off and close the garage door. If the state is ‘on’ (garage door closed) I want the automation to not run the action.

As of right now, the automation works; if the garage door is open after 11pm, the relay will trigger and shut the garage door, but if the door is already shut, the relay triggers anyway. I assumed with my condition checking the garage door sensor for only firing when it’s in the ‘off’ state would solve this, but I’m obviously missing something. Please review my automation below and let me know what I’m doing wrong:

- action:
  - alias: ''
    data:
      entity_id: switch.garage_door
    service: switch.toggle
  alias: Close Garage Door after 11PM
  condition:
  - condition: state
    entity_id: switch.garage_door
    state: 'off'
  id: '1516590572395'
  trigger:
  - at: '19:00'
    platform: time

Check your switch.garage_door state is actually 'on/‘off’ and not 0/1 or open/closed. Also please select your code and use the </> button in the edit window to format your code for display here, it’s hard enough to read after the automations editor has finished with it as it is :frowning:

Keith,
I have formatted my code so it’s easier to read. Regarding the switch.garge_door state it is on/off as you can see from the picture below. The condition works to close the garage door but the condition isn’t preventing the switch.toggle action from running if the state isn’t off. Do I need to proclaim somewhere for the action to not run if the switch state is set to ‘on’?

It looks OK to me, have you got another automation that may be changing the state of the switch? Why does it say sensor_state: on?

I’m not sure what that is. I’ve updated my code a bit, but it doesn’t work:

    - action:
      - data:
          entity_id: switch.garage_door
        service: switch.toggle
      alias: Shut Garage Door after 11PM
      condition:
      - condition: state
        entity_id: switch.garage_door
        state: 'off'
      id: '1516680934286'
      trigger:
      - at: '22:00'
        platform: time

my condition states are accurate, but if the state is either on or off, the automation still fires. I want the action to only fire if the state of switch.garage_door is ‘off’. If the state of switch.garage_door is ‘on’ then I want the action to NOT fire.

How are you testing this? You aren’t manually triggering the automation are you?

Try putting the condition in the action part.

James,
I am manually modifying the trigger time while I sit by my garage door and test the results. I am not triggering it manually.

Keith,
Do you want me to remove the condition completely or leave the condition alone and add it to the action? Also, should I leave my current action there?

I will sometimes add an input boolean as a trigger to test things that are time based. All you need to do is add the trigger to your existing code and flip the boolean to test all the actions aside from the time trigger.

Also, I’m guessing you used the automation creator in the GUI to create this automation because everything is out of logical order. I’d recommend that you put this in a readable order so that you can follow the code yourself. It makes it much easier to read for yourself and others trying to help:

- alias: Shut Garage Door after 11PM
  trigger:
    - platform: time
      at: '22:00'
  condition:
    condition: state
    entity_id: switch.garage_door
    state: 'off'
  action:
    service: switch.toggle
    entity_id: switch.garage_door

Also, writing it this way allowed me to find the issue with your automation. Your action is wrong, entity_id does not go in the data:

- action:
  - data:
      entity_id: switch.garage_door
    service: switch.toggle

should be:

- action:
  - entity_id: switch.garage_door
    service: switch.toggle

Petro,

Would I need a dual conditional statement as well? Something like, “If it’s after 11pm AND the state of the switch is off, then fire the action”.

No, the trigger occurs at 11pm.

So at 11 pm, the door will shut if its open. If someone opens the door at 11:01pm, this automation will not shut the door until the next day at 11pm.

I manually set the time trigger to 2 minutes in the future to test the config and it doesn’t work. Nothing triggers and the log doesn’t show that anything triggers. Again, my code is below:

- alias: Shut Garage Door after 11PM
  trigger:
    - platform: time
      at: '08:49'
  condition:
    condition: state
    entity_id: switch.garage_door
    state: 'off'
  action:
    service: switch.toggle
    entity_id: switch.garage_door

is the time set correctly in your hass? Also, does ‘off’ = open garage or does ‘on’ = open garage. I the way my switches work is ‘on’ = open/on, ‘off’ = closed/off.

How do you set the time in hass?

Regarding “on/off” state, my system defaulted to “off” being the garage door is open and “on” being the garage door is shut

I probably should have stated what version of HA I’m using as well. I’m currently on version 0.61.0

I confirmed my time is set to the correct timezone in the config file as well.

If you know the state of the switch, why are you using switch.toggle ? This won’t fix your issue, but I recommend using switch.turn_on instead.

just noticed, time should be formatted: 00:00:00

- alias: Shut Garage Door after 11PM
  trigger:
    - platform: time
      at: '08:49:00'
  condition:
    condition: state
    entity_id: switch.garage_door
    state: 'off'
  action:
    service: switch.toggle
    entity_id: switch.garage_door
   action:
     - service: switch.turn_on
       entity_id: 
         - switch.rfl_bedroom_pcmonitorandsound
         - switch.zw_bedroomsunlamp_switch
         - switch.rfl_bedroom_pcmonitorandsound
         - switch.rfl_bedroom_uplightredbottomlamp
     - condition: or
       conditions:
         - condition: sun
           before: sunrise
           before_offset: "00:15:00"
         - condition: sun
           after: sunset
           after_offset: "-00:45:00"             
     - service: light.turn_on
       entity_id: 
         - light.rfl_bedroom_ceiling_light

This is how I do it - my lights come on but I don’t want the ceiling light to come on unless it’s dark

Try your condition like this …

  condition:
    - condition: state
      entity_id: switch.garage_door
      state: 'off'

using the - just places it in an ordered dictionary. It’s needed if you have more than one condition. Shouldn’t be needed in his case. I think his issue is not having the HH:MM:SS format. His automation is only MM:SS which may be ignored or it will treat it like 00:MM:SS which means the automation would only occur between midnight and 1 am.

1 Like