Hello,
I am muddling through rules with hard earned success overall. My latest rule is one that updates family member’s cellphone’s LastUpdate item, a DateTime type, at each state change. I couldn’t find an example of how to write it in one rule so I wrote 4 rules, 1 for each phone:
rule "Update User1 Last-Seen Time"
when
Item Presence_Mobile_User1 changed
then
User1_LastUpdate.postUpdate(new DateTimeType())
end
Is there a way to write a single rule that will update a phone when it changes state?
BTW, I created a group with all 4 phones but I don’t know how to update an individual phone when the group item receives an update (It is a Group:SwitchOR type of group)
This lead me to a bigger question. How can I further educate myself on writing rules? Would it be helpful to read a “Java for Dummies” book in order to learn the syntax rules and features of Java? (I know rules uses XTend but it would be a start.)
Since you already have a group, you can enumerate all items from a rule.
See
Inside your rule you then can check the current items state vs. the previous state (persistance needed) and then update the item.
I think the best way to educate yourself is actually to do something with your OpenHab. Learn from examples/solutions in the forums, try different things out and so on.
No need to be a JAVA expert in my opinion.
This is not tested and may contain some errors, but this is basically the easiest way since openHAB2.2
rule "Update User1 Last-Seen Time"
when
// this will get easier in future when the group trigger is accepted
// and added to the distribution, then only the group has to be listed
Item Presence_Mobile_User1 changed or
Item Presence_Mobile_User2 changed or
Item Presence_Mobile_User3 changed
then
var time = new DateTimeType()
postUpdate( triggeringItem.name.toString , time.toString)
end
there are some things which maybe will be of interrest in following threads, for your rules. I tried to add as many explanations as a could.