Phidgets Plugin Discussion

Posted on
Tue May 14, 2013 9:27 am
daz offline
Posts: 1
Joined: May 14, 2013

Re: Phidgets Plugin Discussion

hamw wrote:
I wrote up the install here. Overall it went pretty smoothly.

Following Berkinet's advice I used one of the digital inputs on the 8/8/8 board to count the pulses, and it works! As the meter spins the little dial rotates under the sensor and sends a pulse to the Phidgets board. The pulse is incremented with a trigger into a variable. So, no frequency counter required (yaay! total project cost is now $75 bucks cheaper!!).

There are a couple of things I'd like to do:

1. Total up historical water usage on a current day, prior day, current week, prior week, current month, and all months prior for one year (and maybe two or three?).

2. Use the pulse info to determine if there is a leak. It seems like water intensive things could create false calls, for instance running a bath or washing a car. I'm thinking that using the occupancy sensors (SPR, FMF, alarm status) during the day to determine if someone is home and suppressing a trigger would account for most of these events - I don't think my wife will allow motion detectors in the bathrooms! Then, monitoring strictly for any flow when everyone is away, and at night when everyone is asleep might pick up slow leaks.

I think both of these could be done with Applescript and some triggers. I am OK with AS but am not sure how to get time dependent things like current day, prior day, current month, prior month etc into a script. But, this reporting is very similar to what the RFXcom plugin's Rain Sensor already does. If anyone has suggestions how to write such a script I'd be very appreciative.


Nice write up :)

Posted on
Wed May 15, 2013 8:27 pm
hamw offline
Posts: 1212
Joined: Mar 31, 2008

Re: Phidgets Plugin Discussion

daz, appreciate the post! :D

I think I figured it out. Each "current variable", for instance Today, This Week and This Month, are incremented each time the water meter clicks via a single trigger. Every day at 12:01 AM a schedule runs the following script:

Code: Select all
      set {year:y, month:m, day:d, weekday:w} to (current date)


--Today and Yesterday. Second line in each sequence resets the current variable to ""
set value of variable "WaterUse_2_Yesterday" to value of variable "WaterUse_1_Today" as string

set value of variable "WaterUse_1_Today" to ""


--This week and last week
if w is Monday then
   set value of variable "WaterUse_4_LastWeek" to value of variable "WaterUse_3_ThisWeek"
   set value of variable "WaterUse_2_Yesterday" to ""
end if


--This month and last month
if d is 1 then
   set value of variable "WaterUse_6_LastMonth" to value of variable "WaterUse_5_ThisMonth"
   set waterUseThisMonth to value of variable "WaterUse_5_ThisMonth"
   set value of variable "WaterUse_5_ThisMonth" to ""
end if


--Prior Month historical data
if d is 1 then
   if m is January then
      set value of variable "WaterUse_18_Dec" to waterUseThisMonth
   end if
   
   if m is February then
      set value of variable "WaterUse_7_Jan" to waterUseThisMonth
   end if
   
   if m is March then
      set value of variable "WaterUse_8_Feb" to waterUseThisMonth
   end if
   
   if m is April then
      set value of variable "WaterUse_9_Mar" to waterUseThisMonth
   end if
   
   if m is May then
      set value of variable "WaterUse_10_Apr" to waterUseThisMonth
   end if
   
   if m is June then
      set value of variable "WaterUse_11_May" to waterUseThisMonth
   end if
   
   if m is July then
      set value of variable "WaterUse_12_Jun" to waterUseThisMonth
   end if
   
   if m is August then
      set value of variable "WaterUse_13_Jul" to waterUseThisMonth
   end if
   
   if m is September then
      set value of variable "WaterUse_14_Aug" to waterUseThisMonth
   end if
   
   if m is October then
      set value of variable "WaterUse_15_Sep" to waterUseThisMonth
   end if
   
   if m is November then
      set value of variable "WaterUse_16_Oct" to waterUseThisMonth
   end if
   
   if m is December then
      set value of variable "WaterUse_17_Nov" to waterUseThisMonth
   end if
   
end if
         



Honestly, this is probably not very elegant. If anyone can show me how to write this in a less "brute force" way, I'd appreciate seeing how it's done. I will work on the "sensing" stuff.

Posted on
Mon May 20, 2013 5:14 am
loafbread offline
Posts: 137
Joined: May 25, 2009

Re: Phidgets Plugin Discussion

Indigo Beta 8 causes a lot of Phidgets errors in the log. The IO seems to be working but here is a sample of the errors when operating a Digital Output on a 0/0/8 board attached to an SBC. Phidgets plugin v0.5.3.


Phidgets ifKit digital output read finished update for index 0
Phidgets Error Error in plugin execution ServerReplacedElem:

Traceback (most recent call last):
File "/Library/Application Support/Perceptive Automation/Indigo 6/IndigoPluginHost.app/Contents/PlugIns/plugin_base.py", line 800, in deviceUpdated
File "plugin.py", line 326, in didDeviceCommPropertyChange
File "/Library/Application Support/Perceptive Automation/Indigo 6/Plugins/Phidgets.indigoPlugin/Contents/Server Plugin/ifkit.py", line 224, in readDigitalOutput
<type 'exceptions.UnboundLocalError'>: local variable 'inValue' referenced before assignment

Phidgets Error Error in plugin execution ServerReplacedElem:

Traceback (most recent call last):
File "/Library/Application Support/Perceptive Automation/Indigo 6/IndigoPluginHost.app/Contents/PlugIns/plugin_base.py", line 800, in deviceUpdated
File "plugin.py", line 326, in didDeviceCommPropertyChange
File "/Library/Application Support/Perceptive Automation/Indigo 6/Plugins/Phidgets.indigoPlugin/Contents/Server Plugin/ifkit.py", line 224, in readDigitalOutput
<type 'exceptions.UnboundLocalError'>: local variable 'inValue' referenced before assignment

Phidgets Error Error in plugin execution ServerReplacedElem:

Traceback (most recent call last):
File "/Library/Application Support/Perceptive Automation/Indigo 6/IndigoPluginHost.app/Contents/PlugIns/plugin_base.py", line 800, in deviceUpdated
File "plugin.py", line 326, in didDeviceCommPropertyChange
File "/Library/Application Support/Perceptive Automation/Indigo 6/Plugins/Phidgets.indigoPlugin/Contents/Server Plugin/ifkit.py", line 224, in readDigitalOutput
<type 'exceptions.UnboundLocalError'>: local variable 'inValue' referenced before assignment

Phidgets ifKit Setup for device "Phidgets 0/0/8 " complete, listening for events
Phidgets ifKit digital output read finished update for index 1
Phidgets ifKit digital output read finished update for index 2
Phidgets ifKit digital output read finished update for index 3
Phidgets ifKit digital output read finished update for index 4
Phidgets ifKit digital output read finished update for index 5
Phidgets ifKit digital output read finished update for index 6
Phidgets ifKit digital output read finished update for index 7

Posted on
Mon May 20, 2013 9:02 am
matt (support) offline
Site Admin
User avatar
Posts: 21416
Joined: Jan 27, 2003
Location: Texas

Re: Phidgets Plugin Discussion

Hi Richard:

I think this problem is occurring because now the deviceUpdated() callback is called more frequently, which then calls the plugin's override of the didDeviceCommPropertyChange() method. I suspect that inside the override it is then referencing variables/instances that haven't yet been created.

Note that deviceUpdated() can be called now before a device's ConfigUI has been shown or validated (placeholder devices are created and inserted into the database before the UI is shown in Indigo 6). You can check if the device is configured yet by testing the dev.configured attribute. So you'll probably want to add a conditional at the top of didDeviceCommPropertyChange() that checks if that is False, in which case it returns out.

Additionally, deviceUpdate() is now also called when states are updated by the plugin. Previously there was a buglet that prevented the callback in that particular case.

Image

Posted on
Mon May 20, 2013 4:43 pm
jsrivet offline
User avatar
Posts: 13
Joined: May 23, 2010
Location: Joliette, Québec, Canada

Re: Phidgets Plugin Discussion

I had the same problem and I have the solution. You have to go disabled line 299 to 326 of file plugin.py. in the file phidget.indigo.pluing

Code: Select all
 ########################################
    # def didDeviceCommPropertyChange(self, origDev, newDev):
        #if self.logLevel > 1:
            #indigo.server.log(u"Entering didDeviceCommPropertyChange for device: %s (%d - %s)" % (newDev.name, newDev.id, newDev.deviceTypeId))

        #if newDev.deviceTypeId == "ifKit" or newDev.deviceTypeId == "phStandalonePhidget" or newDev.deviceTypeId == "phLcdScreen":
            # If this is a standalone device, make sure it gets restarted on any changes
            #return True
        #elif newDev.deviceTypeId == 'phIfKitSensor':
            # This is an analog sensor -- Nothing to restart, put we should re-read the index value
            #ifKitDevId = int(newDev.pluginProps['phSensorIfKitId'])
            #ifKitDevIndex = int(newDev.pluginProps['phSensorIfKitAnalogInput'])
            #if self.logLevel > 1:
                #indigo.server.log(u"Sensor attached to dev num: %s" % ifKitDevId)
            #self.phThreadDict[ifKitDevId].readSensorInput(ifKitDevIndex)
        #elif newDev.deviceTypeId == 'phDiIfKit':
          # This is a digital input -- Nothing to restart, put we should re-read the index state
            #ifKitDevId = int(newDev.pluginProps['phDiIfKitId'])
            #ifKitDevIndex = int(newDev.pluginProps['phDiIfKitInput'])
            #if self.logLevel > 1:
                #indigo.server.log(u"Digital Input on dev num: %s" % ifKitDevId)
            #self.phThreadDict[ifKitDevId].readDigitalInput(ifKitDevIndex)
        #elif newDev.deviceTypeId == 'phDoIfKit':
          # This is a digital input -- Nothing to restart, put we should re-read the index state
            #ifKitDevId = int(newDev.pluginProps['phDoIfKitId'])
            #ifKitDevIndex = int(newDev.pluginProps['phDoIfKitOutput'])
            #if self.logLevel > 1:
                #indigo.server.log(u"Digital Input on dev num: %s" % ifKitDevId)
            #self.phThreadDict[ifKitDevId].readDigitalOutput(ifKitDevIndex)

        return False

    ########################################
Last edited by jsrivet on Thu Jun 06, 2013 3:56 pm, edited 1 time in total.

Posted on
Mon May 20, 2013 11:39 pm
berkinet offline
User avatar
Posts: 3290
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: Phidgets Plugin Discussion

I am on the road for a couple of weeks. Until I can get back, to make the changes noted by Matt, you can follow jaruvet's advice.

Posted on
Mon May 27, 2013 11:10 am
midd offline
Posts: 372
Joined: Apr 18, 2010

Re: Phidgets Plugin Discussion

Well I just read all 10 pages of this thread and have a few questions. Would love to use the Vegetronix soil moisture sensors in my yard. I would obviously need the Phidget 1048 device. Would I need anything else other than the plug in?

Indigo 7, Monterey (12.1) on a 2009 Mac Pro..

Posted on
Mon May 27, 2013 12:17 pm
berkinet offline
User avatar
Posts: 3290
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: Phidgets Plugin Discussion

If I understand the Vegetronix sensors, they output a voltage between 0 and 3vdc proportionate to moisture or temperature. If that is the case, rather than the 1048 Phidget which reads thermistors, you would need a Phidgets board with analog inputs like the 1010,1011, 1018, 1019 or the SBC.

You could then use the plugin to create a generic sensor and a custom formula to produce the appropriate output value for your sensors.

Posted on
Fri Jun 21, 2013 12:37 pm
midd offline
Posts: 372
Joined: Apr 18, 2010

Re: Phidgets Plugin Discussion

Anyone else using Vegetronix soil moisture sensors? I'd like to see/use your formula.

Thanks

berkinet wrote:
If I understand the Vegetronix sensors, they output a voltage between 0 and 3vdc proportionate to moisture or temperature. If that is the case, rather than the 1048 Phidget which reads thermistors, you would need a Phidgets board with analog inputs like the 1010,1011, 1018, 1019 or the SBC.

You could then use the plugin to create a generic sensor and a custom formula to produce the appropriate output value for your sensors.

Indigo 7, Monterey (12.1) on a 2009 Mac Pro..

Posted on
Wed Jun 26, 2013 5:37 pm
loafbread offline
Posts: 137
Joined: May 25, 2009

Re: Phidgets Plugin Discussion

Berkinet, has there been a Phidgets update since 0.5.3? Are you still traveling? I am holding off on the recent Indigo updates until Phidgets is compatible. I am totally dependent on Phidgets now :)

Thanks

Posted on
Thu Jun 27, 2013 1:21 am
berkinet offline
User avatar
Posts: 3290
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: Phidgets Plugin Discussion

I will be putting up 0.56 in the next day or so. This will address problems related to changes in the plugin interface introduced in I6b9. But, other than adding the 3130 humidity sensor there are no significant changes.

Posted on
Sat Jul 06, 2013 7:06 am
midd offline
Posts: 372
Joined: Apr 18, 2010

Re: Phidgets Plugin Discussion

I was able to get my Phidgets board and vegetronix moisture sensor setup through Indigo. Thanks berkinet for the plugin and gtreece for your help. However I'm not getting any updated readings. The last reading was the initial reading when I first connected everything together. To get a new reading I have to unplug the USB cable from my mac mini and plug it back in.

Indigo 7, Monterey (12.1) on a 2009 Mac Pro..

Posted on
Sat Jul 06, 2013 11:01 am
berkinet offline
User avatar
Posts: 3290
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: Phidgets Plugin Discussion

midd wrote:
...I'm not getting any updated readings. The last reading was the initial reading when I first connected everything together. To get a new reading I have to unplug the USB cable from my mac mini and plug it back in.

That's not much information to go on. But, If I had to guess, I'd say you have configured the Phidgets plugin to connect to your InterfaceKit using USB and you also have the Phidgets preference panel open at the same time. Or you have the InterfaceKit open in the preference panel using ISB. When using USB only one program at a time may access the USB port. If this is the case, the solution is to turn on the Phidgets Web Service (in the Phidgets Control Panel) and then configure the plugin to connect to the InterfaceKit over IP at 127.0.0.1 at whatever port you set when you started the web service (default is 5001).

If this is not the case. Then please provide the details of your setup. Also, you might try testing with the Phidgets Preference panel using the listing for your InterfaceKit found on the Bonjour tab of the preference pane. That way it will also use the web service and not conflict with the plugin.

Posted on
Sat Jul 06, 2013 11:24 am
midd offline
Posts: 372
Joined: Apr 18, 2010

Re: Phidgets Plugin Discussion

Thanks for the response. The control panel was closed. I had the Phidgets connection set to USB. Once I changed it to IP network, it updated. Will keep an eye to make sure it continues to update.

berkinet wrote:
midd wrote:
...I'm not getting any updated readings. The last reading was the initial reading when I first connected everything together. To get a new reading I have to unplug the USB cable from my mac mini and plug it back in.

That's not much information to go on. But, If I had to guess, I'd say you have configured the Phidgets plugin to connect to your InterfaceKit using USB and you also have the Phidgets preference panel open at the same time. Or you have the InterfaceKit open in the preference panel using ISB. When using USB only one program at a time may access the USB port. If this is the case, the solution is to turn on the Phidgets Web Service (in the Phidgets Control Panel) and then configure the plugin to connect to the InterfaceKit over IP at 127.0.0.1 at whatever port you set when you started the web service (default is 5001).

If this is not the case. Then please provide the details of your setup. Also, you might try testing with the Phidgets Preference panel using the listing for your InterfaceKit found on the Bonjour tab of the preference pane. That way it will also use the web service and not conflict with the plugin.

Indigo 7, Monterey (12.1) on a 2009 Mac Pro..

Posted on
Sun Jul 07, 2013 2:31 pm
midd offline
Posts: 372
Joined: Apr 18, 2010

Re: Phidgets Plugin Discussion

Well I'm still not getting any updates to readouts from my Vegetronix moisture sensor and my Phidgets 1018 Interface Kit. I watered outback and decided to soak the area where my vegetronix is. There was no change to the variable or voltage. The sensor is connected to input 0. If I unplug and replug the USB cable, I'll get an initial reading

Here is a pic of the Phidgets Interface setup in Indigo:
Image



Here is a pic of the Vegetronix setup in Indigo:

Image


and here is a pic of the Phidgets Control Panel (which has been closed) from the System Preferences:

Image

Any help is appreciated!

Indigo 7, Monterey (12.1) on a 2009 Mac Pro..

Page 10 of 39 1 ... 7, 8, 9, 10, 11, 12, 13 ... 39

Who is online

Users browsing this forum: No registered users and 2 guests