Paperui rules engine usage

That button makes a REST API call something like this…

http://localhost:8080/rest/rules/9ede01b8-bbb7-43a1-9679-1fad663b7090/runnow

… which executes RuleEngineImpl.runNow(ruleUID, false, null). This then gets down to…

executeActions(rule, false);

… which just executes the rule’s Actions. In your case, this is turning off the soundbar. Even if you have Conditions that aren’t met (you don’t happen to have any), the Actions will still execute. The Triggers are not part of the equation. So, everything appears to be working as expected. :slight_smile:

@5iver Thanks for the explanation. This is making more sense now but if I have to evaluate that the rule should fire only when the Iphone is on then how do I do that because you’re saying that I don’t have the condition defined in my rule to check for the Phone but the when condition isn’t it ensuring that the Phone Channel online has to be online. Is there a way to evaluate Phone Online channel to see if it is True or False?

If your rule is working, then why do you need to evaluate the phone’s state in the Action? I’m thinking there must be some pieces to the puzzle that you have not shared. :slight_smile: Maybe you want to execute the Action from another rule? If so, just add a Condition to the other rule to check if your phone Item’s state.

If you are wanting to evaluate the state of Items in your Action, then you will need to use the ‘execute a given script’ Action, and use JS to add conditional logic to the Action. @rlkoshak has put together a series of posts about using the new rule engine with Paper UI, and I think here may have covered this.

@5iver I may have not explained correctly in the beginning but my only Use Case is that if my Phone is disconnected form the Wifi then shutdown my soundbar which also controls my TV.

The next thing would have been to configure me and my wife’s phone (by grouping them) and then the rule should evaluate that if both phones are not on network then close all home lights.

Now what I was thinking and may be I am wrong is that online channel of phone has two states 1 or 0 just like any network binding thing has. If it is on network then it is True and if it is disconnected then it is 0.
Here’s I am monitoring it. I have created a Switch Widget for Online Channel for both me and my wife’s phone and I was hoping that the rule should work when the phone turns off or either 0 in binary.

The screenshot shows that I have disconnected my Phone WIFI and it turned Red and I am assuming this means it is in 0 state and the ideal Use Case would be to check both phones and if they are off then turn the sound bar and other lights off.
The other challenge that I have is I am not able to figure out how to create a group switch and link these two phones to it so that I can use that group switch in my Rule “When” condition.

presence

There are supported states for each Item type. For SwitchItem, the states are ON, OFF, and NULL.

You can create a group like this, and then add you phones to the group. When all phones are OFF, the group will be OFF. When either phone is ON, the group is ON. Then, use a state change on the group to trigger your rule.

Group:Switch:AND(OFF,ON)    gPhone    "Phones [MAP(presence.map):%s]"    <present>

Group functions are very powerful, and allow you to use them for a lot the logic that you would need to add to your rules. I use them heavily, and have been able to reduce ALL of my lighting rules (and sound) to just a single rule! Here are some handy truth tables I put together to help with understanding the logic (I need to get them into the docs).

1 Like

@5iver wasn’t able to understand earlier as well the following would create a Group Switch but how do I add phone to it?

Do I need to add network:pingdevice:a7eb819b:online to it or it should be the label of the item ? Is there a specific command? I wasn’t able to find many details on how to add two items to the Group

Group:Switch:AND(OFF,ON) gPhone “Phones [MAP(presence.map):%s]”

Is there any example code that I can follow to add phones to this group?

This depends on whether you have your Items in files…

… or if you created them in Paper UI…

I have created them in Paper UI but I have simple mode turned off or either on and I don’t see the option to add a parent group. I only see things with linked channels. I dont see items and if I turn that mode on then I see items but it messes up some other config. Do you have the sample code for the things file?

If you have Simple Mode turned on, you will need to turn it off to edit your Items, because they will not be visible until you do. You should be able to turn off Simple Mode, edit your Items, and then turn it back on. If you choose to use an Items file, you will need to delete the phone Items in Paper UI, which will also require you to turn off simple mode.

Please provide more details on what configuration is messed up when you turn off Simple Mode. Maybe there is a bug. IMO, Simple Mode causes more issues than it resolves. :wink:

There is no Things file needed… it is an Items file, and there are examples in the documentation I linked to.

Last time when I changed the mode my Nest had stopped working and I had to reconfigure it. But you’re right it is easy with Items tab available. Let me try and I’ll provide the results.

Okie so I did create a Group switch manually by going to Items file then I turned the simple mode off and now I see Items. I went to the item to update the parent group and the field is disabled.

Something isn’t right, even I deleted and recreated my Phone and then when I tried to add the group it never saved it.

Have you created the group Items?

I created a group item in items file like this.

Group:Switch:AND(OFF,ON) gPhone “Phones [MAP(presence.map):%s]”

Delete it and create it in Paper UI… that way you will have all your Items in one place. You probably have an error in your log, since you probably don’t have the MAP transformation service or a presence.map file. Due to the error, the group would have not been created, which explains why you can’t add the phone Items to it.

Success, I tried it with PaperUI and I am able to create it. Looks good so far.

For MAP transformation service or a presence map file. What has to be in those?

To start with, nothing. You could add these in later. Remove from the definition.

Also for the group to check if both Phones are off which function should work?

As in how do you map with the following

The first one.

and UNDEF.

:+1 I hate simple mode. I spend more time helping people figure out problems caused by their use of Simple Mode than almost anything else.

In more expanded English:

  • All ON → ON else OFF | If all members of the Group are ON, the Group state will be ON. In all other cases the Group will be OFF.
  • All ON → OFF else ON | If all members of the Group are ON, the Group state will be OFF. In all other cases the Group witll be ON.

and so on.

1 Like