Announcement

Collapse
No announcement yet.

.net script not working... Please Help

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    .net script not working... Please Help

    I am monitoring my cistern fill with an ultrasonic sensor. That data is fed into HS via a MQTT upload. That works as it should, but the ultrasonic sensor sometimes sends false readings. I have written a script in Homeseer that runs every 2 minutes to get the data from the MQTT variable and compare it to the last reading. If the reading changed by more than 4 it should ignore it. I have since added if it is a negative number or 0 to ignore it.

    I am at a loss because I am still getting false readings taken as a good reading and it messes up the whole system.

    As an example lets say the reading that was good was 74. So PreviousCisternLevel is 74. A false reading comes in at 115. I am not sure why it is being allowed passed the first if statement:

    Code:
      Dim CurrentCisternLevel As Integer = hs.DeviceValue(854) '<-- Current state of Cistern
      Dim PreviousCisternLevel As Integer = hs.DeviceValue(859) '<--Previous Reported Level
      Dim FalseReading As Integer
    
     hs.WriteLog("Cistern Reading", "Confirming reading was reset to  " & PreviousCisternLevel)
    
      '<-- To start, compare previous reported with current report.  If greater than just a couple point then trow away as it is more than likley a false reading
    [COLOR=#c0392b] if (CurrentCisternLevel >= PreviousCisternLevel +4 And CurrentCisternLevel >= 0 And CurrentCisternLevel < 105) Then[/COLOR]
        FalseReading = 1
        hs.WriteLog("Cistern Reading", "False reading on the cistern was ignored.  Current is: " & CurrentCisternLevel & " and previous was " & PreviousCisternLevel)
    Here is the complete script:

    Code:
    Public Sub Main(ByVal Parms As Object)
    
    Dim CurrentCisternLevel As Integer = hs.DeviceValue(854) '<-- Current state of Cistern
      Dim PreviousCisternLevel As Integer = hs.DeviceValue(859) '<--Previous Reported Level
      Dim FalseReading As Integer
     hs.WriteLog("Cistern Reading", "Confirming reading was reset to  " & PreviousCisternLevel)
      '<-- To start, compare previous reported with current report.  If greater than just a couple point then trow away as it is more than likley a false reading
      if (CurrentCisternLevel >= PreviousCisternLevel +4 And CurrentCisternLevel >= 0 And CurrentCisternLevel < 105) Then
        FalseReading = 1
        hs.WriteLog("Cistern Reading", "False reading on the cistern was ignored.  Current is: " & CurrentCisternLevel & " and previous was " & PreviousCisternLevel)
      Else
        FalseReading = 0
        'Reading is real so assign as previous for next loop
        hs.SetDeviceValueByName("Cistern Level - Previous", CurrentCisternLevel)
        hs.SetDeviceString(859, CurrentCisternLevel, True)
    
    
      '<-- Cistern Full so set virtual fill valve to off
      if ( CurrentCisternLevel >= 100) Then
        hs.SetDeviceString(857, "Full", True)   '<-Set Cistern Status to full
        hs.SetDeviceValueByName("Cistern Fill Status", 100) '<-Set Fill Status to full
        hs.WriteLog("Cistern Fill Level", "The current cistern level is being reported as FULL at  " & CurrentCisternLevel)
      elseif ( CurrentCisternLevel <= 80 And CurrentCisternLevel >= 51) Then
        hs.SetDeviceString(857, "Fill Needed", True)   '<-Set Cistern Status to Needs fill tonight
        hs.SetDeviceValueByName("Cistern Fill Status", 50) '<-Set Fill Status to Needs Fill tonoght
        hs.WriteLog("Cistern Fill Level", "The current cistern level is being reported as Less Than 80 at  " & CurrentCisternLevel)
      elseif ( CurrentCisternLevel <= 30 ) Then
        hs.SetDeviceString(857, "Fill Now", True)   '<-Set Cistern Status to Needs fill NOW
        hs.SetDeviceValueByName("Cistern Fill Status", 0) '<-Set Fill Status to Needs Fill NOW
        hs.WriteLog("Cistern Fill Level", "The current cistern level is being reported as Less Than 50 at  " & CurrentCisternLevel)
      End If
      '<-- Set up the proper level indicator
      if ( CurrentCisternLevel >= 100) Then
        hs.SetDeviceValueByName("Cistern Level", 100) '<-Set Fill Status to full
        hs.SetDeviceString(858, 100, True)   '<-Set Cistern Status to full
      elseif ( CurrentCisternLevel <= 99 And CurrentCisternLevel >= 75) Then
        hs.SetDeviceValueByName("Cistern Level", 75) '<-Set Fill Status to 3/4
        hs.SetDeviceString(858, 75, True)   '<-Set Cistern Status to 3/4
      elseif ( CurrentCisternLevel <= 74 And CurrentCisternLevel >= 50) Then
        hs.SetDeviceValueByName("Cistern Level", 50) '<-Set Fill Status to 1/2
        hs.SetDeviceString(858, 50, True)   '<-Set Cistern Status to 1/2 
      elseif ( CurrentCisternLevel <= 49  And CurrentCisternLevel >= 25) Then
        hs.SetDeviceValueByName("Cistern Level", 25) '<-Set Fill Status to 1/4
        hs.SetDeviceString(858, 25, True)   '<-Set Cistern Status to 1/4
      elseif ( CurrentCisternLevel <= 24 And CurrentCisternLevel >= 5) Then
        hs.SetDeviceValueByName("Cistern Level", 0) '<-Set Fill Status to low
        hs.SetDeviceString(858, 0, True)   '<-Set Cistern Status to low
      End If
      End If 'End Checking for false reading
    end Sub
    I have been fighting with this for weeks now. It runs great for days and then for some reason allows a number like 114 through when there is no way in my mind it should. PLEASE HELP!!!!

    What am I missing
    Kirk

    http://cleverhouseautomation.ca
    http://southcoastwebsitedesign.ca

    #2
    CurrentCisternLevel of 114 isn't in range 0 thru 105, so it won't be flagged as FalseReading?

    Comment


      #3
      Yes, I have made so many changes over the weeks to get it working. Your right. the way I have it now is totally wrong. I added, that is else and did not change some of the other variables. So now this should work.....

      if (CurrentCisternLevel >= PreviousCisternLevel +4 OR CurrentCisternLevel < 0 Or CurrentCisternLevel > 105) Then
      Kirk

      http://cleverhouseautomation.ca
      http://southcoastwebsitedesign.ca

      Comment

      Working...
      X