Announcement

Collapse
No announcement yet.

Opening a can of worms

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

  • racerfern
    replied
    Bob_Linux_User Thanks, I'll take it and run with it, we'll see how far I get.

    Leave a comment:


  • Bob_Linux_User
    replied
    Below is a .vb script that writes my monthly power cost to a file. Maybe you can revise to meet your needs. Hope it helps.

    Code:
    '***************************************************************************
    '*                      Update Total Kilo-Watts Cost                       *
    '* This Script should be run by an Event which runs every hour and updates *
    '* a virtual device with the total watts being used at the time of the     *
    '* execution of the script. This value will be used to announce the value  *
    '* on the hourly chime.                                                    *
    '***************************************************************************
    
    
    Imports System.IO
    Imports System.Text
    
    Sub Main(parm as object)
       Dim kwatts1 as Double = 0
       Dim kwatts2 as Double = 0
       Dim total_kwatts as Double = 0
       Dim total_kwatts_Cost as Double = 0
       Dim total_MPower as Double = 0
       DIM MPower as Double = 0
       Dim SToday as Date = DateTime.Today 
       Dim STime as String = DateTime.Now.ToString("HH:mm:ss")
       Dim write_string as String = ""
       Dim device_ref as Integer
       Dim device_ref1 as Integer 
       DIM device_ref2 as Integer
       DIM device_ref3 as Integer
       Dim FILE_NAME As String = "C:\Program Files (x86)\HomeSeer HS3\Data\Monthly_KiloWatts_Cost.csv"
    
    
    '***************************************************************************
    '*                 Get Device Reference Number                             *
    '*                                                                         *
    '*     Note: You must change the Name String to Match Your Device          *
    '*           There is no error processing on this command                  *
    '***************************************************************************
    
      device_ref = hs.GetDeviceRefByName("1st Floor Power Total kwatts Cost")
      device_ref3 = hs.GetDeviceRefByName("1st Floor Power Total Monthly Power Cost")
      device_ref1 = hs.GetDeviceRefByName("1st Floor Power kW Hours 1")
      device_ref2 = hs.GetDeviceRefByName("1st Floor Power kW Hours 2")
    
    '***************************************************************************
    '*                    Get Current Device Value                             *
    '*                                                                         *
    '*     Get Today's Date and create a string to write to the Log and File   *
    '*                                                                         *
    '***************************************************************************
    
       Try
          kwatts1 = hs.DeviceValue(device_ref1)
          kwatts2 = hs.DeviceValue(device_ref2)
          MPower = hs.DeviceValue(device_ref3)
          total_kwatts = (kwatts1 + kwatts2)
          total_kwatts_Cost = (total_Kwatts * .08606)
          total_MPower = (MPower + total_kwatts_Cost)
          write_string = SToday & " " & STime & ";" & CStr(total_MPower) & ControlChars.CrLf
         hs.WriteLog("Total Monthly KiloWatts Cost",write_string)
    
       Catch ex as Exception
          hs.WriteLog("Total KWatts Cost",ex.Message)
       End Try  
    
     '***************************************************************************
    '*                 Check if File Exists and Write to File                  *
    '*                                                                         *
    '*        If the File Does Not Exist - Create the File and Write to File   *
    '*                                                                         *
    '***************************************************************************
    
       If System.IO.File.Exists(FILE_NAME) = True Then
               Dim objWriter As New System.IO.StreamWriter( FILE_NAME,True )
               objWriter.Write( write_string )
               objWriter.Close()
       Else
               Dim newWriter = System.IO.File.Create(FILE_NAME)
               newWriter.Close()  
               Dim objWriter As New System.IO.StreamWriter( FILE_NAME,True )
               objWriter.Write( write_string )
               objWriter.Close()
       End If
    
    
    End Sub

    Leave a comment:


  • racerfern
    started a topic Opening a can of worms

    Opening a can of worms

    I've succeeded in getting Modbus to read data from my inverter. Now I want to save that data to some type of ASCII file so I can read it later. XML, CSV, whatever.

    I've created virtual devices that capture power production every 15 minutes and also one that stores the total for the day. Now...

    How do I output those to some kind of file? I assume I'm entering the realm of scripts and therefore a can of worms. The last time I really coded was Fortan V longer ago than I can remember.

    If this post belongs in a different forum section, please advise.
Working...
X