Announcement

Collapse
No announcement yet.

How would I compare current vs. previous device value?

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

    How would I compare current vs. previous device value?

    Hi folks, I'm using the EvnCan weather plugin and one of the devices returns a barometer value from Environment Canada Atom feeds.

    I'm interested in an event that would detect a barometer value decrease (i.e. bad weather coming), or warn on the magnitude of the differential drop etc.
    So presumably I would need to save the current incoming value for comparison the next time the feed changes.

    I'm using a Hometroller Zee S2.
    Any suggestions would be welcome and appreciated.
    Cheers!

    #2
    Probably the easiest way (depending on what your scripting powers are like), would be to create a global variable and have that get updated when things change. You can then use a script to take the current value, and the GV value (before its overwritten) and use that.

    Here is a script as an example (I got it from someone smarter than me on the forum) that compares outside temperature to inside and alerts that windows should be opened or closed. The top part would be the part for how to do the global variable. I could help you with this if you want, as I am sure others on the forum would chime in too.

    Code:
    Sub SetTrend(var)
        DIM errst
        'Get Outside temperature
        DIM OT=CInt(hs.DeviceValue(864))
        'Get Previous Temperature from Global Variable
        DIM PT=hs.GetVar("temp_previous")
    
        IF (PT=999) THEN 'initializing on first run  - set in startup script
          PT=OT
          errst = hs.SaveVar("temp_previous",PT) ' save it as previous temp
        END IF
    
        IF (PT<>OT) THEN
            IF (PT>OT) THEN 'temp cooling
                errst = hs.SaveVar("temp_trend","FALLING")
            ELSE 
                errst = hs.SaveVar("temp_trend","RISING")
            END IF 
        ELSE
           errst = hs.SaveVar("temp_trend","STEADY")
        END IF
        errst = hs.SaveVar("temp_previous",OT)
    End Sub
    
    Sub WindowAdvice(var)
        Dim CSP = 74 'CInt(hs.DeviceValue(670)) 'cooling set point
        Dim HSP = 64 'CInt(hs.DeviceValue(669)) ' heating set point
        Dim ASP = CInt((CSP + HSP)/2) ' average between HSP/CSP
        Dim OT = CInt(hs.DeviceValue(864)) ' Outside temp
        Dim IT = CInt(hs.Devicevalue(671)) ' Inside temp
        Dim OTMax As Integer = 75 'Max I can stand
        Dim OTMin As Integer = 55 'Min I can stand
        Dim Trend As String = hs.GetVar("temp_trend")
    	dim speaker as string = "{speaker=HouseNoBackyard, volume=22, source=2, sound=ding} "
        'this is a timer that tells me how long a door or window has been open
        'timer starts/stops based on alarm system fault status
        Dim OpenTime As TimeSpan = hs.TimerValue("DoorWindow")
        Dim Open As Boolean = (OpenTime.TotalSeconds > 0)
    	dim window_speak_status as integer = hs.devicevalue(1540)
    	
    
    
        If ((Open) And (window_speak_status = 100)) Then 'Windows Open - Advise CLOSE WINDOWS
            'I used to do this logic based on CSP/HSP, but now use ave +/- 2
            If (((OT >= ASP + 2) And (Trend = "RISING")) _
            Or ((OT <= ASP - 2) And (Trend = "FALLING"))) Then 'Outside Temp Trend is crossing Inside Temp to reserve heat/cool of house
    
                hs.Speak(speaker & "Outside Temperature is " & OT.ToString() & " and " & Trend & ". Recommend closing windows.", True)
                'commented out next line due to low WAF (she doesn't like the house telling her what to do)
                'hs.Speak("Recommend closing windows.", True)
                hs.WriteLog("HVAC Advisory", "Close B/C OT Passing ASP (A) [OT=" & OT & "|TREND=" & Trend & "|IT=" & IT & "| CSP=" & CSP & "|HSP=" & HSP)
    			hs.setdevicevaluebyref(1540,0,true)
    
            End If
    
            If ((OT >= IT) And (IT >= CSP - 1)) Then ' situation more extreme, now warmer outside air is heating house
    
                'hs.Speak("Outside air is " & OT.ToString() & " degrees" & " and " & Trend, True)
                hs.Speak(speaker & "A.C. required to maintain comfort.", True)
                hs.WriteLog("HVAC Advisory", "Close B/C OT>=IT (B) [OT=" & OT & "|TREND=" & Trend & "|IT=" & IT & "| CSP=" & CSP & "|HSP=" & HSP)
    			hs.setdevicevaluebyref(1540,0,true)
    
            ElseIf ((OT <= IT) And (IT <= HSP)) Then ' situation more extreme, heat from house is escaping outside
    
                'hs.Speak("Heat escaping outside.", True)
                hs.Speak(Speaker & "Heater will need to run when windows closed.", True)
                hs.WriteLog("HVAC Advisory", "Close B/C OT<=IT (C) [OT=" & OT & "|TREND=" & Trend & "|IT=" & IT & "| CSP=" & CSP & "|HSP=" & HSP)
    			hs.setdevicevaluebyref(1540,0,true)
    
            End If
        
        Else ' Windows Closed - Advise OPEN WINDOWS if Outside Temp in comfort range
    
            If (((OT < IT) And (Trend <> "RISING") And (OT >= OTMin)) _
            Or ((OT <= IT) And (Trend = "FALLING") And (OT <= OTMax))) Then
    
                hs.Speak(speaker & "Outside temperature is " & OT.ToString() & " and " & Trend & ". Recommend opening windows.", True)
                'hs.Speak("Recommend opening windows.", True)
                hs.WriteLog("HVAC Advisory", "Open B/C OT between SPs (D) [OT=" & OT & "|TREND=" & Trend & "|OTMax=" & OTMax & "|OTMin=" & OTMin & "|IT=" & IT & "| CSP=" & CSP & "|HSP=" & HSP)
    			hs.setdevicevaluebyref(1540,0,true)
            End If
        End If
    
    End Sub

    Comment


      #3
      Originally posted by Otto-mation View Post
      Hi folks, I'm using the EvnCan weather plugin and one of the devices returns a barometer value from Environment Canada Atom feeds.

      I'm interested in an event that would detect a barometer value decrease (i.e. bad weather coming), or warn on the magnitude of the differential drop etc.
      So presumably I would need to save the current incoming value for comparison the next time the feed changes.

      I'm using a Hometroller Zee S2.
      Any suggestions would be welcome and appreciated.
      Cheers!
      Easytrigger can compare two values. create a new virtual device to hold the previous reading and compare with current to fire a event

      Comment


        #4
        Originally posted by waynehead99 View Post
        Probably the easiest way (depending on what your scripting powers are like), would be to create a global variable and have that get updated when things change. You can then use a script to take the current value, and the GV value (before its overwritten) and use that.

        Here is a script as an example (I got it from someone smarter than me on the forum) that compares outside temperature to inside and alerts that windows should be opened or closed. The top part would be the part for how to do the global variable. I could help you with this if you want, as I am sure others on the forum would chime in too.

        Code:
        Sub SetTrend(var)
            DIM errst
            'Get Outside temperature
            DIM OT=CInt(hs.DeviceValue(864))
            'Get Previous Temperature from Global Variable
            DIM PT=hs.GetVar("temp_previous")
        
            IF (PT=999) THEN 'initializing on first run  - set in startup script
              PT=OT
              errst = hs.SaveVar("temp_previous",PT) ' save it as previous temp
            END IF
        
            IF (PT<>OT) THEN
                IF (PT>OT) THEN 'temp cooling
                    errst = hs.SaveVar("temp_trend","FALLING")
                ELSE 
                    errst = hs.SaveVar("temp_trend","RISING")
                END IF 
            ELSE
               errst = hs.SaveVar("temp_trend","STEADY")
            END IF
            errst = hs.SaveVar("temp_previous",OT)
        End Sub
        
        Sub WindowAdvice(var)
            Dim CSP = 74 'CInt(hs.DeviceValue(670)) 'cooling set point
            Dim HSP = 64 'CInt(hs.DeviceValue(669)) ' heating set point
            Dim ASP = CInt((CSP + HSP)/2) ' average between HSP/CSP
            Dim OT = CInt(hs.DeviceValue(864)) ' Outside temp
            Dim IT = CInt(hs.Devicevalue(671)) ' Inside temp
            Dim OTMax As Integer = 75 'Max I can stand
            Dim OTMin As Integer = 55 'Min I can stand
            Dim Trend As String = hs.GetVar("temp_trend")
        	dim speaker as string = "{speaker=HouseNoBackyard, volume=22, source=2, sound=ding} "
            'this is a timer that tells me how long a door or window has been open
            'timer starts/stops based on alarm system fault status
            Dim OpenTime As TimeSpan = hs.TimerValue("DoorWindow")
            Dim Open As Boolean = (OpenTime.TotalSeconds > 0)
        	dim window_speak_status as integer = hs.devicevalue(1540)
        	
        
        
            If ((Open) And (window_speak_status = 100)) Then 'Windows Open - Advise CLOSE WINDOWS
                'I used to do this logic based on CSP/HSP, but now use ave +/- 2
                If (((OT >= ASP + 2) And (Trend = "RISING")) _
                Or ((OT <= ASP - 2) And (Trend = "FALLING"))) Then 'Outside Temp Trend is crossing Inside Temp to reserve heat/cool of house
        
                    hs.Speak(speaker & "Outside Temperature is " & OT.ToString() & " and " & Trend & ". Recommend closing windows.", True)
                    'commented out next line due to low WAF (she doesn't like the house telling her what to do)
                    'hs.Speak("Recommend closing windows.", True)
                    hs.WriteLog("HVAC Advisory", "Close B/C OT Passing ASP (A) [OT=" & OT & "|TREND=" & Trend & "|IT=" & IT & "| CSP=" & CSP & "|HSP=" & HSP)
        			hs.setdevicevaluebyref(1540,0,true)
        
                End If
        
                If ((OT >= IT) And (IT >= CSP - 1)) Then ' situation more extreme, now warmer outside air is heating house
        
                    'hs.Speak("Outside air is " & OT.ToString() & " degrees" & " and " & Trend, True)
                    hs.Speak(speaker & "A.C. required to maintain comfort.", True)
                    hs.WriteLog("HVAC Advisory", "Close B/C OT>=IT (B) [OT=" & OT & "|TREND=" & Trend & "|IT=" & IT & "| CSP=" & CSP & "|HSP=" & HSP)
        			hs.setdevicevaluebyref(1540,0,true)
        
                ElseIf ((OT <= IT) And (IT <= HSP)) Then ' situation more extreme, heat from house is escaping outside
        
                    'hs.Speak("Heat escaping outside.", True)
                    hs.Speak(Speaker & "Heater will need to run when windows closed.", True)
                    hs.WriteLog("HVAC Advisory", "Close B/C OT<=IT (C) [OT=" & OT & "|TREND=" & Trend & "|IT=" & IT & "| CSP=" & CSP & "|HSP=" & HSP)
        			hs.setdevicevaluebyref(1540,0,true)
        
                End If
            
            Else ' Windows Closed - Advise OPEN WINDOWS if Outside Temp in comfort range
        
                If (((OT < IT) And (Trend <> "RISING") And (OT >= OTMin)) _
                Or ((OT <= IT) And (Trend = "FALLING") And (OT <= OTMax))) Then
        
                    hs.Speak(speaker & "Outside temperature is " & OT.ToString() & " and " & Trend & ". Recommend opening windows.", True)
                    'hs.Speak("Recommend opening windows.", True)
                    hs.WriteLog("HVAC Advisory", "Open B/C OT between SPs (D) [OT=" & OT & "|TREND=" & Trend & "|OTMax=" & OTMax & "|OTMin=" & OTMin & "|IT=" & IT & "| CSP=" & CSP & "|HSP=" & HSP)
        			hs.setdevicevaluebyref(1540,0,true)
                End If
            End If
        
        End Sub

        Eeesh, thanks - that's a lot of coding but I haven't done coding since the 1990s and that pre-dated VBScript. But I will definitely consider it.
        I appreciate the detail in your reply.
        Thank you.

        Comment


          #5
          Originally posted by wadesready View Post
          Easytrigger can compare two values. create a new virtual device to hold the previous reading and compare with current to fire a event
          Whoa! This got my attention! Wow, this sounds like it could just be the ticket!
          And apparently I have room for one more plugin.
          Time to look at Easytrigger.

          Thanks for the suggestion. Very helpful.
          Cheers!

          Comment

          Working...
          X