HestiaPi / hestia-touch-openhab

OpenHAB2 files for HestiaPi Touch model
GNU General Public License v3.0
60 stars 17 forks source link

Made rules generic #28

Closed rkoshak closed 4 years ago

rkoshak commented 4 years ago

A rewrite of the Rules to remove duplicate code, add some logging and some error checking.

The new Rules should work almost exactly the same as the old code. There were a couple of bugs in the old code (e.g. referring to Items that do not exist, the rule never would have worked).

As mentioned all the Rules are now in the one file so hvac.rules and generic.rules have been removed and default.rules added.

You will find a new file in scripts called TestChecklist.txt. This shows the tests and verification steps that I performed to test out these new Rules. I tried to be pretty thorough. But if I misinterpreted the way something is supposed to work, you will see that in the checklist.

I'm pretty sure I exercised every line of code so it should work as expected. But please let me know if I missed something or missinterpreted something.

I help in some commented out code. I wasn't sure what it was all about.

I've some TODOs scattered throughout the code with some questions about whether certain things are still needed (e.g. the reboot after changing the SystemType.

Solves #26 and #10

Signed-off-by: Richard Koshak rlkoshak@gmail.com

rkoshak commented 4 years ago

I apologize for the extra commit. I discovered a bug that occurs on a restart of the machine. The change is to allow sensor updates to process even if the system is starting up (i.e. remove the if(initializing) return; from the Process Sensor Changes Rule.

Otherwise, if the reading is holding steady nothing will work until the temp actually changes which could be quite some time. There is already a check in place to avoid turning on or off anything until the system is done booting up.

rkoshak commented 4 years ago

OK, there are other problems with reboot. I'm working on another commit. Until I figure this out consider this a WIP.

rkoshak commented 4 years ago

OK, this latest check-in should be fine. The problem before was the new sensor readings were being ignored while the initialization Rule was running. But the sensor may not change enough to generate a change every ten seconds. In fact, if the temp is held pretty steady it could be a long time before there's a change and consequently the proxy Items never update causing the rules that need to check the current temp (or humi) to fail because the proxy was NULL.

The other problem was even if the sensor readings are not ignored and all the proxies are updated, if the temp changed during the initialization rule that change wouldn't have been processed. As a result we would have to wait until the temp changed again by a large enough amount before, for example, the heater would turn on even if the temp was below the setpoint while the initialization rule was running. So we command the proxy and the PrevReading Item at the end of initialization which will kick off the "Temp/Humidity or setpoint changed" rules which will immediately activate the devices (or not) based on the current mode.

This should be ready for review now. It's been running on my spare HestiaPi for about a week now and running on my production one for the past 24 hours or so (it was transferring it to my production system that I discovered the reboot problem).