Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dual interlocking relays and 3T valve #8

Open
thucar opened this issue Nov 6, 2018 · 27 comments
Open

Dual interlocking relays and 3T valve #8

thucar opened this issue Nov 6, 2018 · 27 comments

Comments

@thucar
Copy link

thucar commented Nov 6, 2018

I’ve been using a z-wave roller shutter module and node-red to control my central heating for over a year now. I’d like to give sonoff a hard thermostat a go in stead to mitigate any issues when the pc crashes for instance.

I’m not completely sure I can control my 3T valve like that though. It looks like it would require two, mirroring outputs with a dead zone between them. Otherwise the valve would end up constantly either opening or closing. Am I over thinking this?

@colinl
Copy link
Owner

colinl commented Nov 6, 2018

Can you give me a link to how the device operates?

@thucar
Copy link
Author

thucar commented Nov 6, 2018

For instance this one:
http://www.syxthsense.com/product/product_pdf/HT230-3-S.pdf Look at the three point control. If 230v is applied to one terminal, the valve moves in one direction. If to the other terminal, then in the opposite direction. To stop the valve and hold current position, you cut the power completely.

@colinl
Copy link
Owner

colinl commented Nov 6, 2018

Right, understood. Whether the current s/w will cope with that depends on what you want to do. If you want to linearly control the flow so the valve might be sitting at half open for example then the answer is no, I am afraid the current PID algorithm won't cope with that. As the motor drive is itself a free integrator then that knowledge needs to be built into the algorithm, effectively replacing the integral that is currently included in the software. To do that would not be a trivial task and I haven't got any plans to do it at the moment.
However if you were prepared just to treat it as a valve that is only either open or closed (like the simpler valves that are just open or closed) then you could use the same technique that is used for those valves. That is to use the time proportioned output so that if, for example, the pid algorithm called for 50% power then the valve would be opened for, say, 5 minutes and closed for 5 minutes alternately.

@thucar
Copy link
Author

thucar commented Nov 7, 2018

Ok, that's what I was afraid of. Unfortunately treating it as a simple open-closed valve would not work because that valve directly controls the temperature of the water going into the radiators in the house. The hot water tank where it gets its water from is often sitting at 90C.

Now if someone were to add valve/shutter control logics with positioning to Tasmota - making it possible to set the output of such a device in 0-100% range. Would that be easier to implement to PID control?

@colinl
Copy link
Owner

colinl commented Nov 7, 2018

Yes, if there was s/w given a required valve position in the range 0 to 1 (for example) that moved the valve to that position (or at least, knowing where the current estimated position is, moved it in the right direction for the right time so that the position estimate is the required position) then the existing PID output could be fed directly to that. It would not be as good as building it into the PID algorithm but it could probably be made to work. Of course if the valve had position feedback then it would be much better (and more expensive).

@thucar
Copy link
Author

thucar commented Nov 7, 2018

Ok, that's good news. As a matter of fact, that is exactly how I am using the Node-Red PID controller right now. I scale the 0-1 output up to 0-99 integer values which I feed directly into the Fibaro roller shutter module as position. Works like a charm but I'd prefer to have a contingency plan in place should there be a failure of one of the components.

The Fibaro Z-Wave roller shutter module does a great job at estimating the valve position without any feedback. I guess it measures the travel time and then just keeps track of its position based on how long it has been moving in one or the other direction. It also seems to "re-calibrate itself" every time it reaches one of the end switches.

I'll look into achieving the same with a Sonoff Dual.

@colinl
Copy link
Owner

colinl commented Nov 7, 2018

It shouldn't be two difficult to write a function node in node red to emulate the shutter module. Once that was working then it could be re-coded for the sonoff. I don't have time to look at that at the moment though.
The trick to making it recalibrate would be that any time the requested position was fully off or on then it would keep the motor drive on until it hit the switch (or just keeps it on permanently if the wiring can be organised so that the motor is automatically switched off when it hits the switch).

@thucar
Copy link
Author

thucar commented Nov 7, 2018

Looks like @stefanbode has done the heavy lifting already: https://github.com/stefanbode/Sonoff-Tasmota/wiki/Shutter-blinds-working-with-two-relays

Are there any plans of pushing the PID control functionality back to the main Tasmota branch at some point? I'm trying to decide on the best course of action. Right now it seems I would need to juggle these three branches into one of my own to get the most up to date version of all components involved.

@colinl
Copy link
Owner

colinl commented Nov 7, 2018

Excellent. No there aren't any plans to get it back onto the main branch. I check occasionally that it still works but I don't think it would be worth the effort to continually keep up to date with the latest, it changes too often. Since you don't need the timeprop feature all you need to do is to pick up the two PID files in lib/ProcessControl and the xdrv92 pid file from my branch and add them into your code. My code changes very rarely, I fixed a problem with setting PB to zero recently so it goes into on/off control properly but there is nothing else going on at the moment and I don't know of any issues with it.

@thucar
Copy link
Author

thucar commented Nov 7, 2018

Great! I'll see if I can get all three parts playing nice with each other then.

@colinl
Copy link
Owner

colinl commented Nov 7, 2018

Let me know how you get on. It would be worth adding the details to the tasmotta wiki if you get it going. Either as a separate section or added to my bit.

@thucar
Copy link
Author

thucar commented Nov 9, 2018

Ok, so I seem to have both, the shutter and PID code running side by side. However, they are not quite playing nice yet.

At first I tried to take the latest Tasmota firmware and add your and @stefanbode's code to it. Unfortunately his was quite extensively changed and I ended up just taking his full code and adding your PID file/library to that.

Now I have the shutter part working and I see your PID power value every time there is a temperature report. The only thing I'm not sure on, is how to feed that power value to Stefan's shutter position directly within the sonoff. His code accepts commands like: "Shutterposition xx"

I'm thinking rules might be the way to go? I've not used the rules system yet so unsure if that would be the route to take.

@colinl
Copy link
Owner

colinl commented Nov 9, 2018

I haven't used the rules either.
If I were doing it I would have a look at the shutter code and you will hopefully find a function that is called when the shutter command is called. If you then look at my code then at the end of the function run_pid() you will see some conditional code (which you are not calling because you haven't defined use timeprop)

#if defined PID_USE_TIMPROP
    // send power to appropriate timeprop output
    Timeprop_Set_Power( PID_USE_TIMPROP-1, power );
#endif // PID_USE_TIMPROP

if you add above there something like

#if defined PID_USE_SHUTTER
    // send power to the shutter position code
    SomeFunctionInTheShutterCode( power );
#endif // PID_USE_SHUTTER

and then define PID_USE_SHUTTER in your config obviously then it wll call that function each time round.
I don't know what your experience is writing code, do you need help finding the function to call?
If so can you point me to where to find the repo and an idea of which file to look in?

@thucar
Copy link
Author

thucar commented Nov 9, 2018

Yup, that did it! I was trying to avoid having to make any changes to the actual code on any side of the equation that is why I was looking into Rules. It seems that rules would actually work well for this also. I just could not figure out how to trigger a rule off your Pid_ power report.

For now I ended up adding this small snippet:

//Thucars-mod
#if defined USE_SHUTTER
  int pos = power * 100;
  SetShutterPosition(1, pos);
#endif
//

to where you suggested.

@colinl
Copy link
Owner

colinl commented Nov 9, 2018

Excellent. Could you make it PID_USE_SHUTTER so that it is clear what it is for. We want to make sure that all #defines used by the pid code are unique, with it just being USE_SHUTTER the code might get included accidentally if USE_SHUTTER were used for something else. You could imagine someone using shutters with manual control and using the pid control for something different in the same device.
Once you are fully happy it is all working I will put that into the code ready for anyone else.

@thucar
Copy link
Author

thucar commented Nov 9, 2018

The USE_SHUTTER is the same variable that enables shutter functionality in Stefan's code. I just reused that. But now that you mention it, it does make sense to have a separate variable to enable/daisble PID control for said shutter. My current solution also does not account for different number of shutters nor can you specify which shutter it would control.

This leads me to another question - would it be possible to have multiple instances of the PID control running? So that if I were to hook up 8 relays and 4 temperature sensors, I could have them all working independently?

@stefanbode
Copy link

Hi gents,
sorry for making so many changes to my fork. I just try to keep it in sync with the TASMOTA master branch and therefore there are always changes. @colinl. Clould you directly get into contact with me by opening a case in my fork. I like the PID idea an already have done the implementation for up to 4 shutter. Therefore hopefully not that much work. But only if you are ok, that I reuse your idea.

@colinl
Copy link
Owner

colinl commented Nov 9, 2018

You can only have one PID as it is currently written. It could be extended to allow multiple instances but I think you might start running out of processor and memory pretty quickly. If I were doing that I would use a Pi with node-red. The same algorithm is available in node-red. Can the shutter code drive multiple shutters?

@stefanbode
Copy link

Yes up to 4 with 8 relays, but this is also only one configuration. Normally more does not make sense. Theoretically, 16 up to 32 valves should be possible with some minor changes and hardware like the PCF8574

@thucar
Copy link
Author

thucar commented Nov 9, 2018

Well, I gotta say both you gentlemen have done awesome job with your respective codes. The only thing I would really love at this point is if we could get the PID and shutter codes pushed back into the main Tasmota repo. At the moment it seems that PID is very well isolated and should not require lot of upkeep to stay up to date with main branch changes.

If needed, I'm willing to play the man-in-the middle and create a uniform PR for the joint code and help run maintenance in the future should things break with upgrades. I would need some guidance from @stefanbode with his code though. As it contains so much more than just the shutter control.

@colinl
Copy link
Owner

colinl commented Nov 9, 2018

I should have thought of the possibility of multiple loops when designing it in the first place. It wouldn't be that difficult to extend but I don't have time at the moment. PRs always welcome :)
Are you actually using it with the valve control now?
Would the mods be accepted back into the main code? I don't know what the policy is.

@stefanbode
Copy link

Let me change the Web interface to the new method. Arendst has made it easier do to enhancements also here. My shutter needs the modified INTERLOCK and the SHUTTER module. The changes INSIDE the master code should be ~5-10 smaller ones. My Problem is I do not know github that well that I can do a PR request out of my fork.

@stefanbode
Copy link

Where do I find your PID enhancements in the code? Just point me to a starting point.

@colinl
Copy link
Owner

colinl commented Nov 9, 2018

I have opened an issue on @stefanbode fork to carry on talking about the integration.
stefanbode#87

@thucar
Copy link
Author

thucar commented Jan 11, 2020

I had not been using the PID function for a while. Mainly because I could not be bothered with making the changes needed when upgrading.

Today I decided to try it again, and it's dead easy.

Only one modification needed - maybe @colinl could incorporate it into the code? I don't have a development environment set up currently or I'd make a PR

Anyways, the added snip is this: right before PID_USE_TIMPROP

#if defined PID_SHUTTER
    // send output as a position from 0-100 to defined shutter
    int pos = power * 100;
    ShutterSetPosition(PID_SHUTTER, pos);
#endif

And an additional PID configuration parameter is PID_SHUTTER which holds the number of the shutter to use for PID output.

And that's it! Works like a charm. I have 6 local DS18B20's hooked up to my 4CH Pro, so I'm using a Rule to capture the correct temp value and issue a pid_pv command. Works like a charm.

At this point the Sonoff is a complete standalone heating controller for my house. The ruleset below manages the temperature of the water going into my radiators, turns radiator circulation pump on and off when needed, and also turns on/off my boiler circulation pump depending if the boiler is heating or sitting idle.

on tele-DS18B20-3#Temperature do pid_pv %value% endon
on tele-DS18B20-3#Temperature > 30 do POWER3 ON endon
on tele-DS18B20-3#Temperature < 25 do POWER3 OFF endon
on tele-DS18B20-5#Temperature do Var1 %value% endon
on tele-DS18B20-1#Temperature > %Var1%+10 do POWER4 ON endon
on tele-DS18B20-1#Temperature < %Var1% do POWER4 OFF endon

@thucar
Copy link
Author

thucar commented Jan 12, 2020

Created a PR for this

@degreal
Copy link

degreal commented Feb 16, 2022

How do you solve shutter drift issue? I calibrated 3T valve as a shutter precisely as I can but in a week it's going to drift so it will not fully close or fully open, you have to cycle from 0% -to 100% so that the position in Tasmota reflects the reality. Often times it's impossible to cycle it to 100% because 110c water is going to melt my pex pipes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants