-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f04c17b
commit 93404a8
Showing
5 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0.01: New App! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# BTHome Rotation | ||
|
||
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/ | ||
|
||
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. | ||
|
||
This is based on https://www.espruino.com/BTHome | ||
|
||
|
||
## Usage | ||
|
||
Install the app and disconnect, then Puck.js will appear in Home Assistant as a new device |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
var a,rx,ry; | ||
|
||
// https://www.espruino.com/BTHome | ||
// Update the data we're advertising here | ||
function updateAdvertising() { | ||
// read accelerometer | ||
a = Puck.accel().acc; | ||
// calculate angle | ||
rx = Math.atan2(a.x,a.z)*180/Math.PI; | ||
ry = Math.atan2(a.y,a.z)*180/Math.PI; | ||
|
||
NRF.setAdvertising(require("BTHome").getAdvertisement([ | ||
{ | ||
type : "battery", | ||
v : E.getBattery() | ||
}, | ||
{ | ||
type : "temperature", | ||
v : E.getTemperature() | ||
}, | ||
{ | ||
type : "rotation", | ||
v : rx | ||
}, | ||
{ | ||
type : "rotation", | ||
v : ry | ||
}, | ||
]), { | ||
name : "Rot", interval:1000, | ||
// not being connectable/scannable saves power (but you'll need to reboot to connect again with the IDE!) | ||
//connectable : false, scannable : false, | ||
}); | ||
} | ||
|
||
NRF.setTxPower(4); | ||
updateAdvertising(); | ||
setInterval(updateAdvertising, 60000); // 1 minute |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"id": "bthome_rotate", | ||
"name": "BTHome Rotation Sensor", | ||
"icon": "icon.png", | ||
"version": "0.01", | ||
"description": "Turn your Puck.js into a BTHome/Home Assistant compatible angle/rotation sensor", | ||
"tags": "bluetooth,homeassistant,angle,rotation", | ||
"readme": "README.md", | ||
"needsFeatures": [ | ||
"BLE", | ||
"ACCEL" | ||
], | ||
"storage": [ | ||
{ | ||
"name": ".bootcde", | ||
"url": "app.js" | ||
} | ||
] | ||
} |