Trouble triggering off of dimmer

rules
Tags: #<Tag:0x00007fe053fe1948>

(Greg) #1

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.

Thanks


(Scott Karns) #2

Hi, Greg (@TexasGreg). It is possible to trigger on a change of state to a Dimmer item. It will be easier and faster to help you if you can post your rule here.


(Angelos) #3

and check all the hard work that @rlkoshak did to write up this series:

It will help you with a lot of your questions


(Rossko57) #4

Bear in mind that a Dimmer type Item doesn’t go to OFF state, but to zero.


(Greg) #5

Yes rossko57 I tried putting 0 as the state to check for and it would not save in the rules engine.


(Scott Karns) #6

I have yet to play with the NGRE via PaperUI. In a rule, is it not possible to use an expression like this:

myDimmerItem.getStateAs(OnOffType.class) == OFF

After all, a Dimmer item is a subclass of a Switch item.


(Greg) #7

Scott I was able to change to trigger off of just a change in state of the dimmer and it worked so I just need to figure out how to let it know to only trigger when the state goes to zero.


(Scott Karns) #8

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?


(Greg) #9

Scott this is what the rules engine creates:

 {
  "bf36643a-9839-49d2-887b-7f6aa49bcdcc": {
    "class": "org.eclipse.smarthome.automation.dto.RuleDTO",
    "value": {
      "triggers": [
        {
          "id": "3",
          "label": "an item state changes",
          "description": "This triggers the rule if an item state has changed.",
          "configuration": {
            "itemName": "office_light",
            "state": "OFF",
            "previousState": "ON"
          },
          "type": "core.ItemStateChangeTrigger"
        }
      ],
      "conditions": [],
      "actions": [
        {
          "inputs": {},
          "id": "2",
          "label": "send a command",
          "description": "Sends a command to a specified item.",
          "configuration": {
            "itemName": "sonos_CONNECTAMP_RINCON_000E5F6F201400_control",
            "command": "PAUSE"
          },
          "type": "core.ItemCommandAction"
        }
      ],
      "configuration": {},
      "configDescriptions": [],
      "uid": "bf36643a-9839-49d2-887b-7f6aa49bcdcc",
      "name": "Turn Off Music",
      "tags": [],
      "visibility": "VISIBLE"
    }
  }
}

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.


(Scott Karns) #10

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:

Group:Switch:Or(ON, OFF)  g_office_light
...
Item Dimmer               office_light     (g_office_light)

(Rich Koshak) #11

This is indeed possible.

Put 0 in the “state” field of the trigger.

If you want something more elaborate (e.g. only trigger the rule when the Dimmer goes above 50, use the “but only if…” section.

Please How to use code fences even for posting JSON formatted code like this.

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.


(Scott Karns) #12

Thanks, Rich. I was in the middle of amending my reply to request the use of code fences.


(Greg) #13

It has presets like OPEN, CLOSE, OFF, ON, UP, DOWN and allows me to manually put just about anything but a zero.


(Rich Koshak) #14

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

NOTE: I’ve done next to nothing with Condition Scripts so I’m not 100% positive this will work. I’m also not yet certain if I can just do a > using oldState without converting it to some sort of JavaScript number type.

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.