Optimizing actions

Posted on
Thu Aug 08, 2013 7:57 am
berkinet offline
User avatar
Posts: 3298
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Optimizing actions

I am toying with energy measurement. I have installed a sensor on my electric meter that sends a pulse to Indigo (via a Phidgets device) every time 1 Wh is consumed. Updates occur around once a second, though the rate can go much higher. The Phidgets device is set to 1 each time a pulse is received, and then is set back to zero. I have a simple trigger that watches for the device's state to become > 0 and then executes a Modify Variable (Variable Actions) action to increment a variable by 1.

Going forward, I would like to maintain two separate totals, based on the period (time of day) of usage: low hours, 01:00-07:00 & 14:00-17:00, and high, 07:00-14:00 & 17:00-01:00.

Given that this action is going to be executed quite frequently, my concerns are related to the most efficient means of maintaining those two totals. I have considered the following (all triggers are based on the device state becoming > 0):
  • 4 triggers, each with a condition limiting it to one specific time period, and with an action to increment the appropriate variable (I.e. no scripting, but 4 triggers will fire each time the device's value becomes > 1, though only 1 will succeed)..
  • 1 trigger with an embedded AppleScript to check the time of day and then increment the appropriate variable.
  • 1 trigger with an embedded Python script to check the time of day and then increment the appropriate variable.
  • Something else I haven't though of...

To be honest, this is probably a much better project for an Arduino or R-Pi which would capture "bips" for some longer period, say 15 minutes, and then update Indigo. But, while I am testing the concept, this is an easy way to start.

Posted on
Thu Aug 08, 2013 8:58 am
matt (support) offline
Site Admin
User avatar
Posts: 21429
Joined: Jan 27, 2003
Location: Texas

Re: Optimizing actions

The most efficient technique would be to add the logic the Phidgets plugins. So you would add a new "Pulse Meter" device type that increments 1 of 2 different device states based on the current time. Then all the logic occurs within the plugin, and you can access the device states in Indigo for further logic.

Of the 3 other choices you listed, I would either do the 4 trigger approach or the 1 trigger with an embedded python script approach. I think all of them will be fast enough to not be an issue though, presuming it is just once per second.

Image

Posted on
Thu Aug 08, 2013 9:16 am
berkinet offline
User avatar
Posts: 3298
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: Optimizing actions

Thanks Matt. The question was quite theoretical, but none-the-less practical. The core question was the internal efficiency of the compiled Indigo core code vs. executing a script.

I like the idea of having two (or more) states in the device and incrementing the appropriate one based on Time-of-day - or possibly some other algorithm. I think I will try that out.

But, all of this may be moot, at least for the current project. I am now concerned about the response time of the light sensor and the Phidgets controller's 16ms scanning rate (when used over IP). If events occur more often then every 16ms, I would start losing data. That would be around 3.75 kWh or approx 16 amps. We have 45 amp 230V AC here and I have seen the usage go as high at 39 amps. So, way beyond the ability of my simple toy.

Time for some research, or €€€ :roll: Maybe the NorthQ or RFX ideas are worth their price.

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 2 guests

cron