Announcement

Collapse
No announcement yet.

Post ON Device Status to file for email send

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

    Post ON Device Status to file for email send

    I would like to be able to send a very brief file through the email out facility to my cell phone. The file would contain only the U/H for the ON devices. Do I need to build a script to generate the file or is there some other way?

    Thanks,
    Rick

    #2
    degabe,
    You will need to loop over all the devices and see if they are on. The create the email from that list.
    💁‍♂️ Support & Customer Service 🙋‍♂️ Sales Questions 🛒 Shop HomeSeer Products

    Comment


      #3
      I was hoping that someone had already created such a method. Any suggestion on example code that I code leverage? Should I take this to the scripting forum?

      Thanks,

      Comment


        #4
        degabe,
        This should get you started ...

        <pre class="ip-ubbcode-code-pre">
        dev_count = hs.DeviceCount ' get total number of devices
        For i = 1 To dev_count
        Set device = hs.GetDevice(i)
        strDeviceCode = device.hc & device.dc
        If hs.IsOn(strDeviceCode) Then
        msgbox (device.location & " " & device.Name & " is/are on")
        End If
        Next
        </pre>

        This will loop through all of your devices and popup a msgbox if the device is on.
        💁‍♂️ Support & Customer Service 🙋‍♂️ Sales Questions 🛒 Shop HomeSeer Products

        Comment


          #5
          Hi Rupp,

          Thanks for the help. Here's a semi-working script. Need to test out tonight.

          Rick

          sub main()

          Dim fso, txtfile
          Set fso = CreateObject("Scripting.FileSystemObject")
          Set txtfile = fso.CreateTextFile("C:\Program Files\HomeSeer\DATA\ONDEV.txt", True)


          dev_count = hs.DeviceCount ' get total number of devices
          For i = 1 To dev_count
          Set device = hs.GetDevice(i)
          strDeviceCode = device.hc & device.dc
          If hs.IsOn(strDeviceCode) Then

          ' Skip Message Box post
          ' msgbox (device.location & " " & device.Name & " is/are on")

          ' Write to file

          txtfile.WriteLine(device.location & " " & device.Name & " ON")
          End If
          Next

          txtfile.Close
          end sub

          Comment


            #6
            Here's a script that I use to email me the status of ALL devices each morning. You could simply select all those with only "ON" statuses.

            '===========================================================
            ' Name: Device Status Email
            ' Author: JR
            ' Credit: Thanks to mckillen_stephan in New Zealand for the initial work
            ' Date: June 2003
            ' Purpose: Captures status of devices and puts in email
            ' Requirements: HS must be email enabled
            ' Installation: 1) install in HS scripts directory
            ' 2) build event in HS that calls this script
            ' 3) change email address in code below
            ' Notes: none
            ' Called From: Event in HS
            ' Calls To: none
            '===========================================================

            sub main()
            Dim Dev_count
            Dim i
            Dim My_Dev_Count
            Dim Devices
            Dim My_Status
            Dim My_Status_Value
            Dim My_Device_String
            Dim last_change

            'determine # of devices
            My_Dev_Count = hs.DeviceCount
            My_Device_String ="" ' set to null

            'hs.speak "device count " & My_Dev_Count
            'msgbox My_Dev_Count

            '===========================================================
            'assemble for each device found
            '===========================================================
            For i = 1 to My_Dev_Count
            Set Devices = hs.GetDevice(i)
            my_status = hs.DeviceStatus(devices.hc & devices.dc) ' will return one of these values
            'hs.speak devices.hc & devices.dc
            select case my_status
            case 2 ' ON
            My_Status_Value = "ON "
            case 3 ' OFF
            My_Status_Value = "OFF "
            case 4 ' DIM
            My_Status_Value = "DIM "
            case else ' Don't know what it is
            My_Status_Value = ""
            End select

            s=hs.DeviceString(devices.hc & devices.dc) ' will return the string assigned to the device
            '===========================================================
            ' now need to remove any image tags - remove any characters between "&lt;" and "&gt;"
            '===========================================================
            x=instr(s,"&gt;")
            s=right(s,len(s)-x)
            '===========================================================
            ' will return the time of last change
            '===========================================================
            last_change = hs.DeviceLastChange(devices.hc & devices.dc)
            '===========================================================
            ' continue to concatinate the text of the email
            '===========================================================

            'My_Device_String = My_Device_String & devices.hc & devices.dc & " = " & devices.location & " " & devices.Name & " = " & my_status_value & vbnewline 'vbnewline creates a new line after each pass of the loop
            My_Device_String = My_Device_String & devices.hc & devices.dc & " = " & devices.location & " " & devices.Name & " = " & my_status_value & " " & s & " " & last_change & vbnewline 'vbnewline creates a new line after each pass of the loop
            'My_Device_String = My_Device_String & devices.hc & devices.dc & " = " & " " & devices.Name & " = " & VBVerticalTab & VBtab & VBtab & VBtab & my_status_value & " " & s & " " & last_change & vbnewline 'vbnewline creates a new line after each pass of the loop

            next
            '===========================================================
            'display message box requiring OK click
            'msgbox My_Device_String 'debug statement, will display limited # of findings (msgbox seems to be limited in length)
            'put # of devices comment as first line in display

            My_Device_String = "You have " & My_Dev_Count & " Devices " & vbnewline & My_Device_String
            '===========================================================
            'send a email
            '===========================================================
            'hs.SendEmail "sendto@this.address","fromEmail@this.address,"Subject",My_D evice_String
            'hs.speak "done"
            '===========================================================

            end sub

            Comment

            Working...
            X