Hi all,
I have been trying to set an automation that follows this:
If my location changed from “away” to “home”, and the front door is opened, turn the lights on for 30 secs then turn off, adjust the AC temperature and play announcement. If lights were already on, do not turn lights off. If I am home for more than 5 minutes, do not run automation anymore.
All works, except for the fact that it runs every time I open the door even if I have been home for hours.
I tried to implement a check if I have been home for 5 minutes or more to stop running the automation, but I cannot manage to let the node output different messages depending on if I have been home for less than 5 minutes or more than 5 minutes (figure 3). Any suggestions?
I think you’re under the impression that the switch node is going to wait until both the door is opened and you are home. That’s not how that works at all. Drawing two lines into the same node doesn’t mean they have anything to do with each other, each flow is independent. It just means from that point forward they go down the same path.
So what happens is this. First flow (starting from the "Door opened?" trigger node):
Door is opened - create msg and start flow
Switch node - Does msg.payload == 'on'? If so, proceed to "Sun Down?". If not, do nothing
Continue with rest of flow from "Sun down?" on
Basically this is going to fire the flow every time you open the door. Whether you are home, not home, have been home for 2 days, all completely irrelevant. When the door opens, this flow will proceed because that’s the trigger and msg.payload will be equal to on.
Completely separately and totally unrelated to the first flow you have this flow starting from "Home?":
You arrive home - create msg'and start flow
Current state node - Have you been home for 5 minutes or more? If so, end this flow (the first output for when the condition is true goes nowhere). If not then first set msg.payload equal to already_home. Then immediately change msg.payload to just_arrived (why are you setting msg.payload twice in the same node with nothing in between?) and proceed to the switch node
Switch node - Immediately end this flow. msg.payload is always going to be just_arrived in this flow and the second output on this node goes nowhere. It only proceeds to the nodes that follow when msg.payload == 'on'
From reading it this flow is always going to stop at either the current state node or the switch node, depending on whether you have been home for 5 minutes or not. It will never make it past the switch node though because the output for when msg.payload == 'just_arrived' goes nowhere.
What I believe you want to do there is drop the Home? trigger entirely. Only have the Door Opened? trigger and replace the switch node with the Home for 5 minutes or more? current state node. Then when the door is opened it will start the flow but it will only do the lights and announcements if you haven’t been home for 5 minutes or more.
thank you for the quick reply! I think I understood what you explained above. Seems like I was overcomplicating the flow but now seems like it will work fine: