Delay Timer With Momentary Push Button

I've searched this forum and the flows library and drawing a blank to this simple problem.
Using a momentary pushbutton, I can toggle the output on/off with each push.
Now I would like to add a timer to turn off the light if someone leaves it on.
The trigger node works for this function but the push button will have to be pressed twice to turn the light back on if the trigger node turned it off.
Trying to find a way to eliminate the extra button push to get back in sync with the output.

[{"id":"6c4e53bf.97148c","type":"subflow","name":"Toggle 1/0","info":"","category":"","in":[{"x":60,"y":180,"wires":[{"id":"5047f5ea.66c1ec"}]}],"out":[{"x":780,"y":160,"wires":[{"id":"82ff5a1a.efefc8","port":0},{"id":"26637948.29d256","port":0}]}],"env":[],"color":"#DDAA99"},{"id":"7347b78.8b23848","type":"switch","z":"6c4e53bf.97148c","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"str"},{"t":"eq","v":"0","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":390,"y":180,"wires":[["82ff5a1a.efefc8"],["26637948.29d256"]]},{"id":"82ff5a1a.efefc8","type":"change","z":"6c4e53bf.97148c","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"1","tot":"str"},{"t":"set","p":"next","pt":"flow","to":"0","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":600,"y":140,"wires":[[]]},{"id":"26637948.29d256","type":"change","z":"6c4e53bf.97148c","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"0","tot":"str"},{"t":"set","p":"next","pt":"flow","to":"1","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":600,"y":200,"wires":[[]]},{"id":"5047f5ea.66c1ec","type":"function","z":"6c4e53bf.97148c","name":"get next value","func":"msg.payload = flow.get(\"next\")||0;\nreturn msg;","outputs":1,"noerr":0,"x":200,"y":180,"wires":[["7347b78.8b23848"]]},{"id":"63d63c99.01ce24","type":"rpi-gpio out","z":"29688e2c.d40952","name":"Inside Lights 1","pin":"12","set":"","level":"0","freq":"","out":"out","x":700,"y":160,"wires":[]},{"id":"f843202a.e1d73","type":"subflow:6c4e53bf.97148c","z":"29688e2c.d40952","name":"","env":[],"x":470,"y":140,"wires":[["63d63c99.01ce24"]]},{"id":"a358c971.574ff8","type":"ui_button","z":"29688e2c.d40952","name":"","group":"d95eee3.582311","order":0,"width":0,"height":0,"passthru":false,"label":"button","tooltip":"","color":"","bgcolor":"","icon":"","payload":"1","payloadType":"num","topic":"","x":290,"y":160,"wires":[["f843202a.e1d73","a6df00a9.c7179"]]},{"id":"a6df00a9.c7179","type":"trigger","z":"29688e2c.d40952","op1":"","op2":"0","op1type":"nul","op2type":"str","duration":"5","extend":false,"units":"s","reset":"","bytopic":"all","name":"","x":480,"y":180,"wires":[["63d63c99.01ce24"]]},{"id":"d95eee3.582311","type":"ui_group","z":"","name":"Default","tab":"943e4ae0.008958","disp":true,"width":"6","collapse":false},{"id":"943e4ae0.008958","type":"ui_tab","z":"","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]

Your code above is not importable, please see the link below, and edit your post so that others may help you.

Thanks! I looked for that FAQ and couldn't find it. Just edited my original post.

Rather than feed the output of the trigger to the GPIO, feed it into your subflow.

When your trigger node switches off the light, it also needs to toggle the flow context value, to prepare the subflow for the next button push occurrence.

I'm new to the subflow process. Trying to determine where the trigger node gets inserted within the subflow?

Change the trigger node so it outputs 1, exactly as the button does, connect its output to the subflow input (you can have two wires going into one node). Then from the perspective of the subflow it will appear exactly as if the button has been pressed again.

1 Like

It doesn't need to get inserted into the subflow, you just need the output from the trigger node to also toggle the saved flow context value.
Currently, after the trigger node switches off the light, the flow context value still indicates that the light is on. So the first button push switches OFF the light (which is already off!!)

As always there are multiple ways of doing things. Personally I would keep all manipulation of the context value in one place (inside the subflow).

@Colin I think its confusing for both of us to answer this post at the same time, so I'll butt out :wink:

Hopefully having multiple options is not confusing, @Randy can consider both and decide which he prefers.

Well if I was @Randy I would use your solution @Colin - it's a better way of achieving the same result than what I suggested :rage:

Thanks guys, problem solved!
I had previously tried this but had the button sending a 1 and the trigger node sending a 0. Nothing like going in circles.
BTW, icing on the cake would be a timer/trigger node that allowed the reset time to be changed from a dashboard numeric input. Normally turning the lights off after 15 minutes works. But being able to select a longer time would be nice.