Ideas to new bindings

Hi Community,
I have been using OH since version 1.3 (or something like that), and over time I have developed som rules that is quite complex. Actually I haven’t developed them all by my self, but I have started with the complex rules shared in the forum. Especially there is an article called Taking rules to new hights. This article basically describes how to make a PIR sensor trigger a light and then turn it off after some time specified. I realised that when OH is started the first run of the rule takes ages, seems like the HashMap /Arrays is initialised. I also dislike the idea o basef putting configuration into my rules.

After looking at OH2 and the new Bridges and Things, I believe that this could be implemented through a Binding. The idea strok me to create a binding that allows to map a switch and a contact to the same bridge, and then have some configuration on the bridge to make it possible to be more that just a dumb switch. Eg. a condition could be that the bridge is only active when it is dark outside.

I am a little in doubt if this is in the scope of OH Bindings (since it is not directly integrating to any external system). The question is if it is worth considdering or if such “problems” shoul be handled in another way?

I have similar ideas to other bindings, eg. some binding to do more advanced presence detection, or alternatively give a probability of somebody being at home. But again, this is not integration to any external system.

That article is excellent at showing how to do a lot of different things with the Rules engine. I learned a lot about how to code in the Rules DSL through that article. However, I believe it is overly complex and could be vastly simplified and accomplish the same thing. In particular Groups can be used to replace the motionSensors HashMap entirely and I’m pretty sure the fixtures HashMap can be managed better as well. With those changed the logic in the rule can be simplified to use group.members.forEach, .filter, .sortBy, etc. Based on my experience with my own rules I could probably cut the lines of code by half and probably make it run better in the process.

That might address your initial run delay issues, if that is in fact the source of your problem (I’m not convinced).

I also dislike putting configuration in my Rules. I use Items for that. These days the only time I need to have a a hashmap is so I can keep track of Timers. Everything else goes in Items.

I’m firmly of the opinion that this does not belong in a binding. Bindings are for providing a means to connect openHAB to external technologies, not for implementing behavior like this. Rules are the appropriate place to implement behavior.

Yes, they should be handled by further refining your rules. In extreme situations (which this is not one) one might consider changes to the rules engine. But adding a binding for this I believe goes against the OH architecture.

This should all be handled in rules.

One thing you may find of interest is that kai is working on a new Rules engine which will be optional in OH 2 that will allow for the creation of generic rules that can easily be shared. Once that is done perhaps a library of reusable rules can be created that implements these sorts of behaviors that users can just drop into their config.

As an exercise I’ll rewrite that Taking Rules to New Heights example to illustrate some of what I’m talking about.

Thanks for your thoughts. Bottomline I actually agree to your points.

It might be that my rules can be optimized. My problem is that I am not native Java programmer, and when working with scripts, the problems is that some logic might be wrong which might be hard to deal with. I like the concept of a compiling stuff. When the compiler doen’t I have fixed all syntax errors. But I agree thats not a argument against making bindings…

I wil definately wait and see what the new rule engine can do and how it can help me. I would like to see some possibility to make reuseable rules. I already use the Group trick, and it is a really powerfull thing.

Right now I will focus on the ZoneMinder binding I am working on :slight_smile:

Rules are not Java. the Rules and scripts are written in a Domain Specific Language that resembles Xtend. They are most definitely not written in Java.

That is true for all programming be it low level assembly to the highest level scripting language.

You should be using Designer for your rules and an IDE for other coding. It checks your syntax as you type. Even with compiled languages you should use an editor that checks the syntax as you type. If you wait until you compile or run something to find syntax errors you are making it harder on yourself.

Good luck with your binding!