We have moved at community.getvera.com

Author Topic: Scripts for Scenes  (Read 1662 times)

Offline torpex77

  • Sr. Newbie
  • *
  • Posts: 46
  • Karma: +4/-1
Scripts for Scenes
« on: November 29, 2015, 12:12:21 pm »
Anybody else using OpenHab scripts as a replacement for Vera Scenes?

For example, I have a rule that fires at 9:00 PM that turns sets my kitchen lights to "night" mode.

Code: [Select]
rule "Night kitchen"
when
Time cron "0 30 21 ? * *"
then
sendCommand(KitchenLightsStatus, OFF)
sendCommand(KitchenTableLightStatus, OFF)
sendCommand(IslandLightsLoadLevelStatus, 20)
end

But I could put that same group of light settings in a OpenHab script, then just just call the script. 

Code: [Select]
rule "Night kitchen"
when
Time cron "0 30 21 ? * *"
then
callScript("night_kitchen")
end

The advantage that all of my light settings are in a single place, and that would make it easier to reuse those settings in other rules - for example to a button on a MiniMote or MultiSwitch.  The alternative would be to have multiple triggers for the rule - Time and Command, but I'm using separate rule files for different things.  My lighting is in one, my remotes in another, etc.  Given that, OpenHab Scripts would seem like the way to go.

Anybody else taking that approach?

Doug

Offline guessed

  • Moderator
  • Master Member
  • *****
  • Posts: 5301
  • Karma: +92/-22
  • Release compat is not a bolted-on afterthought
Re: Scripts for Scenes
« Reply #1 on: November 29, 2015, 01:50:30 pm »
That's the general approach I'm taking as well.  For me, it's limited to the cases where I specifically need to re-use the script.

The Minimote use-case you listed is one of the primary examples in my system.


The other pattern I use a lot is to create a number of specialized Groups that also relate to the Scenes.

Code: [Select]
Group GManagedGoodnight "Goodnight Switches" (GManaged)

and then attach this Group to all the relevant Switches.  You can then use a single line to turn off the relevant Switch items.  In my case, there are ~40 switches being turned off with this single command:

Code: [Select]
GManagedGoodnight.sendCommand(OFF)

This makes my goodnight script simpler, since it's just:

Code: [Select]
GManagedGoodnight.sendCommand(OFF)

Thread::sleep(5000)

GManagedLock.sendCommand(ON)

GManagedSonos?.members.forEach(item |
        sendMiosAction(item, "MediaNavigation1/Stop")
)

harmonyStartActivity("family", "PowerOff")
« Last Edit: November 29, 2015, 09:42:58 pm by guessed »

Offline torpex77

  • Sr. Newbie
  • *
  • Posts: 46
  • Karma: +4/-1
Re: Scripts for Scenes
« Reply #2 on: November 29, 2015, 08:52:15 pm »
I'll have to take a look at groups one of these days.   I know they can do stuff like that, but just haven't used them at all yet for automation purposes, anyway.

Thanks,

Doug

Offline silencery

  • Sr. Member
  • ****
  • Posts: 255
  • Karma: +14/-1
Re: Scripts for Scenes
« Reply #3 on: December 08, 2015, 01:27:05 am »
Using scripts as well for writing information overlays to blue iris macros. The reusability is perfect and overall it works great!