You can keep track of the time in rules and update an Item while the switch remains ON. You can use the previousState(true) method on the Item to figure out when the Item most recently changed state and use that to update an Item.
There is no way to directly query the database from rules.
Hello Rich,
may be this post is out of date but for me still not being clear if now is possible to query database directly from rules.
For example, I have an influxdb database where I store the desired temperature of my house during the different seasons.
I have a rule for switching on an off my heating/cooling system, and in this rule I activate my system doing a comparison of the current temperature with a “temperature set point”. I would like to get this setpoint from the database depending of the season.
Does exist already a direct way to do that? If not I suppose the best solution is to implement some script to cast the variable value?
The limited set of queries avalable in rules for use with persistence includes historicState() , which allows you fetch the state of an Item at a specific moment in time.
If there’s no data for that exact moment, the next-previous state is fetched (on the basis that it hadn’t changed since)
I don’t understand what you’re up to - fetching last year’s enviro data as a starting point for today?
Not all the persistence services support al the functions.
I´ve readen the post about persistence before but I was wondering if there is a better way. Because the information that I have in my database is not related with states of an Openhab´s Item.
In my database the information is like that:
Month Temperature Objetive
January 25ºC
February 24ºC
and so on…
This example it´s simple and someone could just say: “Why you dont write that directly in the rules”
But the problem is that I have this information according to each room, the kind of use of the room and the occupacy… That´s why i´m trying to have like a “fix code” in openhab which activate and desactivate the heating/cooling system depending of one variable which i´m getting from different database depending the room.
Then you cannot use openHABs persistence services with it.
There are no other built in methods to get arbitrary data from any database.
You’d have to script it.