Skip to content

Commit 93404a8

Browse files
committed
add rotation sensor
1 parent f04c17b commit 93404a8

File tree

5 files changed

+70
-0
lines changed

5 files changed

+70
-0
lines changed

apps/bthome_rotate/ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.01: New App!

apps/bthome_rotate/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# BTHome Rotation
2+
3+
This advertises temperature, battery and rotation in a [BTHome (https://bthome.io/)](https://bthome.io/) compatible format, which can then be used in https://www.home-assistant.io/
4+
5+
There are two rotations advertised, for the X and Y axes. When the Puck.js is completely flat on a desk (aerial up, button down) a value of `0,0` will be reported, and will vary +/- 180 degrees. Rotation updates once per minute.
6+
7+
This is based on https://www.espruino.com/BTHome
8+
9+
10+
## Usage
11+
12+
Install the app and disconnect, then Puck.js will appear in Home Assistant as a new device

apps/bthome_rotate/app.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
var a,rx,ry;
2+
3+
// https://www.espruino.com/BTHome
4+
// Update the data we're advertising here
5+
function updateAdvertising() {
6+
// read accelerometer
7+
a = Puck.accel().acc;
8+
// calculate angle
9+
rx = Math.atan2(a.x,a.z)*180/Math.PI;
10+
ry = Math.atan2(a.y,a.z)*180/Math.PI;
11+
12+
NRF.setAdvertising(require("BTHome").getAdvertisement([
13+
{
14+
type : "battery",
15+
v : E.getBattery()
16+
},
17+
{
18+
type : "temperature",
19+
v : E.getTemperature()
20+
},
21+
{
22+
type : "rotation",
23+
v : rx
24+
},
25+
{
26+
type : "rotation",
27+
v : ry
28+
},
29+
]), {
30+
name : "Rot", interval:1000,
31+
// not being connectable/scannable saves power (but you'll need to reboot to connect again with the IDE!)
32+
//connectable : false, scannable : false,
33+
});
34+
}
35+
36+
NRF.setTxPower(4);
37+
updateAdvertising();
38+
setInterval(updateAdvertising, 60000); // 1 minute

apps/bthome_rotate/icon.png

1.73 KB
Loading

apps/bthome_rotate/metadata.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"id": "bthome_rotate",
3+
"name": "BTHome Rotation Sensor",
4+
"icon": "icon.png",
5+
"version": "0.01",
6+
"description": "Turn your Puck.js into a BTHome/Home Assistant compatible angle/rotation sensor",
7+
"tags": "bluetooth,homeassistant,angle,rotation",
8+
"readme": "README.md",
9+
"needsFeatures": [
10+
"BLE",
11+
"ACCEL"
12+
],
13+
"storage": [
14+
{
15+
"name": ".bootcde",
16+
"url": "app.js"
17+
}
18+
]
19+
}

0 commit comments

Comments
 (0)