Thank you so much am so happy it now works
i have modified the workflow as follows and now it do what i want finally after 2 days.
thanks to you again brother .
[{"id":"8bf2702708aca886","type":"inject","z":"a5a4adb58554b6e2","name":"relay -> \"0\"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"0","payloadType":"str","x":130,"y":140,"wires":[["5d368d1216d31c6e"]]},{"id":"973d433ca296448b","type":"inject","z":"a5a4adb58554b6e2","name":"check -> \"0\"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"0","payloadType":"str","x":110,"y":520,"wires":[["4fda245f89d15c4b"]]},{"id":"7a8f51bb04a6d7c0","type":"inject","z":"a5a4adb58554b6e2","name":"relay -> \"1\"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"str","x":130,"y":180,"wires":[["5d368d1216d31c6e"]]},{"id":"54cd0eea641a8a3e","type":"inject","z":"a5a4adb58554b6e2","name":"check -> \"1\"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"str","x":110,"y":560,"wires":[["4fda245f89d15c4b"]]},{"id":"5d368d1216d31c6e","type":"change","z":"a5a4adb58554b6e2","name":"payload to flow","rules":[{"t":"set","p":"relay","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":300,"y":160,"wires":[["142d4614.f818aa","c0b966c.6cdca98","305cfdf2.9e8af2"]]},{"id":"4fda245f89d15c4b","type":"change","z":"a5a4adb58554b6e2","name":"check to flow","rules":[{"t":"set","p":"check","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":290,"y":540,"wires":[[]]},{"id":"c0b966c.6cdca98","type":"switch","z":"a5a4adb58554b6e2","name":"if (check == 1)","property":"check","propertyType":"flow","rules":[{"t":"eq","v":"1","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":580,"y":300,"wires":[["a04dcc7.c72123"]]},{"id":"a04dcc7.c72123","type":"switch","z":"a5a4adb58554b6e2","name":"if (relay == 1)","property":"relay","propertyType":"flow","rules":[{"t":"eq","v":"1","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":750,"y":300,"wires":[["9e1e9f30.858e9"]]},{"id":"9e1e9f30.858e9","type":"change","z":"a5a4adb58554b6e2","name":"flow to payload ","rules":[{"t":"set","p":"payload","pt":"msg","to":"relay","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":920,"y":300,"wires":[["cb4c28be.e0f698"]]},{"id":"305cfdf2.9e8af2","type":"switch","z":"a5a4adb58554b6e2","name":"if (check == 1)","property":"check","propertyType":"flow","rules":[{"t":"eq","v":"1","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":580,"y":380,"wires":[["5c95c53f.3773ec"]]},{"id":"5c95c53f.3773ec","type":"switch","z":"a5a4adb58554b6e2","name":"if (relay == 0)","property":"relay","propertyType":"flow","rules":[{"t":"eq","v":"0","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":750,"y":380,"wires":[["6e17ee06.4fa98"]]},{"id":"6e17ee06.4fa98","type":"change","z":"a5a4adb58554b6e2","name":"flow to payload ","rules":[{"t":"set","p":"payload","pt":"msg","to":"relay","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":920,"y":380,"wires":[["e48e73ac.33f52"]]},{"id":"618c6bda.b481b4","type":"debug","z":"a5a4adb58554b6e2","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1170,"y":220,"wires":[]},{"id":"cb4c28be.e0f698","type":"debug","z":"a5a4adb58554b6e2","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1170,"y":300,"wires":[]},{"id":"e48e73ac.33f52","type":"debug","z":"a5a4adb58554b6e2","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1170,"y":380,"wires":[]},{"id":"142d4614.f818aa","type":"switch","z":"a5a4adb58554b6e2","name":"if (check == 0)","property":"check","propertyType":"flow","rules":[{"t":"eq","v":"0","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":580,"y":220,"wires":[["d451c0c0.03235"]]},{"id":"d451c0c0.03235","type":"switch","z":"a5a4adb58554b6e2","name":"if (relay == 1)","property":"relay","propertyType":"flow","rules":[{"t":"eq","v":"1","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":750,"y":220,"wires":[["b7a1eef0.026ea"]]},{"id":"b7a1eef0.026ea","type":"change","z":"a5a4adb58554b6e2","name":"flow to payload ","rules":[{"t":"set","p":"payload","pt":"msg","to":"relay","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":920,"y":220,"wires":[["618c6bda.b481b4"]]}]