Basic design toggle switch

I trying some basic concept for my HA setup. The current design is intended to operate the light based on time settings, which works well BUT…

I ran into the situation that the light is toggle on just within the time frame it should work, but the toggle to turn the light off again, never happens until the filter is not applied anymore.

Is there a simple solution to resolve that ? Maybe the solution should be more generic so a light can be controlled by multiple variants that control the light:
variant “on/off” OR
variant “all on/all off” OR
variant “Toggle” (based on sensor combined with time as depicted below).

I’m sure it is possible, but what is the most simple design ?

[{"id":"434ba335.1c8b7c","type":"tab","label":"Zigbee","disabled":false,"info":""},{"id":"15af4d3889db3b8e","type":"debug","z":"434ba335.1c8b7c","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1010,"y":340,"wires":[]},{"id":"5691de42c960c4e8","type":"debug","z":"434ba335.1c8b7c","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":380,"y":240,"wires":[]},{"id":"20698df4494427dc","type":"server-state-changed","z":"434ba335.1c8b7c","name":"Detector ","server":"c85ce556.38fbc8","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.hallway_motion_mot","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"eventData"}],"x":180,"y":340,"wires":[["5691de42c960c4e8","67840782c1b4700f"]]},{"id":"4da7edc8bbc9722b","type":"api-call-service","z":"434ba335.1c8b7c","name":"Test","server":"c85ce556.38fbc8","version":3,"debugenabled":false,"service_domain":"light","service":"toggle","entityId":"light.sw01_on_off","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":850,"y":340,"wires":[["15af4d3889db3b8e"]]},{"id":"7c4c0c79ee1d96e8","type":"inject","z":"434ba335.1c8b7c","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"entitystate","payloadType":"msg","x":180,"y":420,"wires":[["67840782c1b4700f"]]},{"id":"67840782c1b4700f","type":"time-range-switch","z":"434ba335.1c8b7c","name":"Dark Day Period","lat":"51.24118","lon":"4.96651","startTime":"dusk","endTime":"22:00","startOffset":"-60","endOffset":"0","x":410,"y":340,"wires":[["4da7edc8bbc9722b"],["022f2e3b7f1a5e40"]]},{"id":"022f2e3b7f1a5e40","type":"time-range-switch","z":"434ba335.1c8b7c","name":"Dark Day Period","lat":"51.24118","lon":"4.96651","startTime":"dawn","endTime":"09:00","startOffset":"-60","endOffset":"0","x":650,"y":380,"wires":[["4da7edc8bbc9722b"],[]]},{"id":"c85ce556.38fbc8","type":"server","name":"Home Assistant","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30}]

It appears that that this is a motion activated light? Perhaps this will help.

Indeed. These are motion triggered. Thanks for the link. Will adapt my flow to check the results.