Announcement

Collapse
No announcement yet.

Using Replacement Variable To Identify Device

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

    Using Replacement Variable To Identify Device

    I'm new to scripting and commands and would appreciate help using replacement variables.

    I am trying to use replacement variables in an email to give me the status of a device. I have been successful in passing along in the email the status using $$DVRref): but I don't see in the list of HS3 replacement variables one for the device name? There is one for the device string $$DTAaddress): however this does not return the name of my device in the email. Is this string field the same as listed on the advance tab of the device? This field for my device is null and I do not see any way to add a value. Thank you in advance for any assistance.

    #2
    There has never been one for the name that I remember in HS2 or HS3, I guess the idea was that you would tend to know the name so just write it in manually rather than need a variable for it.

    Depends on what you are trying to do as to which is the best way to do it, if you are looking at complex lists then it may be easier to do this by script. You could look at using the device enumerator to loop through the devices and put the name in the email or just grabbing the device by reference and getting the name that way.

    Comment


      #3
      Thank you for the quick response and scripting suggestions. This saves me a lot of time searching further through the forum for an answer.

      Comment


        #4
        Here's an example of a script I use to send me the status of batteries. It retrieves the device name and other values, so you may be able to do something similar. It has an array at the beginning where I define which devices I want to retrieve the info for and then it loops through them and builds the email.

        Cheers
        Al

        Code:
        Sub Main(ByVal Parms As String)
        
        	Dim logName As String = "Battery Status"						'set log type for HS log
        	Dim Debug As Boolean = False										'set to True if the script give you errors and it will provide additional info in the HS3 log to help troubleshoot
        
        	Dim Devices() As Integer = {517,1024,875,757,777,768,475,2506,765,802,808,771,785,791,2505,825,781,2498,1005,393,385,1009}
        	Dim BatteryStatus(100) As Integer 
        	Dim i As Integer = 0
        	Dim j As Integer = 0
        	Dim dv As Object 
        	Dim mailMessage As String = ""
        	Dim Email As Boolean = True										'set to False if you don't want to send emails
        	Dim AlertEmail As String = "hsalert@email.com"		'email address to send alerts to
        	Dim WarningEmail As String = "hswarning@email.com"	'email address to send warnings to
        	Dim FromEmail As String = "homeseer@email.com"			'email address to send emails from
        	Dim Pushover As Boolean = True									'set to False if you don't use the Pushover plugin
        
        	Try
        		For Each Device As Integer In Devices
        			BatteryStatus(i) = hs.DeviceValue(Device)
        			If BatteryStatus(i) > 100 Then BatteryStatus(i) = 0
        			i = i + 1
        		Next 
        
        		ReDim Preserve BatteryStatus(i-1)
        		Array.Sort(BatteryStatus, Devices)
        
        		For j = 0 to i - 1
        			dv = hs.GetDeviceByRef(Devices(j))
        			If Debug Then hs.writelog(logName,BatteryStatus(j) & "%  " & Replace(hs.DeviceName(Devices(j)),dv.Location(hs) & " " & dv.Location2(hs),"") & " (" & hs.DeviceLastChangeRef(Devices(j)) & ")")
        			mailMessage = mailMessage & BatteryStatus(j).ToString & "%  " & Replace(hs.DeviceName(Devices(j)),dv.Location(hs) & " " & dv.Location2(hs),"") & " (" & hs.DeviceLastChangeRef(Devices(j)) & ")" & chr(13) & chr(10)
        		Next
        
        		If Email Then hs.SendEmail(WarningEmail,FromEmail,"","",logName,mailMessage,"")
        
        	Catch ex As Exception
        		hs.WriteLog(logName, ex.Message)
        	End Try
        
        End Sub
        HS 4.2.8.0: 2134 Devices 1252 Events
        Z-Wave 3.0.10.0: 133 Nodes on one Z-Net

        Comment


          #5
          Sparkman,

          This is great and exactly what I needed! I'm very new to scripting but do have some VB programming experience so going through your script was a great tutorial for me. I was able to edit with my values and it ran perfectly. Thanks for the help!

          Mike

          Comment


            #6
            Originally posted by sblamjo View Post
            Sparkman,

            This is great and exactly what I needed! I'm very new to scripting but do have some VB programming experience so going through your script was a great tutorial for me. I was able to edit with my values and it ran perfectly. Thanks for the help!

            Mike
            Hi Mike,

            Glad I was able to help.

            Cheers
            Al
            HS 4.2.8.0: 2134 Devices 1252 Events
            Z-Wave 3.0.10.0: 133 Nodes on one Z-Net

            Comment


              #7
              Originally posted by mrhappy View Post
              There has never been one for the name that I remember in HS2 or HS3, I guess the idea was that you would tend to know the name so just write it in manually rather than need a variable for it.

              This is unfortunate. I'm new to HS3 and setting up some initial events. This was one of the first replacement variables I went looking for and could not find. :/ I wanted to make a rather simple singular catch-all event for alerting me to lock status changes, and not have to write an event for each individual lock.

              Perhaps there is a now a way to perform this from within the email template given it has been two years since this thread was active, but without a direct replacement variable I need to use a script? That seems overly complex for a simple task.

              Comment


                #8
                Originally posted by scorp508 View Post
                This is unfortunate. I'm new to HS3 and setting up some initial events. This was one of the first replacement variables I went looking for and could not find. :/ I wanted to make a rather simple singular catch-all event for alerting me to lock status changes, and not have to write an event for each individual lock.

                Perhaps there is a now a way to perform this from within the email template given it has been two years since this thread was active, but without a direct replacement variable I need to use a script? That seems overly complex for a simple task.
                This may help you: https://board.homeseer.com/showthread.php?t=172326

                Cheers
                Al
                HS 4.2.8.0: 2134 Devices 1252 Events
                Z-Wave 3.0.10.0: 133 Nodes on one Z-Net

                Comment


                  #9
                  Originally posted by sparkman View Post
                  Well hello there, that looks like a lot of good work already done for the community. Thank you for sharing this as I suspect it will indeed help get me to where I'd like to be. Still wouldn't mind that replacement variable existing...

                  Comment


                    #10
                    Originally posted by scorp508 View Post
                    This is unfortunate. I'm new to HS3 and setting up some initial events. This was one of the first replacement variables I went looking for and could not find. :/ I wanted to make a rather simple singular catch-all event for alerting me to lock status changes, and not have to write an event for each individual lock.

                    Perhaps there is a now a way to perform this from within the email template given it has been two years since this thread was active, but without a direct replacement variable I need to use a script? That seems overly complex for a simple task.
                    I was hoping to be able to do much the same thing to combine some of the hundreds of individual events I have. I am not a programmer, and have no idea how to make something like this work.

                    For example, I have 21 Aeon Gen5 multisensors installed throughout the house. I have an individual event that alerts if a temperature crosses above a threshold, and reports if the temperature returns to normal. That itself is 42 separate events just to cover these sensors. I have similar events for doors, windows, glass, motion, PHLocation, etc., etc. Nearly 1000 events running, most of which should be able to be consolidated down.

                    I set up the groups of sensors in EasyTrigger, but I cannot get the Pushover output to differentiate between the name of each sensor. There should be a way to take the device name and current value, and plug it into a SINGLE Pushover message with replacement variables, instead of a separate event. Things like $date work, but nothing that will give me the correct device name and value for a different sensor, feeding into the same event.

                    I imagine there are scripts to do what I am looking for, but I don't have the knowledge to build something like this. It would be much easier to be able to plug replacement variables in that would allow outputs to be run through a single event.

                    Comment


                      #11
                      Perhaps Spud can find a way to add this functionality to his EasyTrigger plug-in - or create a new plug-in to do it. Have you posted your problem on his forum?
                      Mike____________________________________________________________ __________________
                      HS3 Pro Edition 3.0.0.548, NUC i3

                      HW: Stargate | NX8e | CAV6.6 | Squeezebox | PCS | WGL 800RF | RFXCOM | Vantage Pro | Green-Eye | Edgeport/8 | Way2Call | Ecobee3 | EtherRain | Ubiquiti

                      Comment


                        #12
                        No, but that is a great idea. Thanks!

                        Comment

                        Working...
                        X