Editing SmartPlug Help File

Jump to navigation Jump to search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.

Latest revision Your text
Line 2: Line 2:
 
   
 
   
  
Help file for smart plug application ( Documentation for Ver7 ).  You can also get a lot of information about how the program works by looking at the GUI and its explanation: '''[[SmartPlug GUI Images]]'''.
+
 
 +
 
 +
 
 +
Help file for smart plug application ( Ver4 )
 +
 
 +
 
 +
   
 +
 
 +
 
  
  
 
= Application Features =  
 
= Application Features =  
  
*Works with multiple smartplugs.
 
*Provides on, off, timing, and  energy recording functions from a graphical user interface ( gui ), see '''[[SmartPlug GUI Images]]'''.
 
*Supports graphing of data.  Currently power and energy over time.  Multiple devices on one graph.
 
*Supports comma separated values ( csv ) output of data to text files.
 
*Saves data to a sql lite database that you can use any way you wish.
 
*Highly configurable.
 
  
= Two Applications =
+
        Works with multiple smartplugs
 +
        Provides on off functions from a graphical user interface ( gui )
 +
        Highly configurable
 +
        Supports graphing of data
 +
        Supports csv output of data
 +
        Saves data to a sql lite database that you can use any way you wish
  
This program is actually 2 main programs. The first program is for control of the smartplugs and capture of data, the second for the graphing and processing of the data.  The main routines may be run by respectively running: smart_plug.py graph_smart_plug.py  I think ( but have not tested ) they may be run at the same time.
 
  
= Download and Install =  
+
============ First Use of the SmartPlug Application ===============
  
There is really no install program.  Currently the application is intended for those who have at least a little familiarity with Python coding and can just insert the downloaded code into their development environment and run it. Code at '''[https://github.com/russ-hensel/smart_plug/tree/master russ-hensel/Smart_plug Application ]''' For most of you it will not run due to dependency problems.  You will need to add them.  Pretty much read the error messages and install the missing code.  I use Anaconda Spyder so my preferred tool is conda ( conda install pyHS100 ).  If conda does not work or you do not use it use pip.  pyHS100, a library for smart plugs is pretty likely to be missing ( pip install pyHS100) .  Depending on your installation there may be more.
+
        The application is set up with a default database, but it need some information
 +
        on your devices.
  
Much of the application is configurable through the parameter.py file, but the default should give you an application that runs, including a default database.  You probably will not be able to talk to your smartplugs, because the parameters do need to be told what and where ( tcpip address ) they are.
 
  
So to tell the application about your plugs. You should know the address of each plug. If not you might want to use an application like advanced ip scanner ( google it ). The smartplug gives up very little information on my scans, but run the scan with the plug plugged in and out, and the address that appears ( or disappears ) it the address of your device.
+
        .........
  
The section of parameters.py that locates the device looks like this:
+
=  How to Use the Parameter File =
  
        self.device_list      =  [
+
You need a text editor sutible for .py files to manage the parameter file ( parameters.py )
                { "name": "device_1",  "tcpip": "192.168.0.209", "more": None, "gui_label": None, "gui_combo": None  },
+
This includes most text editorsI particurlay like:
                { "name": "device_2",  "tcpip": "192.168.0.209", "more": None, "gui_label": None, "gui_combo": None },
 
                { "name": "device_3",  "tcpip": "192.168.0.209", "more": None, "gui_label": None, "gui_combo": None  },
 
                                  ]
 
it is a list of dictionaries.  The entry above is for 3 devices ( but I only have one, so the tcpip address is repeated ) For now only worry about the tcpip address and the name for the device; put in as many devices as you wish to control.
 
  
With the edited parameter file saved, restart the application.  You should be able to "talk" to your devices.  Not working?  Double check or email me.
+
    notepad++
 +
    geany
  
In the future I may try to add some autodetect featuresThere is a routine to discover the plugs in the pyHS100 library, but it does not work for me.
+
You can also use the editor that comes in many python development enviroments, the simples of
 +
which may be Idle.  But there are many many othersIf you are reading this you probably have
 +
some experience.
  
= How To:... =
+
    A couple of gotchas to watch out for.
 +
        * Python cares about capitalization, use the capitalization indicated in the default
 +
          files and the example code.
 +
        * Python also cares a lot about how lines are indented. Do not change the indentation from
 +
          the sample files, and always indent using spaces ( not tabs. most text editors will use spaces
 +
          automatically for .py files, even if you use the tab key )
  
Some stuff is pretty obvious from the GUI, take a look at it as well as reading the material here [[SmartPlug GUI Images]].
+
    First time editing of the parameters.py file
  
 +
        Use your chosen text editor to open the file parameters
  
== Either/Both Applications ==
 
  
Some operations work the same way in both applications
+
specify in parameters.py with
*Install: see section above.
+
    self.ex_editor          = r"D:\apps\Notepad++\notepad++.exe"  # use r" or the backslashes will not work, or you can use forward slashes insterd they may be wrong
*Debug:  see section below.
+
    but they work.
*Edit the parameter file:  *Change Parameters: Use the application button <Edit Parms> ( after configuring for your editor ) or any text editor suitable for Python ( no tabs ) on the file parameters.py.  See also: The section below, [[Configuration Files For Python]] and [[SmartPlug GUI Images]]
 
*Edit the log file:  This is a standard python logging file.  Useful for debugging and general tracking of the applicationYou can set the level of the logging using the parameter file.
 
*Backup the database: Just make a copy of the database using your file manager.  It is all in one file, but you can make multiple databases.
 
*Add a new device or change device data: edit the parameter file, device_list.  Restart the application. <Restart> will do it
 
*Quick Restart of the application:  As perhaps after a parameter change.  Use the <Restart> button.  See also: [[SmartPlug GUI Images]]
 
*Make a graph: Use the graphing application or Live Graph ... see sections below. See also: [[SmartPlug GUI Images]].
 
*Switch databases:  Use browse control on GUI.  Please do not change while db operations are active.  
 
  
*Get Help: Press the <Help> button.  Depending on how it is setup in parameters.py you may see this page.
 
*Work with text in message area:  See buttons to the left of the area.
 
  
== Smart Plug Application ==
 
This is the application in smart_plug.py  Many action are in the GUI see: [[SmartPlug GUI Images]].
 
*Turn plug on/off: Use the <Plug On> checkbox.
 
*Record data from Plug: Data is saved to the database. Use the check box <Record>.
 
*Monitor Plug: continuously monitor and display
 
*Set a timer:  Use drop down list to select time, then press <Start Timer..> Time remaining will be displayed on the GUI.
 
*Find plugs on your network:  Press the <Probe Plugs> button.  Scan can take a long time ( minutes ).  Use parameters to control how the scan is conducted.
 
*Get Data about a Plug:  Press the button with the plug name.  Info appears in the message area.
 
*Start a live graph:  Use the <Live Graph> checkbox, you should have monitor checked for some devices.  Data is accumulated in memory, not the database. Live graph is a graph of the data as it comes in.  Will only collect data for devices whose monitor button is turned on.  Data is deleted when graph is stopped.
 
*Save CSV file: <Save CSV>  Save the data to a CSV file, live_data.csv.  Saves time ( python timestamp ) and power.  Delimiter is actually a tab character.  Data is appended if file already exists.
 
  
== Graphing Application ==
 
  
This is the application in smart_plug_graphing.py.  It generally preforms operations on the database, mostly graphing, but also some other operations.
 
*Choose what data to graph - which devices, and for what time period. There are several ways to do this:
 
**Set the dates in the parameter file.
 
**Use the date and time controls on the GUI. 
 
**Use the radio button controls on the GUI.
 
*Save graph as .png file: Icon on the graph
 
*Zoom in on part of the graph: Icon on the graph
 
*Change the zero point ( time ) for the graph -- see parameters.py
 
*Move the graph lines around within the graph frame: Icon on the graph
 
*Change the units on the time scale of the graph -- see parameters.py
 
*Change the max and minimum values on the graph -- see parameters.py or zoom the graph
 
*Export a csv file:  Saves time ( python timestamp ), power and energy.  Delimiter is actually a tab character.  File name is data.csv Data is appended if file already exists.
 
*Create a new empty database:  There is a button on the graphing application.  First set the file name ( including full path ) to a non existent file.  You can browse to an existing file and then edit the name.
 
*Set default size of the graph: parameters.py.
 
  
=  How to Use the Parameter File =
 
See: [[Configuration Files For Python]]
 
You need a text editor suitable for .py files to manage the parameter file ( parameters.py )
 
This includes most text editors.  I particularity like:
 
  
*notepad++
 
*geany
 
  
You can also use the editor that comes in many python development environments, the simplest of
 
which may be Idle.  But there are many many others.  If you are reading this you probably have
 
some experience.
 
  
Once you configure an editor in parameters.py you can edit from the <Edit Parms> in the GUI ( see below )
 
  
When editing there are couple of gotchas to watch out for.
+
   
* Python cares about capitalization, use the capitalization indicated in the default files and the example code.
 
* Python also cares a lot about how lines are indented. Do not change the indentation from the sample files, and always indent using spaces ( not tabs. most text editors will use spaces automatically for .py files, even if you use the tab key )
 
  
Editing of the parameters.py file
 
 
*Edit so the program finds your devices.
 
**See above in Download and Install
 
*Enable your favorite editor to work with the application.
 
**self.ex_editor          =  r"D:\apps\Notepad++\notepad++.exe"  # use r" or the backslashes will not work, or you can use forward slashes instead they may be wrong but they work.
 
*Lots of other settings:
 
**Read the comments in parameters.py and change as desired.  If a setting does not work let me know.
 
*If you mess up.
 
**Re download and get back to the original file.
 
  
 
= Working With Database Files =  
 
= Working With Database Files =  
Line 129: Line 83:
  
  
 
  
  
= The GUI =
 
  
see: [[SmartPlug GUI Images]]
+
 
 +
 
 +
 
 +
 
 +
= The GUI =
 +
 
 +
 
 +
= General =
 +
 
 +
 
 +
 
 +
 
 +
= System Buttons =
 +
 
 +
                    * The edit functions work only after you have configured parameters.py for your systems text editor
 +
<Edit Log>          >Open the application python log file using the system editor specified in parameters.py file
 +
<Edit Parms>        >Open the application parameters.py file using the system editor, after the file has been modified
 +
                    the system can be quickly restarted using the Restart button.
 +
 
 +
 
 +
<Restart>          >Quickly restarts the system after the parameters.py file is changed or any time you want to restart the system
 +
                    from its current defaults
  
 
= Debugging =  
 
= Debugging =  
  
There are several application outputs that may be useful for debugging.
 
  
* Watch the GUI
+
        Watch the console for error messages and in particular look for modules that may be missing ( I do not provide these, pip or conda should install them )
* Check the Python console.
+
 
* Look at the python log file ( use the GUI button <Edit Log> ( specify your editor in parameters.py first ) or use your editor on the default name of the log file ...\smart_plug\smart_plug.py_log.
 
  
Most issues will probably be missing libraries, parameters.py issues, or just bugs in my code (email me ).
 
  
<!-----------
 
  
  
Line 152: Line 121:
 
= Work Flow Overview =
 
= Work Flow Overview =
  
== Just a bit of theory the may be helpful - Some Definitions ==
+
================= Just a bit of theory the may be helpful - Some Definitions =
  
 
Databases
 
Databases
Line 173: Line 142:
 
     It may give you useful feedback on what the system is doing.
 
     It may give you useful feedback on what the system is doing.
  
this cannot bee seen
 
------------->
 
  
= Links =
 
  
*[[Python Control of Smart Plugs]] main page for this project
 
* see categories below as well
 
 
  
[[Category:Python SmartPlug]] [[category:Python]] [[category:Python Projects]]
+
 
 +
 
 +
 
 +
 
 +
 
 +
 
 +
[[category:Python]]

Please note that all contributions to OpenCircuits may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see OpenCircuits:Copyrights for details). Do not submit copyrighted work without permission!

Cancel Editing help (opens in new window)