Metadata-Version: 1.1
Name: timevortex.currentcost
Version: 2.4.13
Summary: TimeVortex module that collect CurrentCost data.
Home-page: https://github.com/liogen/timevortex.currentcost
Author: Pierre Leray
Author-email: pierreleray64@gmail.com
License: MIT
Description: ======================
        timevortex.currentcost
        ======================
        
        .. image:: http://img.shields.io/travis/timevortexproject/timevortex.currentcost.png?branch=master
            :target: https://travis-ci.org/timevortexproject/timevortex.currentcost
            :alt: Travis CI Build Status
        
        .. image:: http://img.shields.io/pypi/v/timevortex.currentcost.png
            :target: https://pypi.python.org/pypi/timevortex.currentcost
            :alt: Latest Version
        
        .. image:: http://img.shields.io/pypi/dm/timevortex.currentcost.png
            :target: https://pypi.python.org/pypi/timevortex.currentcost
            :alt: Downloads
        
        .. image:: http://img.shields.io/badge/license-MIT-red.png
            :target: https://github.com/timevortexproject/timevortex.currentcost
            :alt: License
        
        ---------
        
        TimeVortex module that collect CurrentCost data.
        
        `CurrentCost EnviR 128 <http://www.currentcost.com/product-envir.html>`_ is an appliance that monitor your electricity consumption and provide an `API <http://www.currentcost.com/cc128/xml.htm>`_ to retrieve data from USB cable.
        
        timevortex.currentcost allow us to retrieve data from usb cable using `pyserial <http://pyserial.sourceforge.net/>`_ and transmit information to stdout or to `RabbitMQ <https://www.rabbitmq.com/>`_ using `Pika <http://pika.readthedocs.org/en/latest/>`_ module. 
        
        More precisly, this script collect instantaneous and historical data from Current Cost. It also take care of usb disconnection, Current Cost bad message format, timeout and power disconnection and send an error on stdout or on RabbitMQ each time for later anlysis. Also it create an udev rule to transform /dev/ttyUSB* to /dev/currentcost for serial port connection.
        
        For more information, full documentation is available on `readthedocs.org <http://timevortex-currentcost.readthedocs.org/en/latest/>`_
        
        Installation
        ------------
        
        Requirements:
        
          * Platform: Unix (only tested on Ubuntu 12.04)
          * Python 2.7
          * Pip (last version)
          * RabbitMQ (last version)
        
        To install this software, you need to install python 2.7 and pip
        
        .. code-block:: bash
          
          sudo apt-get install python python-pip
          sudo pip install --upgrade pip
        
        Then if you want to use it, you can install and configure RabbitMQ (change "admin" and "password" by your credential)
        
        .. code-block:: bash
          
          USERNAME="admin"
          PASSWORD="password" 
          echo "deb http://www.rabbitmq.com/debian/ testing main" > sudo /etc/apt/sources.list.d/rabbitmq.list
          wget http://www.rabbitmq.com/rabbitmq-signing-key-public.asc
          sudo apt-key add rabbitmq-signing-key-public.asc
          sudo apt-get update
          sudo apt-get install rabbitmq-server -y
          sudo service rabbitmq-server start
          sudo rabbitmq-plugins enable rabbitmq_management
          # If you get a 'command not found' error for this line, use: 
          # sudo /usr/lib/rabbitmq/bin/rabbitmq-plugins enable rabbitmq_management
          # sudo /usr/lib/rabbitmq/bin/rabbitmq-activate-plugins enable rabbitmq_management
          sudo rabbitmqctl add_user $USERNAME $PASSWORD
          sudo rabbitmqctl set_permissions -p / $USERNAME ".*" ".*" ".*"
          sudo rabbitmqctl delete_user guest
          sudo service rabbitmq-server restart
        
        Then you can install timevortex.currentcost
        
        .. code-block:: bash
          
          sudo pip install timevortex.currentcost
        
        To verify version of timevortex.currentcost installed package
        
        .. code-block:: bash
          
          pip show timevortex.currentcost
        
        Usage
        -----
        
        .. code-block:: bash
        
            $ sudo timevortex-currentcost -h
              usage: timevortex-currentcost [-h] [-v] [-c CONFIG_FILE]
        
              optional arguments:
                -h, --help            show this help message and exit
                -v, --verbose         activate verbose mode
                -c CONFIG_FILE, --config-file CONFIG_FILE
                                      path to configuration file
        
        By default:
        
        * Configuration file is located in /opt/timevortex/config.ini. You can override configuration file using -c option with a path to your new config file.
        
        Configuration file
        ------------------
        
        To configure easily your file, you will need to read our `Comparison and relation between data collected by a sensor and data representing a physical timeseries <http://timevortex.readthedocs.org/en/latest/presentation.html#sites-and-variables>`_
        
        Basicaly, to configure your timevortex.currentcost, we will have to define a "site_id" that represents your home, a "variable_id" that represents timeseries of your sensor, "chX_w" and "tmpr" that represents physical timeseries that you want to monitore in your home. Then, you have to configure RabbitMQ in order to send message to other services if you want.
        
        .. code-block:: ini
        
          [timevortex_currentcost]
          # Mandatory field used to regroup data per site.  
          site_id = <ENTER_A_SITE_ID_HERE>
          # Mandatory field used to flag data collected by CurrentCost device.
          variable_id = <ENTER_A_VARIABLE_ID_HERE>
          # Optional field used to store data collected by ch1 of CurrentCost device.
          ch1_w = <ENTER_A_OTHER_VARIABLE_ID_FOR_CH1_HERE>
          # Optional field used to store data collected by ch2 of CurrentCost device.
          ch2_w = <ENTER_A_OTHER_VARIABLE_ID_FOR_CH2_HERE>
          # Optional field used to store data collected by ch3 of CurrentCost device.
          ch3_w = <ENTER_A_OTHER_VARIABLE_ID_FOR_CH3_HERE>
          # Optional field used to store data collected by tmpr of CurrentCost device.
          tmpr = tmp
          # USB port adress to collect data of currentcost
          tty_port = /dev/currentcost
          # Timeout before sending an alert to inform problem with currentcost
          timeout_currentcost = 10
          # Time waited before retrying a connection to USB port
          usb_retry = 5
          # Log configuration path
          log_file = /opt/timevortex/timevortex-currentcost.conf
        
          [timevortex_messager]
          # RabbitMQ credential
          rabbitmq_username = <ENTER_RABBIT_MQ_USERNAME_HERE>
          rabbitmq_password = <ENTER_RABBIT_MQ_PASSWORD_HERE>
          rabbitmq_host = <ENTER_RABBIT_MQ_HOST_HERE>
        
          [timevortex_filestorage]
          # Folder path where to store data
          data_folder = /opt/timevortex/data
        
        Examples
        --------
        
        To see the current consumption on Current cost on stdout (without using RabbitMQ) use:
        
        In config file:
        
        .. code-block:: ini
        
          [timevortex_currentcost]
          site_id = liogen_home
          variable_id = electric_meter
          tty_port = /dev/currentcost
          timeout_currentcost = 10
          usb_retry = 5
          log_file = /opt/timevortex/timevortex-currentcost.conf
        
          [timevortex_messager]
          rabbitmq_username = 
          rabbitmq_password = 
          rabbitmq_host = 
        
          [timevortex_filestorage]
          data_folder = /opt/timevortex/data
        
        In your terminal:
        
        .. code-block:: bash
            
            $ sudo timevortex-currentcost
            {"variableID": "electric_meter", "dstTimezone": "UTC", "siteID": "liogen_home", "date": "2014-04-25T12:00:17.754959", "value": "CurrentCost electric_meter in liogen_home: TTY connection problem: /dev/currentcost is unreachable. Retry connection in 5 seconds.", "nonDstTimezone": "UTC"} 
            {"variableID": "electric_meter", "dstTimezone": "UTC", "siteID": "liogen_home", "date": "2014-04-25T12:00:22.769256", "value": "CurrentCost electric_meter in liogen_home: TTY connection problem: /dev/currentcost is unreachable. Retry connection in 5 seconds.", "nonDstTimezone": "UTC"}
            {"variableID": "electric_meter", "dstTimezone": "UTC", "siteID": "liogen_home", "date": "2014-04-25T12:00:22.769256", "value": "<msg><src>CC128-v1.29</src><dsb>00786</dsb><time>00:31:36</time><tmpr>19.3</tmpr><sensor>0</sensor><id>00077</id><type>1</type><ch1><watts>00405</watts></ch1></msg>", "nonDstTimezone": "UTC"}
        
        With rabbitMQ message over the network and verbose mode activated:
        
        In config file:
        
        .. code-block:: ini
        
          [timevortex_currentcost]
          site_id = liogen_home
          variable_id = electric_meter
          tty_port = /dev/currentcost
          timeout_currentcost = 10
          usb_retry = 5
          log_file = /opt/timevortex/timevortex-currentcost.conf
        
          [timevortex_messager]
          rabbitmq_username = admin
          rabbitmq_password = password
          rabbitmq_host = localhost
        
          [timevortex_filestorage]
          data_folder = /opt/timevortex/data
        
        In your terminal:
        
        .. code-block:: bash
        
            $ sudo timevortex-currentcost -v
            Starting current cost application
            Current time: 2014-04-25 12:01:34.350781
            Variable name: electric_meter
            Site name: liogen_home
            TTY port: /dev/currentcost
        
            {"variableID": "electric_meter", "dstTimezone": "UTC", "siteID": "liogen_home", "date": "2014-04-25T12:00:22.769256", "value": "<msg><src>CC128-v1.29</src><dsb>00786</dsb><time>00:31:36</time><tmpr>19.3</tmpr><sensor>0</sensor><id>00077</id><type>1</type><ch1><watts>00405</watts></ch1></msg>", "nonDstTimezone": "UTC"}
            {"variableID": "electric_meter", "dstTimezone": "UTC", "siteID": "liogen_home", "date": "2014-04-25T12:00:22.769256", "value": "<msg><src>CC128-v1.29</src><dsb>00786</dsb><time>00:31:36</time><tmpr>19.3</tmpr><sensor>0</sensor><id>00077</id><type>1</type><ch1><watts>00405</watts></ch1></msg>", "nonDstTimezone": "UTC"}
        
        If you want to send timeseries formatted message over RabbitMQ:
        
        In config file:
        
        .. code-block:: ini
        
          [timevortex_currentcost]
          site_id = liogen_home
          variable_id = electric_meter
          ch1_w = main_consumption
          tmpr = living_room_temperature
          tty_port = /dev/currentcost
          timeout_currentcost = 10
          usb_retry = 5
          log_file = /opt/timevortex/timevortex-currentcost.conf
        
          [timevortex_messager]
          rabbitmq_username = admin
          rabbitmq_password = password
          rabbitmq_host = localhost
        
          [timevortex_filestorage]
          data_folder = /opt/timevortex/data
        
        In your terminal:
        
        .. code-block:: bash
        
            $ sudo timevortex-currentcost -v
            Starting current cost application
            Current time: 2014-04-25 12:01:34.350781
            Variable name: electric_meter
            Site name: liogen_home
            TTY port: /dev/currentcost
        
            {"variableID": "electric_meter", "dstTimezone": "UTC", "siteID": "liogen_home", "date": "2014-04-25T12:00:22.769256", "value": "<msg><src>CC128-v1.29</src><dsb>00786</dsb><time>00:31:36</time><tmpr>19.3</tmpr><sensor>0</sensor><id>00077</id><type>1</type><ch1><watts>00405</watts></ch1></msg>", "nonDstTimezone": "UTC"}
            {"variableID": "main_consumption", "dstTimezone": "UTC", "siteID": "liogen_home", "date": "2014-04-25T12:00:22.769256", "value": "405", "nonDstTimezone": "UTC"}
            {"variableID": "main_consumption_kwh", "dstTimezone": "UTC", "siteID": "liogen_home", "date": "2014-04-25T12:00:22.769256", "value": "0.0", "nonDstTimezone": "UTC"}
            {"variableID": "living_room_temperature", "dstTimezone": "UTC", "siteID": "liogen_home", "date": "2014-04-25T12:00:22.769256", "value": "19.3", "nonDstTimezone": "UTC"}
            {"variableID": "electric_meter", "dstTimezone": "UTC", "siteID": "liogen_home", "date": "2014-04-25T12:00:22.769256", "value": "<msg><src>CC128-v1.29</src><dsb>00786</dsb><time>00:31:36</time><tmpr>19.3</tmpr><sensor>0</sensor><id>00077</id><type>1</type><ch1><watts>00405</watts></ch1></msg>", "nonDstTimezone": "UTC"}
            {"variableID": "main_consumption", "dstTimezone": "UTC", "siteID": "liogen_home", "date": "2014-04-25T12:00:22.769256", "value": "405", "nonDstTimezone": "UTC"}
            {"variableID": "main_consumption_kwh", "dstTimezone": "UTC", "siteID": "liogen_home", "date": "2014-04-25T12:00:22.769256", "value": "0.000123", "nonDstTimezone": "UTC"}
            {"variableID": "living_room_temperature", "dstTimezone": "UTC", "siteID": "liogen_home", "date": "2014-04-25T12:00:22.769256", "value": "19.3", "nonDstTimezone": "UTC"}
        
        Message send through RabbitMQ
        -----------------------------
        
        A message is a JSON containing this properties:
        
        :variableID: Unique device identifier
        :siteID: Name of the site
        :date: Date in UTC
        :dstTimezone: Timezone with DST
        :nonDstTimezone: Timezone without DST
        :message: Message to deliver through RabbitMQ
        
        Messages list:
        
        +-------------+---------------------------------+---------------------------------------------------+ 
        | Channel     | Message                         | Description                                       |
        +=============+=================================+===================================================+ 
        | error       | utils.TTY_CONNECTION_PROBLEM    | Send when TTY port is not reachable               |
        +-------------+---------------------------------+---------------------------------------------------+
        | error       | utils.CURRENTCOST_TIMEOUT       | Send when TTY port is connected but reach timeout |
        +-------------+---------------------------------+---------------------------------------------------+
        | error       | utils.CC_INCORRECT_MESSAGE      | Send when Currentcost send an invalid message     |
        +-------------+---------------------------------+---------------------------------------------------+
        | currentcost | CurrentCost XML message         | Send Currentcost XML message                      |
        +-------------+---------------------------------+---------------------------------------------------+
        
        Contribute
        ----------
        
        I am more than happy to accept external contributions like feedback, bug reports and pull requests. 
        
        Do not hesitate to post an `issue <https://github.com/timevortexproject/timevortex.currentcost/issues>`_ if you have any problem to install or to use this software.
        
        You can also use this way to ask for features request. I am also available to answer you on `Stack Overflow <http://stackoverflow.com/questions/tagged/timevortex.currentcost>`_
        
        Here is the development process to test and validate your features.
        
        1. Prepare your development environment:
        
            .. code-block:: bash
        
                # `Socat <http://www.dest-unreach.org/socat/>`_ is usefull to create socket connection between 2 files.
                $ sudo apt-get install socat vim git-core
                # Install virtualenv and virtualenvwrapper if it's not done.
                $ sudo pip install virtualenvwrapper
                $ mkdir ~/.virtualenvs
                $ vim ~/.bashrc
                # Modify your ~/.bashrc and add this 2 lines:
                # export WORKON_HOME=~/.virtualenvs
                # source /usr/local/bin/virtualenvwrapper.sh
                $ bash
        
        2. Go on `github <https://github.com/liogen/timevortex.currentcost>`_ and fork this project.
        
        3. Clone it on your conputer:
        
            .. code-block:: bash
        
                $ cd <your_workspace>
                $ git clone git@github.com:<username>/timevortex.currentcost.git
                $ git checkout develop
        
        4. Prepare your virtualenv
        
            .. code-block:: bash
        
                $ mkvirtualenv timevortex
                (timevortex)$ pip install paver
                (timevortex)$ paver prepare
        
        5. Add functional or unit tests
        
        6. Code your features
        
        7. To validate your implementation, launch:
        
            .. code-block:: bash
        
                (timevortex)$ paver validate
        
        8. Modify Todo, Changelog and update documentation
        
        9. Commit and push on github:
        
            .. code-block:: bash
        
                (timevortex)$ git add .
                (timevortex)$ git commit -a -m "<your commit message>"
                (timevortex)$ git push origin develop  
        
        10. Propose a pull request on github
        
        License
        -------
        
        The MIT License (MIT)
        
        Copyright (c) 2014 Pierre Leray
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Platform: UNKNOWN
Classifier: Development Status :: 5 - Production/Stable
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Education
Classifier: Intended Audience :: Information Technology
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: Unix
Classifier: Programming Language :: Python :: 2.7
Classifier: Topic :: Home Automation
Classifier: License :: OSI Approved :: MIT License
