We have moved at community.getvera.com

Author Topic: Invoking ISY994i commands from OH rules?  (Read 3007 times)

Offline gduprey

  • Beta Testers
  • Full Member
  • *****
  • Posts: 122
  • Karma: +6/-1
Invoking ISY994i commands from OH rules?
« on: March 09, 2015, 09:28:34 am »
Howdy,

I'm just getting my feet wet in the world of using the MiOS actions and not 100% sure yet the best way to use them or how to map things to a action call.

I have the ISY994i plugin running on my Vera and it works great.  One of the abilities the plugin provides to vera/lua code is the ability to directly execute a ISY program on the ISY unit from the Vera.

As I move logic off the vera, I'd really like to be able to do this from an OH rule.  The ISY plugin has a 'runProgram' action that takes a program number (4 digit hex) and a program path (a string, usually 'run', but can be other things).

Any recommendations on best way to approach this (or at least start investigating this) as an action from a OH rule?

Thanks!

Gerry

Offline gduprey

  • Beta Testers
  • Full Member
  • *****
  • Posts: 122
  • Karma: +6/-1
Howdy,

Doing this my first time -- hope this doesn't sound too stupid:

1) The mios action I want to call is 'runProgram' and the UPnP section is "urn:garrettwp-com:serviceId:ISYController1".  With that, I'd call it like callMiosAction([theIDItem], 'ISYController1/runProgram', newArrayList(.....)), correct?  Or do I need to put the entire "urn:garrettwp-com......./runProgram"?

2) The "item ID" 1st parameter -- is that a number or an Item.  I have an item called ISYControllerId which is the ID item for that Vera device.  Do I pass it, it.state (i.e. ISYControllerId.state) or the actual vera device # in the 1st parameter?

3) Do I just use the call 'sendMiosAction(.....)' in the rule?  Do I need to import anything and/or qualify anything?  I added that latest mios binding/action jars to the designers addons/ directory but it's flagging my call as having errors saying it can't resolve sendMiosAction.  My exact code is:
Code: [Select]
sendMiosAction(ISYControllerId, "ISYController1/runProgram", newArrayList('program' -> '006A', 'path' -> 'run')) 

4) The docs/README.md examples show both a sendMiosAction() call and a sendMios() call (no "Action" in it).  Are both allowed?  (I tried both forms and the designer complained for both of them).

Thanks!!

Gerry
« Last Edit: March 09, 2015, 03:30:37 pm by gduprey »

Offline guessed

  • Moderator
  • Master Member
  • *****
  • Posts: 5301
  • Karma: +92/-22
  • Release compat is not a bolted-on afterthought
Re: Invoking ISY994i commands from OH rules?
« Reply #2 on: March 09, 2015, 03:24:42 pm »
That's probably best handled by the MiOS Action Binding, within a openHAB Rule, which you can get from the 1.7 Cloudbees path.  The README for that Binding is here:
    https://github.com/openhab/openhab/blob/master/bundles/action/org.openhab.action.mios/README.md

Assuming you've already Bound an Item to the correct DeviceId in Vera, then it would be something like:
Code: [Select]
    sendMiosAction(IsyId, "urn:garrettwp-com:serviceId:ISYController1/runProgram", newArrayList('program' -> 'DEAD', 'path' -> 'run'))

The quickest way to find out what a MiOS Device exposes in UPnP is:
    http://192.168.x.y:49451/data_request?id=invoke

and then surf the tree until you come across the relevant part.

Offline guessed

  • Moderator
  • Master Member
  • *****
  • Posts: 5301
  • Karma: +92/-22
  • Release compat is not a bolted-on afterthought
Re: Invoking ISY994i commands from OH rules?
« Reply #3 on: March 09, 2015, 03:27:28 pm »
I merged your topic posts, since they're related.

Offline gduprey

  • Beta Testers
  • Full Member
  • *****
  • Posts: 122
  • Karma: +6/-1
Re: Invoking ISY994i commands from OH rules?
« Reply #4 on: March 09, 2015, 03:34:14 pm »
Thanks for the answer!  I was editing my post just as you merged it, so there may be stuff in there you didn't see before.  I think it was only 3)  OH Designer complains about the call and 4) the small difference in the README.md for the actions.

Thanks again -- I'm really appreciating everything I can do with the Vera/OH combo!!

Gerry

Offline guessed

  • Moderator
  • Master Member
  • *****
  • Posts: 5301
  • Karma: +92/-22
  • Release compat is not a bolted-on afterthought
Re: Invoking ISY994i commands from OH rules?
« Reply #5 on: March 09, 2015, 03:35:53 pm »
Quote
1) The mios action I want to call is 'runProgram' and the UPnP section is "urn:garrettwp-com:serviceId:ISYController1".  With that, I'd call it like callMiosAction([theIDItem], 'ISYController1/runProgram', newArrayList(.....)), correct?  Or do I need to put the entire "urn:garrettwp-com......./runProgram"?
See above.  There's no UPnP alias defined for a number of the Custom Plugins and, for these cases, the fully spelled out UPnP ServiceId is needed.

Quote
2) The "item ID" 1st parameter -- is that a number or an Item.  I have an item called ISYControllerId which is the ID item for that Vera device.  Do I pass it, it.state (i.e. ISYControllerId.state) or the actual vera device # in the 1st parameter?

The "*Id" Item is a Number type.  You pass an Item as the first parameter, and not the Item's State.

Technically, you can use any Items bound to that Device in Vera, since I'm only using them to get the [MiOS] device-id handle required by the MiOS Communications layer. In openHAB 2.x, these calls would likely be made against the "Thing", not the "Channel", since that's a closer match to a Vera Device.

I did it this way to avoid polluting the openHAB Rule file with [Non-Item] references to where Vera is (eg. URL's, etc)

Offline guessed

  • Moderator
  • Master Member
  • *****
  • Posts: 5301
  • Karma: +92/-22
  • Release compat is not a bolted-on afterthought
Re: Invoking ISY994i commands from OH rules?
« Reply #6 on: March 09, 2015, 03:42:53 pm »
Quote
4) The docs/README.md examples show both a sendMiosAction() call and a sendMios() call (no "Action" in it).  Are both allowed?  (I tried both forms and the designer complained for both of them).

That's a Doc throwback.  It was originally sendMios(), and then I made it sendMiosAction() so I could add others as needed.  The Doc section on "Extensions" has them listed correctly.

Quote
3) Do I just use the call 'sendMiosAction(.....)' in the rule?  Do I need to import anything and/or qualify anything?  I added that latest mios binding/action jars to the designers addons/ directory but it's flagging my call as having errors saying it can't resolve sendMiosAction.  My exact code is:

I've never used the Designer, so no idea why it wouldn't pick it up there.  All my work is done with the CLI  ;-)

Offline gduprey

  • Beta Testers
  • Full Member
  • *****
  • Posts: 122
  • Karma: +6/-1
Re: Invoking ISY994i commands from OH rules?
« Reply #7 on: March 09, 2015, 03:55:44 pm »
Thanks again -- I'll just test it.

I generally avoid the designer too, but I haven't found a good way to 'test' rule logic quickly.  The designer, hobbled though it may be, will at least bitch about obvious things (unknown items, typos, missing imports, etc) giving me a shot at a rule that likely works first time around.  I code mostly in emacs, but open things in the designer as a 'sanity' check before uploading the rules to my OH server.

Gerry

Offline guessed

  • Moderator
  • Master Member
  • *****
  • Posts: 5301
  • Karma: +92/-22
  • Release compat is not a bolted-on afterthought
Re: Invoking ISY994i commands from OH rules?
« Reply #8 on: March 09, 2015, 04:03:40 pm »
MiOS Action(s) are only implemented in the 1.7 line.  If you're using them, you'd need to be using a Designer from that line also.

For testing Rules, I use vi on a [new] Rule file with a Time/cron driving it every few seconds.  You can edit it, and see if it's correct or not using another window that's tailing logs/openhab.log (or another shell-pane if you're using emacs). 

It's quick, simple and fast (my favorite friends)  ;)

Offline guessed

  • Moderator
  • Master Member
  • *****
  • Posts: 5301
  • Karma: +92/-22
  • Release compat is not a bolted-on afterthought
Re: Invoking ISY994i commands from OH rules?
« Reply #9 on: March 09, 2015, 08:47:50 pm »
Doc bug on MiOS Action has been fixed:
    https://github.com/openhab/openhab/pull/2266