Author Topic: Code question....  (Read 426 times)

Offline Mike Yeager

  • Hero Member
  • *****
  • Posts: 571
  • Karma: +9/-12
Code question....
« on: December 29, 2017, 05:33:01 pm »
I want to monitor a variable (it's a temperature) and detect when it is increasing between measurements taken at an interval of a minute or two. I'm going to see if I can figure out how to do it in PLEG, but I have a feeling it's going to be a LUA task. Anyone else tackle this in the past???

Offline akbooer

  • Master Member
  • *******
  • Posts: 6153
  • Karma: +275/-69
  • "Less is more"
Re: Code question....
« Reply #1 on: December 29, 2017, 05:56:57 pm »
I'm sure it's very easy in PLEG, but I wouldn't know how.

In Lua, you could simply have a scene scheduled to run every minute or so and do some action if the measurement is increasing.  This sort of thing has been done countless times in the past, so there should be examples to follow.
3x Vera Lite-UI5/Edge-UI7, 25x Fibaro, 23x TKB, 9x MiniMote, 2x NorthQ Power, 2x Netatmo, 1x Foscam FI9831P, 9x Philips Hue,
Razberry, MySensors Arduino, HomeWave, AltUI, AltHue, DataYours, Grafana, openLuup, ZWay, ZeroBrane Studio.

Offline RichardTSchaefer

  • Master Member
  • *******
  • Posts: 10091
  • Karma: +763/-142
Re: Code question....
« Reply #2 on: December 30, 2017, 06:49:37 am »
Of course your measurement needs to update at that frequency.

But if you just want to see of the temperature changes in 2 minutes:
   
                    (Temp @ 2 < 2:00)
So if the temperature changes in 3 minutes .. this will be false ... if it changes in 1:59 seconds it will be true.


Offline Mike Yeager

  • Hero Member
  • *****
  • Posts: 571
  • Karma: +9/-12
Re: Code question....
« Reply #3 on: December 30, 2017, 06:15:17 pm »
Is it really that easy? Seems to me that you'd have to store the value somewhere in order to compare it to it's previous value. I don't know if there's a time stamp on it... On that note, I have this value in a variable where the definition starts with "local". If I remove "local" from the LUA, will I be able to see this variable in PLEG?
« Last Edit: December 30, 2017, 06:19:35 pm by Mike Yeager »

Offline RichardTSchaefer

  • Master Member
  • *******
  • Posts: 10091
  • Karma: +763/-142
Re: Code question....
« Reply #4 on: December 31, 2017, 10:12:17 am »
In PLEG every time an Input or Condition changes value it gets a timestamp. PLEG keeps the last 4 timestamps  (for an On/Off Input or Condition 4 timestamps for On and 4 timestamps for Off)

You can flag a condition as "Export" than it will create a variable on the PLEG device that can be accessed outside of the PLEG in the same way that any LUA or other PLEG accesses a devices variable.


Offline Mike Yeager

  • Hero Member
  • *****
  • Posts: 571
  • Karma: +9/-12
Re: Code question....
« Reply #5 on: January 01, 2018, 02:26:08 pm »
I guess it's time to start studying up then.....

Offline Don Phillips

  • Hero Member
  • *****
  • Posts: 1326
  • Karma: +35/-32
Re: Code question....
« Reply #6 on: January 01, 2018, 03:39:28 pm »
Once you understand how it works, PLEG is the way to automate Vera.
Vera 3, 1.7.1030, CT101, Everspring motion sensor, GE/Jasco switch, Leviton outlet, AeonLabs sensor, NuTone garage door, Blue Iris, Sricam SP011, iPhone locator, APCUPSD, VeraMate, VeraAlerts, PLEG, House Modes, Countdown Timer, DVR, Virtual/Multi Switch, Weatherunderground, LB60Z-1 bulb, Hue, Alexa

Offline Mike Yeager

  • Hero Member
  • *****
  • Posts: 571
  • Karma: +9/-12
Re: Code question....
« Reply #7 on: January 02, 2018, 10:02:45 am »
PLEG is definitely the way to do many things, I'm just learning still how to do many of them...