I’m trying to set up a rule to pause a Sonos player when a dimmer switch is turned off using the rules engine in the PaperUI. I can run manually and get the Sonos player to pause but the dimmer trigger part is not working.
Is it possible to trigger off of a dimmer? Do I need to do this with a script? Where is the script code created by the rules engine stored? Then I can look at code where half of it works.
Greg, with the information you have provided, I can only guess at how you might approach your problem. As I said above, I have not used the Next Generation Rule Engine (NGRE), so I am at even more of a disadvantage here. We can provide more direct help with less guessing if you provide more information.
Did you try using the “received command XX” trigger type? Also, you haven’t described how the command to your dimmer item is being generated, by a rule or by another physical device?
"label": "an item state changes",
"description": "This triggers the rule if an item state has changed.",
"label": "send a command",
"description": "Sends a command to a specified item.",
"name": "Turn Off Music",
The rules engine UI won’t allow me to change “state”: “OFF”,
“previousState”: “ON” to “state”: “0”,
“previousState”: “100” so I changed it in this file automation_rules.json but apparently it is stored somewhere else because my changes don’t show up in the UI even after restarting Openhab.
Greg, I’m away from home so can’t test or try anything myself, so I have this question:
Does the Command field in the Add Trigger dialog show any other possibilities if you search there? (I see that the help text for that field may show: Add or search.)
If all else fails, you could create a group item with base type Switch, function OR(ON, OFF) and add your office_light item to that group. Then change the item referenced in your trigger to the new group Item:
Also, please review the docs that have been started for the NGRE linked to above. But realize it is labeled “Experimental” for a reason. I’m probably the foremost expert on it who contributes on this forum (at least when it comes to creating Rules through PaperUI) and I don’t know near enough yet to use it well. Those docs are it. If the answer isn’t there you may be on your own.
That being said, your Item is a dimmer but you are trying to trigger the Rule using ON/OFF. You can’t do that (yet?) in NGRE. You have to use state: 0 and not use previous state to make this work as written.
As stated above Dimmers store their state as a Number, not ON/OFF.
You can achieve the previousState: OFF part if you use the but only if condition to test for that. But you can’t do it from the trigger itself.
OH does not watch the JSONDB files and load them on changes. It will only reload them on a restart of OH. But when OH closes nicely, it writes out its internal state to the JSONDB (I think). So it probably overwrote your manual change to the JSONDB.
You must stop OH before making any manual changes to the JSONDB.
This part is a little broken. There are a few enum type commands listed but for everything else you need to manually type in what you want.
There might be a bug there. It would be far from the only one.
So instead of using the State and Previous State fields in the trigger, create a Condition Script with code along the lines of:
office_light.getStateAs(OnOffType.class) == OFF && oldState > 0
If you continue to tr to make this work, I sure could use some help in the docs postings linked to above. They are wikis so if you see anything missing or wrong please feel free to edit the post and make corrections or additions.