XBOS Docs
Search…
Python
Python bindings to interact with all XBOS services.

Installation

Install using pip. Currently requires Python 2.
1
pip install xbos
Copied!

Usage

Almost all interactions in XBOS begin with a BOSSWAVE client:
1
from xbos import get_client
2
3
# uses $BW2_AGENT, $BW2_DEFAULT_ENTITY by default
4
client = get_client()
5
client = get_client(agent="172.17.0.1:28589",entity="/home/oski/myentity.ent")
Copied!
xbos.devices contains bindings for interacting with the following devices:
  • Thermostat
  • Plug
  • Light
The bindings respect the standard XBOS interfaces
xbos.services contains bindings for interacting with the following services:

Examples

Below are a set of simple examples

Thermostat Interaction

1
from xbos import get_client
2
from xbos.devices.thermostat import Thermostat
3
4
# get a bosswave client
5
c = get_client() # defaults to $BW2_AGENT, $BW2_DEFAULT_ENTITY
6
7
# instantiate a thermostat
8
tstat = Thermostat(c, "410testbed/devices/venstar/s.venstar/420lab/i.xbos.thermostat")
9
10
# print cached state; blocks until we get first report.
11
# maintains subscription in background.
12
print tstat.heating_setpoint
13
14
# batch actuation
15
state = {
16
"heating_setpoint": 72,
17
"cooling_setpoint": 76
18
}
19
tstat.write(state)
20
21
# or individually
22
tstat.set_heating_setpoint(72)
Copied!

Archiver

1
from xbos import get_client
2
from xbos.services.pundat import DataClient, timestamp, make_dataframe
3
4
# get a bosswave client
5
c = get_client() # defaults to $BW2_AGENT, $BW2_DEFAULT_ENTITY
6
7
dc = DataClient(c,archivers=["ucberkeley"])
8
9
uuids = dc.uuids('name = "air_temp" and Deployment = "CIEE"')
10
11
# get timestamps
12
start = timestamp('6/25/2017')
13
end = timestamp('6/28/2017')
14
15
# get 1-hour window data for the first uuid
16
data = dc.window_uuids(uuids[0], start, end, '1h')
17
18
# get a dataframe from the results, keyed by the UUID
19
dfs = make_dataframe(data)
20
print dfs[uuids[0]].describe()
Copied!

Brick (HodDB)

1
from xbos.services.hod import HodClientHTTP
2
3
hc = HodClientHTTP("http://ciee.cal-sdb.org")
4
5
q = """
6
SELECT ?x ?uri WHERE {
7
?x rdf:type/rdfs:subClassOf* brick:Temperature_Sensor .
8
?x bf:uri ?uri .
9
};
10
"""
11
print hc.do_query(q)
12
#[{u'?uri': u'ciee/sensors/s.hamilton/00126d0700000060/i.temperature/signal/operative',
13
# u'?x': u'hamilton_0060_air_temp'},
14
#{u'?uri': u'ciee/sensors/s.hamilton/00126d070000005e/i.temperature/signal/operative',
15
# u'?x': u'hamilton_005e_air_temp'},
16
#{u'?uri': u'ciee/sensors/s.hamilton/00126d070000005d/i.temperature/signal/operative',
17
# u'?x': u'hamilton_005d_air_temp'},
18
#{u'?uri': u'ciee/sensors/s.hamilton/00126d070000005c/i.temperature/signal/operative',
19
# u'?x': u'hamilton_005c_air_temp'},
20
#{u'?uri': u'ciee/sensors/s.hamilton/00126d070000005b/i.temperature/signal/operative',
21
# u'?x': u'hamilton_005b_air_temp'},
22
#{u'?uri': u'ciee/sensors/s.hamilton/00126d070000005a/i.temperature/signal/operative',
23
# u'?x': u'hamilton_005a_air_temp'},
24
#{u'?uri': u'ciee/sensors/s.hamilton/00126d070000002e/i.temperature/signal/operative',
25
# u'?x': u'hamilton_002e_air_temp'},
26
#{u'?uri': u'ciee/sensors/s.hamilton/00126d070000002c/i.temperature/signal/operative',
27
# u'?x': u'hamilton_002c_air_temp'},
28
#{u'?uri': u'ciee/sensors/s.hamilton/00126d070000002b/i.temperature/signal/operative',
29
# u'?x': u'hamilton_002b_air_temp'},
30
#{u'?uri': u'ciee/sensors/s.hamilton/00126d070000002a/i.temperature/signal/operative',
31
# u'?x': u'hamilton_002a_air_temp'},
32
#{u'?uri': u'ciee/sensors/s.hamilton/00126d0700000029/i.temperature/signal/operative',
33
# u'?x': u'hamilton_0029_air_temp'},
34
#{u'?uri': u'ciee/sensors/s.hamilton/00126d0700000028/i.temperature/signal/operative',
35
# u'?x': u'hamilton_0028_air_temp'},
36
#{u'?uri': u'ciee/sensors/s.hamilton/00126d0700000027/i.temperature/signal/operative',
37
# u'?x': u'hamilton_0027_air_temp'},
38
#{u'?uri': u'ciee/sensors/s.hamilton/00126d0700000025/i.temperature/signal/operative',
39
# u'?x': u'hamilton_0025_air_temp'},
40
#{u'?uri': u'ciee/sensors/s.hamilton/00126d0700000022/i.temperature/signal/operative',
41
# u'?x': u'hamilton_0022_air_temp'}]
Copied!

Archived Data with Brick Query

1
from xbos import get_client
2
from xbos.services.pundat import DataClient, timestamp, make_dataframe, merge_dfs
3
from xbos.services.hod import HodClientHTTP
4
from xbos.devices.thermostat import Thermostat
5
6
# get a bosswave client
7
c = get_client() # defaults to $BW2_AGENT, $BW2_DEFAULT_ENTITY
8
# get a HodDB client
9
hod = HodClientHTTP("http://ciee.cal-sdb.org")
10
# get an archiver client
11
archiver = DataClient(c,archivers=["ucberkeley"])
12
13
# query for CIEE occupancy sensors
14
q = """
15
SELECT ?sensor ?uuid WHERE {
16
?sensor rdf:type/rdfs:subClassOf* brick:Occupancy_Sensor .
17
?sensor bf:uuid ?uuid .
18
};
19
"""
20
res = hod.do_query(q)
21
uuids = [r["?uuid"] for r in res]
22
sensors = [r["?sensor"] for r in res]
23
lookup = dict(zip(uuids, sensors))
24
for uuid, sensorname in lookup.items():
25
print uuid, '=>', sensorname
26
start = '"2017-08-21 00:00:00 PST"'
27
end = '"2017-07-20 00:00:00 PST"'
28
# get 15min interval data
29
dfs = make_dataframe(archiver.window_uuids(uuids, end, start, '15min', timeout=120))
30
# resamples the merged dataframes to 10min mean buckets
31
merged = merge_dfs(dfs, resample='10T', do_mean=True)
32
merged.to_csv("data.csv")
Copied!

All Together

1
from xbos import get_client
2
from xbos.services.pundat import DataClient, timestamp, make_dataframe
3
from xbos.services.hod import HodClientHTTP
4
from xbos.devices.thermostat import Thermostat
5
6
# get a bosswave client
7
c = get_client() # defaults to $BW2_AGENT, $BW2_DEFAULT_ENTITY
8
# get a HodDB client
9
hc = HodClientHTTP("http://ciee.cal-sdb.org")
10
11
# query for CIEE thermostats
12
q = """
13
SELECT ?tstat ?uri WHERE {
14
?tstat rdf:type brick:Thermostat .
15
?tstat bf:uri ?uri .
16
};
17
"""
18
ciee_tstats = hc.do_query(q)
19
20
# instantiate some classes
21
tstats = {}
22
for info in ciee_tstats:
23
tstats[info['?tstat']] = Thermostat(c, info['?uri'])
24
25
# print some settings
26
for name, tstat in tstats.items():
27
print name, 'has heat/cool', tstat.heating_setpoint, tstat.cooling_setpoint
Copied!
Last modified 1yr ago