We have moved at community.getvera.com

Author Topic: Program Logic (Timer and Event Generator) Beta  (Read 6042 times)

Offline RichardTSchaefer

  • Moderator
  • Master Member
  • *****
  • Posts: 10091
  • Karma: +764/-143
Program Logic (Timer and Event Generator) Beta
« on: January 13, 2013, 01:35:49 pm »
The next phase of the Program Logic Plugins is available.
This allows you to use ANY variable in a Vera device in a condition expression ... and subsequently to trigger an event. If the variables you select are changed, the condition expressions are evaluated.  Condition expressions can now be any combination of Triggers, Schedules, and/or Device Variables

i.e. you can create a trigger when two variables are different from each other by some amount.
Bind UpperTemp to upstairs temp sensor
Bind DownTemp to lower level temp sensor
Condition:
      HvacOn = (UpperTemp - LowerTemp > 5.1) and  (not (08:00:00; UpperTemp; 16:00:00))

This condition turns on the Hvac if the temperature difference is > 5.1 degrees at night.
This also shows the last change of a Device Variables can be used in a sequence expression.

Or how about a Vera Alert if the Weather station quits working:
Bind OutSideTemp to Weather Plugin outside temp variable.
Condition:
    WeatherStationTimeOut = OutSideTemp;NOW > 2:00:00

Events based on temperature and lighting levels are now easily manageable.

Prior to this variables in condition expressions were only binary, true or false.
Now they have values.
The following are the operators (from highest to lowest precedence) you can use in a condition expression:
Numbers:
   Unary:   -
               %                          Modulo
               *  /
               + -
               > >= < <= == !=  Numeric Comparison
Strings:
               ..                           (Concatenation)
               eq ne ge gt lt le       String <Lexical Comparison
Boolean:
    Unary   not !
               and
               or


To install extract all of the files from the attached zip file and download to your Vera ... This assumes you have already installed the Plugins from the App store first!

Once you see the changes in the UI I will let you guess what the next phase will be  ;D

The code has been released so the Beta files have been removed.
See the http://RTS-Services.com/Vera/Plugin/PLEG Website for details.
« Last Edit: January 17, 2013, 08:59:36 am by RichardTSchaefer »

Offline jouked

  • Sr. Newbie
  • *
  • Posts: 46
  • Karma: +0/-0
Re: Program Logic (Timer and Event Generator) Beta
« Reply #1 on: January 14, 2013, 01:17:37 pm »
Sound great, just installed and started testing!

An issue I run into is how to specify a match on a string?

I've tried the following:

Input is a Device Property, in this case TransportState, it gives the right Current Value, also in the log. Named input 'KeukenState'

Condition is: TestCond = 5 > 4 and Keukenstate eq PLAYING. This gives an error 'Invalid value token: PLAYING.
The 5 > 4 is there just to check the basic evaluation working.

What is the right way to match a string? I can see from the Lua log that the property is monitored correctly and the values are passed through.


Offline RichardTSchaefer

  • Moderator
  • Master Member
  • *****
  • Posts: 10091
  • Karma: +764/-143
Re: Program Logic (Timer and Event Generator) Beta
« Reply #2 on: January 14, 2013, 04:06:46 pm »
Yep ... that's missing ... I added literal numbers ... but not litteral strings ...
I will add support for 'XXX' and "XXXX".
It will be in PL-Beta3.zip  check back later ...

Offline michaelk

  • Hero Member
  • *****
  • Posts: 633
  • Karma: +0/-0
Re: Program Logic (Timer and Event Generator) Beta
« Reply #3 on: January 14, 2013, 11:40:49 pm »
you are a rock star.

 ;D

Offline RichardTSchaefer

  • Moderator
  • Master Member
  • *****
  • Posts: 10091
  • Karma: +764/-143
Re: Program Logic (Timer and Event Generator) Beta
« Reply #4 on: January 14, 2013, 11:45:38 pm »
I just update the files to PL-Beta3.zip
Added support for string literals.
Fixed a bug I introduced in editing triggers.

Offline jouked

  • Sr. Newbie
  • *
  • Posts: 46
  • Karma: +0/-0
Re: Program Logic (Timer and Event Generator) Beta
« Reply #5 on: January 15, 2013, 05:49:46 am »
This does work brilliantly, it saves a lot of coding to make something work!

Here's my scenario: I have an Hifi amplifier that, due to being a class-a amp, uses a lot of energy even when not playing. I use this amplifier with a Sonos streaming audio device.

Using PLEG I can now monitor the Sonos device state. If it's playing Audio, I switch on the amplifier. If no audio is playing, I turn of the amplifier. I use one Device Property as input (TransportState). I have to conditions configured:

Amp_On = DP_TransportState eq 'PLAYING'
Amp_Off = DP_TransportState ne 'PLAYING'

These two conditions trigger scenes to turn on or off the amplifier.

Now I just want to leave the amplifier on for 10 extra minutes after the audio has stopped, so I changed the last condition to:

Amp_Off = DP_TransportState ne 'PLAYING' and (NOW > 10:00)

This however fails on the parsing of the condition with error 'Invalid Value token: NOW'. I know I can do this in other ways as well though.

Great stuff and a really generic solution to a lot of scenario's I can imagine. Actually it makes the Combination Switch obsolete to me.

Offline RichardTSchaefer

  • Moderator
  • Master Member
  • *****
  • Posts: 10091
  • Karma: +764/-143
Re: Program Logic (Timer and Event Generator) Beta
« Reply #6 on: January 15, 2013, 08:42:28 am »
You must use a sequence expression syntax, and is only valid there.

NotPlaying = DP_TransportState ne 'PLAYING'
Amp_Off = NotPlaying;NOW > 10:00

Note: I have not tested a Condition variable in a sequence expression ... but it should work.
Triggers, Schedules, and Condition Variables get a time attached to them when they are first evaluated as true.

Offline jouked

  • Sr. Newbie
  • *
  • Posts: 46
  • Karma: +0/-0
Re: Program Logic (Timer and Event Generator) Beta
« Reply #7 on: January 15, 2013, 10:16:20 am »
Works this way, wow!

This saves me quite a bit of energy I think.. More importantly, it was fun getting this to work!

Offline RichardTSchaefer

  • Moderator
  • Master Member
  • *****
  • Posts: 10091
  • Karma: +764/-143
Re: Program Logic (Timer and Event Generator) Beta
« Reply #8 on: January 15, 2013, 10:45:28 am »
Always looking for someone to add a review:
   http://apps.mios.com/write-review.php?id=3066

Offline jouked

  • Sr. Newbie
  • *
  • Posts: 46
  • Karma: +0/-0
Re: Program Logic (Timer and Event Generator) Beta
« Reply #9 on: January 15, 2013, 10:56:46 am »
Done!  ;)

Offline RichardTSchaefer

  • Moderator
  • Master Member
  • *****
  • Posts: 10091
  • Karma: +764/-143
Re: Program Logic (Timer and Event Generator) Beta
« Reply #10 on: January 17, 2013, 09:16:00 am »
The code has been released so the Beta files have been removed. This thread is now locked.

See the http://RTS-Services.com/Vera/Plugin/PLEG Website for details.