When a rule is triggered I want to store the value two items (name as string / amount as number) with the actual date/time stamp. This happens almost every day.
Last day of the month I would like to generate a list for each person with its corresponding data and the amounts. date/time name amount
xx.xx.xxxx aaa 10
xx.xx.xxxx aaa 20
xx.xx.xxxx aaa 15
Also I would like to sum up the total of that person (in this example: 45).
The monthly summary will be send by email.
What would be the ideal solution for this in a DSL rule? Variables? Text file? Persistence?
I do work with OH since v1.x but I am missing an idea right now.
Would be cool to use TimeSeries and save states with it. At then end of the month filter by state1 and sum up state2 for the complete month.
You’ll need to save these somewhere permanent. The best place to do that in OH is through persistence.
There really isn’t enough information here to give you the best approach. If I assume that the name and amount is dynamic (you can’t know them ahead of time) and only Rules DSL (which these days is increasingly limited in capability compared to the other options) my recommendation would be to set up persistence with something that supports Strings (not MapDB nor rrd4j).
Create a String Item that will hold it’s state as name/value. Configure persistence to save on every update.
If there is some event that occurs at the timestamp you want to save the name/value then just create a rule that triggers on that event and postUpdate the name/value to the String Item.
If there isn’t an event, whenever you decide to save the value/values you can use MyStringItem.persist(timestamp, 'name/value') to save the value at the given timestamp in the database.
At the end of the month, you’ll query for all the values between the first day of the month and the last day of the month, iterate through the entries and do what ever calculations you need to do.
Thank you very much for your approach. Yes, I do know that DSL is not the prefered solution anymore but since I started with OH 1.x I have lot’s of rules and still love them. They still work (using 5.0.1) and I was always able to find a solution of what I needed.
Your recommendation sounds good. I thought of that as well but was hoping to get around the combination of two items, persist them and then devide them as again.
I will give it a try. Thank you!!
Just to explain the scenario once more (for those trying to understand what I would like to achieve - more or less)…
I have an item called “name/id” and “amount”.
About once a day one or several persons (independently) may trigger the rule. In that moment a variable will have their name and another variable will have an amount corresponding to this person. They rule is triggered for each person and not a group.
So when the rule gets trigger I know the persons name “A” and amount “10”. 10min later the rule may be triggered by person “B” with amount “42”. The number of persons is not limited but each person identified by its unique id.
At the end of the month I would like to have a summary of all entries for each person meaning I would like to send each person an email with it’s list (shown above as sample) and the person’s summary of the latest month.
Weird sample but just trying to avoid going into detail and not to make it to complicated.
I got one more question regarding the peristence of an item because I am getting a warning no matter what I try - and I cannot find a “hint” by searching through the community posts.
my current rule:
var String txt2persist = “name1;18;testtext”
itemsname.persist(txt2persist, now())
*var content just as a sample
log: [WARN ] [nce.extensions.PersistenceExtensions] - There is no persistence service registered with the id 'name1;18;testtext’
What am I doing wrong here?
I am using InfluxDB as the standard database.
<item>.persist(ZonedDateTime, State) Persists a past or future state for the Item
But if you are persisting a state for now usually you’d just configure your persistence strategies as approprioate and just postUpdate the value to save to the Item.