Git Product home page Git Product logo

pyalertme's Introduction

PyAlertMe

Build Status codecov

PyAlertMe is a set of classes which, when used in conjunction with a Digi XBee (ZigBee) module, can be used to simulate an AlertMe (Lowes Iris, Hive, British Gas Safe and Secure) Hub, SmartPlug or Sensor.

Use

Hub

# Setup Serial
XBEE_PORT = '/dev/tty.usbserial-DN018OI6'
XBEE_BAUD = 9600
ser = serial.Serial(XBEE_PORT, XBEE_BAUD)

# Define Callback (Optional)
def callback(type, node_id, field, value):
    if type == 'Attribute':
        print("Attribute Update\n\tNode ID: " + node_id + "  Field: " + field + "  Value: " + str(value))
    elif type == 'Node':
        print("Node Update\n\tNode ID: " + node_id + "  Field: " + field + "  Value: " + str(value))

# Create Hub Object
hub_obj = Hub(callback)
hub_obj.start(ser)

Example output:

2017-08-30 21:51:21,138 INFO zbhub 134 New Device 00:0d:6f:00:00:1b:6a:6a Fully Associated
Attribute Update [Node ID: 00:0d:6f:00:00:1b:6a:6a	Field: manu	Value: AlertMe.com]
Attribute Update [Node ID: 00:0d:6f:00:00:1b:6a:6a	Field: type	Value: Door/Window sensor]
Attribute Update [Node ID: 00:0d:6f:00:00:1b:6a:6a	Field: version	Value: 55979]
Attribute Update [Node ID: 00:0d:6f:00:00:1b:6a:6a	Field: manu_date	Value: 2008-04-17]
{   '00:0d:6f:00:00:1b:6a:6a': {   'manu': 'AlertMe.com',
                                   'type': 'Door/Window sensor',
                                   'version': 55979},
    '00:0d:6f:00:00:1b:76:ea': {   'manu': 'AlertMe.com',
                                   'type': 'Lamp',
                                   'version': 1905},
    '00:0d:6f:00:00:78:61:c0': {   'manu': 'AlertMe.com',
                                   'type': 'Button Device',
                                   'version': 34667},
    '00:0d:6f:00:03:bb:b9:f8': {   'manu': 'AlertMe.com',
                                   'type': 'SmartPlug',
                                   'version': 9586}}
Select Device:Attribute Update [Node ID: 00:0d:6f:00:03:bb:b9:f8	Field: power_demand	Value: 0]
Attribute Update [Node ID: 00:0d:6f:00:03:bb:b9:f8	Field: trigger_state	Value: 0]
Attribute Update [Node ID: 00:0d:6f:00:03:bb:b9:f8	Field: temperature	Value: 99.05]
Attribute Update [Node ID: 00:0d:6f:00:03:bb:b9:f8	Field: tamper_state	Value: 1]
Attribute Update [Node ID: 00:0d:6f:00:00:1b:6a:6a	Field: manu	Value: AlertMe.com]
Attribute Update [Node ID: 00:0d:6f:00:00:1b:6a:6a	Field: type	Value: Door/Window sensor]
Attribute Update [Node ID: 00:0d:6f:00:00:1b:6a:6a	Field: version	Value: 55979]
Attribute Update [Node ID: 00:0d:6f:00:00:1b:6a:6a	Field: manu_date	Value: 2008-04-17]
Attribute Update [Node ID: 00:0d:6f:00:03:bb:b9:f8	Field: power_demand	Value: 0]

The hub supports the following devices:

  • SmartPlug
  • Power Clamp
  • Button Device
  • PIR Device
  • Door/Window sensor
  • Alarm Detector
  • Keyfob Device
  • Beacon
  • Lamp

SmartPlug

# Setup Serial
XBEE_PORT = '/dev/tty.usbserial-DN018OI6'
XBEE_BAUD = 9600
ser = serial.Serial(XBEE_PORT, XBEE_BAUD)

# Create SmartPlug Object
device_obj = SmartPlug()
device_obj.start(ser)

XBee Setup

Configure XBee as follows: XBee Modem XB24-ZB, ZIGBEE Coordinator API, Version 21A7 (or better). Alternatively use you can use scripts/setup-xbee.py to configure the Xbee.

Coordinator (Hub)

  • ZigBee Stack Profile (ZS): 2
  • Encryption Enable (EE): 1
  • Encryption Options (EO): 1
  • Encryption Key (KY): 5a6967426565416c6c69616e63653039
  • API Enable (AP): 2
  • API Output Mode (AO): 3

Router (Device)

  • ZigBee Stack Profile (ZS): 2
  • Encryption Enable (EE): 1
  • Encryption Options (EO): 0
  • Encryption Key (KY): None
  • API Enable (AP): 2
  • API Output Mode (AO): 3

Example Use

See examples/hub-example.py for example Hub. See examples/smartplug-example.py for example SmartPlug.

Credits

Huge thanks to Desert Home http://www.desert-home.com/2014/02/raspberry-pi-and-lowes-iris-smart-switch.html from which this project originates from.

pyalertme's People

Contributors

jamesleesaunders avatar jrjefferies avatar pyup-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pyalertme's Issues

Any code for the Lamp?

Just noticed that the README says that there's support for the Lamp device, but I can't spot any code for it.

no response to 'SH'

From @GoogleCodeExporter on June 22, 2015 13:48

What steps will reproduce the problem?
1. xbee.send('at', chr(9), command="SH") 
2. response = xbee.wait_read_frame()
3.

What is the expected output? What do you see instead?

the wait command doesn't respond.

When I use serial.write() followed by serial.read(), I do get a response for 
"ATSH"
I tried a variety of commands and a variety of frame ids, but "sh" will only 
hang.

What version of the product are you using? On what operating system?
The latest, running on OSX

Please provide any additional information below.

Original issue reported on code.google.com by [email protected] on 8 Sep 2014 at 3:48

Copied from original issue: cthuun/python-xbee#56

Tidy up and rename attributes

Check each parse_xxx function and rename all the attributes to a standard.
State, Temperature, Power etc.

Try to mirror the Attribute names used by the Hive api.

Unrecognised Device Status from Power Clamp

We see the following error from Hub.py when receiving a Status Update frame from AlertMe PowerClamp:
ERROR:root:Unrecognised Device Status

Frame data:
\t\x00\xfb\x1b\x97H\x00\x00H\x0c\x9c\x01\xd4\xff\x00\x00

Logs:

# 2017-04-19 22:38:33,316 DEBUG base  Received Message: {'profile': '\xc2\x16', 'source_addr': 'hp', 'dest_endpoint': '\x02', 'rf_data': '\t\x00\xfb\x1b\x97H\x00\x00H\x0c\x9c\x01\xd4\xff\x00\x00', 'source_endpoint': '\x02', 'options': '\x01', 'source_addr_long': '\x00\ro\x00\x00\xc2\x8a\xb2', 'cluster': '\x00\xf0', 'id': 'rx_explicit'}
# 2017-04-19 22:38:33,316 DEBUG base  Received AlertMe Specific Profile Packet
# 2017-04-19 22:38:33,316 DEBUG hub   Received Status Update
# 2017-04-19 22:38:33,317 DEBUG hub   Sending Missing Link
# 2017-04-19 22:38:33,317 DEBUG base  Sending Message: {'profile': '\xc2\x16', 'dest_addr_long': '\x00\ro\x00\x00\xc2\x8a\xb2', 'description': 'Missing Link', 'src_endpoint': '\x02', 'cluster': '\x00\xf0', 'dest_addr': 'hp', 'data': '\x119\xfd', 'dest_endpoint': '\x02'}
# 2017-04-19 22:38:33,348 DEBUG base  Received Message: {'profile': '\xc2\x16', 'source_addr': 'hp', 'dest_endpoint': '\x02', 'rf_data': '\t\x00\x81\x00\x00', 'source_endpoint': '\x02', 'options': '\x01', 'source_addr_long': '\x00\ro\x00\x00\xc2\x8a\xb2', 'cluster': '\x00\xef', 'id': 'rx_explicit'}

Occasionally Hub discovery discovers itself

At times when running Hub.discovery() it discovers itself. Assumedly because it responds to its own broadcasts.

When this happens we wee the error:
2017-04-19 21:05:00,705 ERROR hub Unrecognised Cluster Command: '\xfc'

On receiving a frame we should make an assessment as to whether the frame has come from itself - it this is the case do not add to list of discovered nodes.

Type Req / Hardware Join 1 & Range Test / Hardware Join 2

Investigate similarity or differences between:

  • Type Request & Hardware Join 1
  • Range Test RSSI Request & Hardware Join 2

Are they the same thing? Look at Desert Home notes again.
Look at commented out code in Device.py.
Look at messages dict in Base.py
Will a device actually join with type / RSSI request instead?

Fix broken range test reply code in Device.py

Iris Devices into Home Assistant

Hi James,

My name is Rick and I recently saw on Dave's (desert-home) site that you're actively doing some work on the AlertMe zigbee devices. I was excited to see this, as I've been trying to migrate off of Lowe's system for a while now and do not wish to abandon all of the devices that I've acquired.

Finding your project is almost perfect timing, as I'd like to introduce you to a community of users who may be able to help integrate your work into a component for Home Assistant.

If you've not heard of Home Assistant yet, I think you will love it.
The system is designed to run on RaspberryPi and is built on Python3. The community has already developed over 650 components for integration and it has been a lot of fun too; great community.

Anyway, the reason I think you will be excited to get involved is that in home assistant you can write your own custom components and eventually merge them into the build. Another user has recently gotten the USB Z-wave plus/zigbee dongle HUSBZB-1 working with zigbee devices. I purchased this device, but found that it was limited in that I couldn't get it to communicate eith Iris gen1 devices. When I found your project, I thought that you'd be interested in the efforts to get zigbee up and running in home assistant.

At the core of the zigbee component is a github project called bellows which looks promising.

I had reached out to Dave a while back, who also seemed interested in Home Assistant, but he too was a bit too busy. I was very happy to see that you've picked up some of this work! I do not have an XBee to test your project out, but am wondering if it could work on the HUSBZB-1. I'll need to investigate, as I have just found your work this morning...but do hope you will give home assistant a look.

You can find me in the gitter chatroom for home assistant or email me if you have questions at [email protected]

Thanks!

Scheduled broadcasts

Can I get the Pi-Hive class objects (Hub, SmartPlug) to send out regular messages like broadcasts and keep alive messages?

Is this the responsibility of the class object or a wider application programme?

No audible feedback from Keyfob

Keyfobs paired with the official Hubs emit a three-tone sound when a successful press has been registered. This would be a very useful feature for this module; both for audio feedback as originally used, but also as a 'find lost keys' helper.

Query about zbhub

I have spent most of the day working through the structure and trying to work out why we are messing up the joining. I think I have found something. The import structure goes like this (I think)
console-example -> zbhub -> zbnode -> node
Note - We can replace console-example with hub-example - it calls the same stuff

We we initiate the ZBHub, we initiate the ZBNode. This starts the zigbee library with a callback of 'receive_message'

receive_message does three things

  • parse_message (generated a list of messages to send)
  • process_message (we'll come back to this)
  • sends the messages generated by parse_message

The next thing to note is the zbnode process_message is documented as being STUB to be overwritten by zbhub
So in zbhub the process_message does the following

  • finds the device object (using device_obj_from_addr)
  • sets the device object attributes

Now the problem is that device_obj_from_addr does the following

  • create the node_obj if it does not exist
  • sends AlertmeCluster commands if the done_obj.type does not exist
    • generate_message (a zbnode procedure)
    • send_message (a zbnode procedure)

Because the device_obj_from_address is sending directly from the zbnode class, these message are

  • Sent before the parse_message generated messages
  • Send potentially too early

It looks like the messages being generated in device_obj_from_address are in the wrong place. This may be a leftover from an earlier version (sorry, not checked the commit record).

So we can do a couple of things. Move the send messages from the device_obj_from_addr (feels the correct thing to do), or move the process_message until after the parse_message queue is send.
I probably need guidance on what direction to go to..

Regards,
James

Contact sensor data error

Once paired, when the device transmits the following error is logged:

2017-10-27 00:54:38,839 CRITICAL zbnode 418 XBee Error: need more than 2 values to unpack

I've paired it with my AlertMe Hub and I'm in the process of checking / updating the firmware to see if that is the issue. I'll report back.

Develop Command Line Interface

Develop command line interface to work with the Pi-Hive classes.

? WebInterface
? Run as service
? MVC
? Do I need one for Hub and another for SmartPlug

Upon discovery and association, devices remain in pairing mode.

Just getting to grips with the module and have managed to get it controlling some SmartPlugs pretty well, but I'm having difficulty getting devices to 'pair' with the XBee. Using your hive-smartplug-xbee project code the SmartPlugs once discovered drop out of pairing or range-finding mode and behave perfectly well. However, using the discovery feature of this module causes devices to associate at least well enough to show up when using hub_obj.list_devices(), but they are generally unreliable in returning data, while the switch_state of SmartPlugs associated using the hive-smartplug-xbee code is seen and logged instantaneously.

I'm in the process of associating some Buttons and Motion Sensors for testing, but they are remaining in range finding double-flash mode and are not reliably returning data when triggered. Are there further steps I should be taking in my code to properly associate them, other than calling hub_obj.discovery()?

Thanks!

Create examples code

Develop 4 example files:

  1. Simple Hub example
  2. Simple SmartPlug example
  3. REST example
  4. Console example

Use real AlertMe hub hardware?

Is it possible to use the real AlertMe hub hardware and run Python and PyAlertMe on it (instead of a ZigBee) or is it basically an expensive brick at this time?

Improve Logging

I still don't get Python Logging! Investigate Beth method of logging in classes.
Consider Debug and Verbose modes.

Work out own address

Function to work out own address.
On hub possibly add the hub itself to the list of nodes creating itself in the DB.

Interested in contributing

James,

I have been playing with your code. I have been working on your console-example.py, but I have found some issues with your code
pyalertme/node.py - last line
self._logger.debug("Attribute Update [Node ID: " + self.id + "\tField: " + attr_name + "\tValue: " + str(attr_value) + "]")
#this was a direct print, so it messed up the console.

zbhub.py - in call_device_command, you were sending the device_id, not the device_obj to the two called modules. They expect the device_obj
"""
this_node_object = self.device_obj_from_id(device_id)
if command == 'switch_state':
self.send_switch_state_request(this_node_object, value)
elif command == 'mode':
self.send_mode_request(this_node_object, value)
#with these two changes I can get the associated smartplug controlled by the console commands.

I would love to contribute to your code in whatever way I can. Though I am not a professional programmer, I do know some python.
My setup is

  • Alertmehub, smartplugs, buttons, infrared sensors, door sensor, power_clamp (soon all to be defunked)
  • Smartthings hub, hive plug, hive plug
  • Hive Hub, hive central heating, hive door sensor, hive infrared sensor
  • Pi with xbee module (one Alertme smartplug associated, one not completing)

I would like to get to the point that I can run all the Alertme stuff (primarily smartplugs) from the pi with a rest API (driven be Alexa or Smartthings)...

Regards,
James J

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.