We have moved at community.getvera.com

Author Topic: Any plans to add an openHAB Action binding for using MiOS Items in Rules  (Read 5228 times)

Offline lolodomo

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3484
  • Karma: +74/-10
Happy new year to all.

I am using a HTTP request in my rules to call some Vera actions to control Sonos (play something and TTS). That works well.

@guessed: Any timeline for adding a Vera action binding (with multiple parameters) ?

Offline guessed

  • Moderator
  • Master Member
  • *****
  • Posts: 5301
  • Karma: +92/-22
  • Release compat is not a bolted-on afterthought
Re: Any plans to add an openHAB Action binding for using MiOS Items in Rules
« Reply #1 on: January 02, 2015, 05:36:13 pm »
I am using a HTTP request in my rules to call some Vera actions to control Sonos (play something and TTS). That works well.

@guessed: Any timeline for adding a Vera action binding (with multiple parameters) ?

I hadn't put a timeline to it, as I'd switched to building an openHAB binding for my Paradox Alarm, but I took a quick look at what it could look like, syntax-wise in Xtend (openHAB's rule language).

The notes from this are below, for comments (to ease the steps required when I get around to implementing it)

A few things I tried didn't work out, so I'm not sure how complete the XTend implementation is in openHAB, or whether perhaps it's just that those features weren't available in the version of XTend that openHAB is using.  In most cases, when it didn't work, the Rule engine stopped (silently) so it was a lot of trial and error.

Initially, I wanted to use XTend's Collections, notably this construct:

Code: [Select]
    val myMap = #{'a' -> 1 ,'b' ->2}
and apply a UPnP bent to it, so you'd end up with something like:

Code: [Select]
val sayParams = #{'Text' -> 'Hello from Sonos' ,'Volume' -> 50}
which would have looked a lot like luup.call_action parameters, but I couldn't get that working for the life of me, so eventually I used the more explicit form:

Code: [Select]
val sayParams = newArrayList('Text' -> 'Hello from Sonos' ,'Volume' -> 50)


Putting it together, the overall call structure would look something like:

Code: [Select]
    callMios(OfficeSonosId, "Sonos/Say", newArrayList('Text' -> 'Hello from Sonos', 'Volume' -> 50))

    // or their syntactic sugar version:
    OfficeSonosId.callMios("Sonos/Say", newArrayList('Text' -> 'Hello from Sonos', 'Volume' -> 50))

In both cases, I'd use the Item as the handle to get ahold of both the MiOS Unit as well as the Device Id within that Unit.  I hadn't planned to use the rest of the Device/Service identification information... but I could possibly default the UPnP ServiceId from that IF it's not been specified in the Command itself (as above "Sonos/Say", where "Sonos" would be the serviceId alias that we've used elsewhere)

For the most part, I'd like to avoid putting the direct Device Id into the MiOS Rule API, as this would make it brittle when devices are changed out.  That's the motivation for using the Item here, even though some of the Item information really isn't needed.

Thoughts?

Offline lolodomo

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3484
  • Karma: +74/-10
Re: Any plans to add an openHAB Action binding for using MiOS Items in Rules
« Reply #2 on: January 03, 2015, 03:54:55 am »
That looks good for me.

No urgency as we already have a workaround.

PS: I started yesterday to setup IDE  ;)

Offline guessed

  • Moderator
  • Master Member
  • *****
  • Posts: 5301
  • Karma: +92/-22
  • Release compat is not a bolted-on afterthought
Re: Any plans to add an openHAB Action binding for using MiOS Items in Rules
« Reply #3 on: January 21, 2015, 05:53:02 pm »
Putting it together, the overall call structure would look something like:

Code: [Select]
    callMios(OfficeSonosId, "Sonos/Say", newArrayList('Text' -> 'Hello from Sonos', 'Volume' -> 50))

    // or their syntactic sugar version:
    OfficeSonosId.callMios("Sonos/Say", newArrayList('Text' -> 'Hello from Sonos', 'Volume' -> 50))
...

Just an update on the support for scripted MiOS calls in openHAB Rules...

I have first-cut prototype of this working.  I made some tweaks along the way, and the code is messy and not ready to be rolled back into the mainline, but the core of it works.

I have a test-rule that looks like:
Code: [Select]
rule "Test action rules Off"
        when
                Time cron "4/5 * * * * ?"
        then
                sendMiosAction(GuestBedroom2LightsId, "Dimmer/SetLoadLevelTarget", newArrayList('newLoadlevelTarget' -> 0))
end

rule "Test action rules On"
        when
                Time cron "2/5 * * * * ?"
        then
                sendMiosAction(GuestBedroom2LightsId, "Dimmer/SetLoadLevelTarget", newArrayList('newLoadlevelTarget' -> 100))
end

and it does preity-much what you'd think it would do...  ;)

I changed the Action name to sendMiosAction (and sendMiosScene) to be more consistent with the naming used for the existing openHAB Action extensions.

The remaining things to do before pushing them to Git and submitting a PR are:
  • P1 Cleanup the code structure, since it's currently awkward with the tweaks made to allow the MiOS Action [OSGi] Add-on to talk to the MiOS Binding [OSGi] Add-on.
  • P2 Add some sort of Command-queue for HTTP calls sent to the MiOS Unit, to avoid failures due to too many threads hitting on Vera at the same time.
  • P3 Work out why the syntactic-sugar version (eg. GuestBedroom2LightsId.sendMiosAction(...)) doesn't work.

Depending upon how much spare time I have, I may submit after P1 and work later on P2 & P3.

If anyone really wants to try out this version, let me know as I haven't updated the online JAR version of it in a while now.

Offline guessed

  • Moderator
  • Master Member
  • *****
  • Posts: 5301
  • Karma: +92/-22
  • Release compat is not a bolted-on afterthought
Re: Any plans to add an openHAB Action binding for using MiOS Items in Rules
« Reply #4 on: January 22, 2015, 03:25:16 pm »
Submitted MiOS Action Binding as PR #2025 in order to get initial code-review comments, and a "build" version of it in the 1.7.0 code line.

Until it's merged, you can read the Documentation for the new Action methods here:
    https://github.com/mrguessed/openhab/tree/mios-action-binding/bundles/action/org.openhab.action.mios


There are still a few items on the todo list, but I wanted to get a version out early, since folks have been pinging me for this.

Offline nwootton

  • Newbie
  • *
  • Posts: 9
  • Karma: +1/-0
Re: Any plans to add an openHAB Action binding for using MiOS Items in Rules
« Reply #5 on: January 22, 2015, 04:34:03 pm »
@guessed

A heartfelt thank you for this. Roll on release 1.7!

Offline guessed

  • Moderator
  • Master Member
  • *****
  • Posts: 5301
  • Karma: +92/-22
  • Release compat is not a bolted-on afterthought
Re: Any plans to add an openHAB Action binding for using MiOS Items in Rules
« Reply #6 on: January 22, 2015, 04:40:13 pm »
@guessed

A heartfelt thank you for this. Roll on release 1.7!

You're welcome!  I figured it was better than wasting folks time by having them build the work-arounds ;)

Offline shmixx

  • Full Member
  • ***
  • Posts: 171
  • Karma: +2/-1
Re: Any plans to add an openHAB Action binding for using MiOS Items in Rules
« Reply #7 on: January 22, 2015, 07:35:00 pm »
Ok my apologies @guessed - can you provide the shorthand of what the main benefit is of this new callMios() capability over the sitemaps/items I'm already using? I hadn't followed the whole thread and it may be difficult trying to find the value in the thread this far out. :)

PS - for anyone who has been hoping we would one day have a ZWave based LED bulb, I recently found one on Amazon - http://www.amazon.com/gp/product/B00PJH16UC/ref=oh_aui_detailpage_o06_s00?ie=UTF8&psc=1
While they are expensive, they operate with the Vera. Though I did have to turn off the Auto Configure function because it kept coming up with errors. It works though and had full dimming capability. I personally use them for nightstand lights and will be setting rules to gradually dim the lights as it gets later. Helping to ease the bedtime rituals and getting in bed at a reasonable hour!
« Last Edit: January 22, 2015, 07:38:07 pm by shmixx »

Offline guessed

  • Moderator
  • Master Member
  • *****
  • Posts: 5301
  • Karma: +92/-22
  • Release compat is not a bolted-on afterthought
Re: Any plans to add an openHAB Action binding for using MiOS Items in Rules
« Reply #8 on: January 22, 2015, 09:03:32 pm »
Ok my apologies @guessed - can you provide the shorthand of what the main benefit is of this new callMios() capability over the sitemaps/items I'm already using? I hadn't followed the whole thread and it may be difficult trying to find the value in the thread this far out. :)

The declarative SiteMaps/Items mechanism are the easiest approach to integration, and will handle most user's needs.

But there are cases where you need to explicitly call you Vera unit during a Rule execution and/or where the form of that call isn't a simple, single-parameter, Bind.

eg. Any UPnP-style call with more than one parameter
eg. Any UPnP-style call where you want to compute a value and pass the parameter value more explicitly.

There are a couple of UPnP API's floating around that have more than one parameter, and here are a few examples:
  • the Say method of @lolodomo's Sonos Plugin
  • the SetPollFrequency(PollingEnabled,PollMinDelay) action of some HaDevice1 ServiceId's
  • the RequestArmMode (State,PINCode) action of urn:micasaverde-com:serviceId:AlarmPartition2

For these, you'll need an openHAB Rule, and the sendMiosAction(...) call...

Offline guessed

  • Moderator
  • Master Member
  • *****
  • Posts: 5301
  • Karma: +92/-22
  • Release compat is not a bolted-on afterthought
Re: Any plans to add an openHAB Action binding for using MiOS Items in Rules
« Reply #9 on: February 23, 2015, 09:41:37 pm »
Submitted MiOS Action Binding as PR #2025 in order to get initial code-review comments, and a "build" version of it in the 1.7.0 code line.

Until it's merged, you can read the Documentation for the new Action methods here:
    https://github.com/mrguessed/openhab/tree/mios-action-binding/bundles/action/org.openhab.action.mios


There are still a few items on the todo list, but I wanted to get a version out early, since folks have been pinging me for this.

This PR has been approved, and will be available in Cloudbees  Nightly build tomorrow, allowing users to perform the sendMiosAction() within Rules.

The merged Documentation is here:
    https://github.com/openhab/openhab/blob/master/bundles/action/org.openhab.action.mios/README.md

I will update Forum links when I get a few cycles.


I've also uploaded new Untested build, including:
  • this openHAB Action change AND;
  • pre-merge changes for reducing the logs (and Item Change events) generated by openHAB PR #2183

for those not wanting to wait, esp for the log/update optimizations.  *Both* JAR files are needed if you want to use the new MiOS Actions within Rule files.
« Last Edit: February 23, 2015, 09:44:32 pm by guessed »

Offline lolodomo

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3484
  • Karma: +74/-10
I just tried the new sendMiosAction to call either Sonos/Say or Sonos/PlayURI and it is working well 8)

The only problem I have is that in openHAB Designer, I get an error "Couldn't resolve reference to sendMiosAction".

For information, I have not the same error when I use sendHttpGetRequest.

My imports in my rule file are only
Code: [Select]
import org.openhab.core.library.types.*
import org.openhab.model.script.actions.*
import org.joda.time.*
import java.util.regex.Matcher
import java.util.regex.Pattern

I just replaced the two new 1.7 jars in my 1.6.2 setup.

Any idea ?

Offline gduprey

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

I'm dealing with this too (the fact the designer doesn't recognize the action).  It appears that the actions are pretty embedded into the designer and adding a new one isn't trivial.  That said, I'm trying and think I've found most of the places that the designer is looking.  I have an active query going on the OH google groups and hope to get something soon.

https://groups.google.com/forum/#!category-topic/openhab/hhL0wUakpko

Once I find out what has to be done, I'll post back here.

Gerry

Offline lolodomo

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3484
  • Karma: +74/-10
Just an idea: maybe we should use designer v1.7 ?

Offline lolodomo

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3484
  • Karma: +74/-10
@gduprey: the bug seems to be fixed in Designer 1.7.

Offline guessed

  • Moderator
  • Master Member
  • *****
  • Posts: 5301
  • Karma: +92/-22
  • Release compat is not a bolted-on afterthought
@gduprey: the bug seems to be fixed in Designer 1.7.

That's good news, thanks for updating @lolodomo!