So I’m rather inexperienced with openHAB, but I’ve been testing the persistence bindings and so far have not seen a solution to load values from queries or write specifics things into a database. I concluded that a workaround could be using the exec binding, but I’m not sure how to go about doing that. I considered making preset commands with queries where I use the name of the item as the ID I’m searching for in the database. If anyone more experienced could tell me if there is a cleaner / easier way of approaching this I’d be grateful.
Another question is that is it possible to trigger interrupts caused by certain item states or rules, to be able to make some actions priority, instead of waiting for updates?
That is because OH does not support this sort of thing. The interface to persistence is strictly through Items. You cannot perform arbitrary queries nor can you perform arbitrary transactions.
What specific values are you after? If it is historic data from a specific Item you have a number of methods on Items in Rules to query for past data such as previousState, historiState, minSince, etc. See http://docs.openhab.org/configuration/persistence.html#persistence-extensions-in-scripts-and-rules
Please provide more details about what you are trying to accomplish. My kneejerk response is “no” but there is enough ambiguity in your question there might be a way.
Thanks for the reply!
I’m after some string values that I can compare in if statements. I am trying to test a color scanner and weight measure attached to my raspberry pi. I have a database with item names as IDs, after scanning I would search the database for the selected ID and flash a green led if the weight and color matches the weight and color for the specific ID in the database. So far I managed to create a command that does that and returns the string I want to compare in my if statement, so I tried using executeCommandLine in a rule to acquire the result, but the SQL command contains quotation marks which seem to conflict with executeCommandLine and I have not found anything on how to escape special characters in rules, so I seem to be stuck again.
About the interrupts, for example I mean that I have a system that is running several sensors, one of which is a PIR sensor and if there is motion I want to be notified of it immediately rather than after it read all the other not too important sensors, so instead of waiting on an update which I right now do with listening on mqtt I was wondering if there is a way to cause an interrupt which triggers a rule concerning a specific item immediately.
" usually works. If not you might need to double escape it \"
For the interrupts your description belies perhaps a misunderstanding about how rules work. ALL roles are interrupt driven. The when clause lists all the events that will trigger the rule to run. So
rule "PIR triggered"
Item PIR changed
//PIR changed code
will trigger immediately when ever the Item PIR changed state. There is no waiting around. But if your sensor waits before reporting that is something you need to manage in the sensor. There is nothing OH can do.
Maybe this is interesting for you. I write custom stuff to a MariaDB database for logging purposes. Using the same approach you can also read stuff.