Hi
Without access to hardware I can only simulate and as Martin mentioned earlier FC is great at that.
I'm not saying the following will work for you or even be what you need but it may give you some ideas.
I assume you do not have the setup for TMR1 to run during sleep so I haven't included.
The attached chart when run, first checks to see if it is being simulated. If so then later in the chart we simulate interrupts and sleeps by including delays. These delays won't appear in your actual hardware and you can just delete if you want.
I have used an LED on A1 as your valve
Button on B1 as your Start
Button on B0 as your Flow Sensor, interrupting and incrementing a count
Note that I don't know anything about your sensor you will need to figure out reading it and how many "counts" equals 200 Litres.
The chart basically sits sleeping from the minute you apply power and briefly:-
As usual we first reset variables then switch your valve off. We then enable WDT for 256 seconds and enable IOC (Start Button) before going into a loop with four branches (0-3).
In Branch 0 we do nothing but loop around sleeping
When the Start button is pressed we wake up and go to Button Macro. In here we set Branch=1
In Branch 1 we disable Start button, disable WDT, Set Branch =2 and enable your Valve. We also enable TMR1 and INT0 (Flow Sensor)
In Branch 2 it basically loops for four hours checking for target values and if reached does something. If you press the button "Flow Sensor" it will increase the value by one count. As we are simulating I have a delay of 13mS in the branch to act as Timer1. Each time the decision is reached it will call the Tick macro which increments a counter.
The first decision in this looping Branch is to check if 200 litres have flowed. If so we disable the Interrupt and disable the Valve.
The next decision is to check if four hours have passed. If so we disable TMR1, Disable INT0, Disable the Valve, Enable WDT and set Branch = 3
In Branch 3 we basically sleep for the next 20 hours (all buttons etc are disabled). Once 20 hours have elapsed we Enable IOC (start button), set Branch = 0 and loop around Branch 0 sleeping until the Start button is pressed.
I have not been able to test but it does compile to C and does simulate.
If you Simulate and have all variables on display, depending on your simulation speed you can see and also alter values. When testing, as I was simulation my four hours, I set "Litres" to 198. This meant I only had to push the "Flow Button" twice to reach 200. When it did the chart did as expected.
I then set "Tick" to 1,000,000 so within a few tens of seconds it had reach "four hours", did what it should then went into Branch 3. Here I checked nothing was active, buttons didn't work etc and then set "Tick" to a value close to 20 hours, which upon hitting the chart did as expected.
It isn't elegant, there are no doubt better ways to do it, but I can't think on a better way to sit in a hotel avoiding typhoons....
Again, it is really just to perhaps give you ideas.
Regards