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
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’?
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.
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:
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.
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.