Skip to main content
Warning: You are using the test version of PyPI. This is a pre-production deployment of Warehouse. Changes made here affect the production instance of TestPyPI (testpypi.python.org).
Help us improve Python packaging - Donate today!

TimeVortex module that collect CurrentCost data.

Project Description

TimeVortex module that collect CurrentCost data.

CurrentCost EnviR 128 is an appliance that monitor your electricity consumption and provide an API to retrieve data from USB cable.

timevortex.currentcost allow us to retrieve data from usb cable using pyserial and transmit information to stdout or to RabbitMQ using Pika 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

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

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)

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

sudo pip install timevortex.currentcost

To verify version of timevortex.currentcost installed package

pip show timevortex.currentcost

Usage

$ 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

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.

[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:

[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:

$ 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:

[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:

$ 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:

[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:

$ 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 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

Here is the development process to test and validate your features.

  1. Prepare your development environment:

    # `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 and fork this project.

  3. Clone it on your conputer:

    $ cd <your_workspace>
    $ git clone git@github.com:<username>/timevortex.currentcost.git
    $ git checkout develop
    
  4. Prepare your virtualenv

    $ 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:

    (timevortex)$ paver validate
    
  8. Modify Todo, Changelog and update documentation

  9. Commit and push on github:

    (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.

Release History

Release History

This version
History Node

2.4.13r204

History Node

2.4.13r203

History Node

2.4.13r202

History Node

2.4.13r201

History Node

2.4.13

History Node

2.4.12r198

History Node

2.4.12

History Node

2.4.11r197

History Node

2.4.11r195

History Node

2.4.11r194

History Node

2.4.11

Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
timevortex.currentcost-2.4.13r204.tar.gz (18.0 kB) Copy SHA256 Checksum SHA256 Source Dec 12, 2014

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting