Skip to content

Python API for talking to a MySensors gateway

License

Notifications You must be signed in to change notification settings

Zyell/pymysensors

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

60 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pymysensors

Python API for talking to a MySensors gateway (http://www.mysensors.org/). Currently supports serial protocol v1.4 and v1.5.

Does not support OTA updates.

Usage

Currently the API is best used by implementing a callback handler

import pymysensors.mysensors.mysensors as mysensors

def event(type, nid):
    print(type+" "+str(nid))

gw = mysensors.SerialGateway('/dev/ttyACM0', event)
gw.start()

In the above example PyMysensors will call "event" whenever a node in the Mysensors network has been updated.

The data structure of a gateway and it's network is described below.

SerialGateway
    sensors - a dict containing all nodes for the gateway; node is of type Sensor

Sensor - a sensor node
    children - a dict containing all child sensors for the gateway
    id - node id on the MySensors network
    type
    sketch_name
    sketch_version
    battery_level

ChildSensor - a child sensor
    id - Child id on the parent node
    type - Data type, S_HUM, S_TEMP etc.
    values - a dictionary of values (V_HUM, V_TEMP, etc.)

Getting the type and values of node 23, child sensor 4 would be performed as follows:

type = gw.sensors[23].children[4].type
values = gw.sensors[23].children[4].values

PyMysensors also supports three other settings. Debug mode, which prints debug information, persistence mode, which saves the sensor network between runs. With persistence mode on, you can restart the gateway without having to restart each individual node in your sensor network. To enable persistance mode, the third argument in the constructor should be True. Debug mode is enabled by setting SerialGateway.debug = True. A path to the config file can be specified as a fourth argument.

import pymysensors.mysensors.mysensors as mysensors

gw = mysensors.SerialGateway('/dev/ttyACM0', None, True, 'somefolder/mysensors.pickle')
gw.debug = True
gw.start()

About

Python API for talking to a MySensors gateway

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%