First working version :D

pull/1995/head
David Peer 2022-06-23 20:06:53 +02:00
parent ce90666725
commit 21cc7a07cc
10 changed files with 81 additions and 37 deletions

View File

@ -1,8 +1,23 @@
# Home Assistant
This app integrates your BangleJs into the HomeAssistant.
# Setup
1.) First of all, make sure that HomeAssistant is working and
the HomeAssistant, as well as BangleJS Android App, is running on your device
2.) Enable intent access in your BangleJS Android App.
3.) Upload this app to your BangleJS and set the actions that you want to trigger from your
BangleJs within the app store.
4.) Set all the actions on your HomeAssistant Android app with preceding "com.espruino.gadgetbridge.banglejs.ha."
5.) The HomeAssistant Android app must be restarted in order to listen for those actions
-- a "Force Stop" is necessary!
6.) Set the corresponding actions in HomeAssistant Web UI
Thats it!
## Creator
- [David Peer](https://github.com/peerdavid).
## Thanks To
<a href="https://www.flaticon.com/free-icons/info" title="info icons">Info icons created by Freepik - Flaticon</a>

31
apps/ha/actions.html Normal file
View File

@ -0,0 +1,31 @@
<html>
<head>
<link rel="stylesheet" href="../../css/spectre.min.css">
</head>
<body>
<p>Actions: <input type="text" id="subjects" class="form-input" value="Seperate home assistant actions by comma, eg. LIGHT,DOOR,..."></p>
<p>Click <button id="upload" class="btn btn-primary">Upload</button></p>
<script src="../../core/lib/customize.js"></script>
<script>
// When the 'upload' button is clicked...
document.getElementById("upload").addEventListener("click", function() {
// get the text to add
var text = document.getElementById("subjects").value;
console.log(text);
// build the app's text using a templated String
var app = text;
// send finished app (in addition to contents of app.json)
sendCustomizedApp({
storage:[
{name:"ha.actions.txt", url:"ha.actions.txt", content:app},
]
});
console.log("Sent actions.txt!");
});
</script>
</body>
</html>

View File

@ -1,38 +1,31 @@
var _GB = global.GB;
var storage = require("Storage");
var W = g.getWidth(), H = g.getHeight();
var position=0;
var response="...";
function GB(msg) {
if (msg.t == "http" || msg.t == "intent") {
response = JSON.stringify(msg);
draw();
}
// Try to read custom actions, otherwise use default
var actions = [
"No Actions",
];
if (_GB) {
_GB(msg);
}
try{
actions = storage.read("ha.actions.txt").split(",");
} catch(e) {
// In case there are no user actions yet, we show the default...
}
function draw() {
g.reset().clearRect(Bangle.appRect);
// Header
g.setFont("Vector", 32).setFontAlign(0,0);
var text = "";
if(position == 0){
text = "Door";
} else if(position == 1){
text = "Light";
}
var h = 26;
g.setFont("Vector", h).setFontAlign(0,0);
var action = actions[position];
var w = g.stringWidth(action);
g.drawString(text, W/2, H/3);
g.setFont("Vector", 24);
g.drawString(response, W/2, H/3+34);
g.fillRect(W/2-w/2-8, H/2-h/2-8, W/2+w/2+2, H/2+h/2+2);
g.setColor(g.theme.bg).drawString(action, W/2, H/2);
}
@ -46,21 +39,25 @@ Bangle.on('touch', function(btn, e){
var isRight = e.x > right;
if(isRight){
Bangle.buzz(40, 0.6);
position += 1;
position = position > 1 ? 0 : position;
position = position >= actions.length ? 0 : position;
}
if(isLeft){
Bangle.buzz(40, 0.6);
position -= 1;
position = position < 0 ? 1 : position;
position = position < 0 ? actions.length-1 : position;
}
if(!isRight && !isLeft){
Bangle.buzz(40, 0.6);
// Trigger HA bridge
response = "sending...";
Bluetooth.println(JSON.stringify({t:"int­ent",action:"com.espruino.gadgetbridge.banglejs.TOGGLE_LIGHT",extra:{}}));
Bangle.buzz(80, 0.6).then(()=>{
action = "com.espruino.gadgetbridge.banglejs.ha." + actions[position];
Bluetooth.println(JSON.stringify({t:"intent", action:action, extra:{}}));
setTimeout(()=>{
Bangle.buzz(80, 0.6);
}, 250);
});
}
draw();

View File

@ -1 +1 @@
require("heatshrink").decompress(atob("mEwwcBkmSpICDBwcJBYwCDpAhFggRJGg8SCI+ABgU//gSDCI4JBj//AAX4JRAIBg4QDAAPgBIJWGgIQFAAI+BLglAgEPCI/wEgJoEgYQHAAPANwhWFAApcBCIWQgAQJAAMAgSMDCJiSCwB6GQA6eCn5TFL4q5BUgIRF/wuBv4RGkCeGO4IREUgMBCJCVGCISwIWw0BYRLIICLBHHCJRrGCIQIFR44I5LIoRaPpARcdIwRJfYMBCJuACKUkgE/a5f8gEJCJD7FCIeAg78FAAvggFJCIMACJZOBCIOQCJsCCIOSgEfCBP4gESCIZTFOIwRDoDIGaguSCIVIgCkFTwcAggRDpIYBQAx6BgAOCAQYIBLghWBTwQRFFgIABXIIFDBwgCDBYQAENAYCFLgIAEKwpKIIhA="))
require("heatshrink").decompress(atob("mEwwMB/4Ae/1/Aof4j4FD+EPAofgAonAgYFDwA/EgOBFAcH8FDAoP8h/wDAX4h1wAoXwhkwAoXgBYnAC4mAEYIwCgED4EAFwIFE/gFDn/4h/D4fwj5dBAokc8fHnEP8EYsfGjEH/4FDF4MfCIP4AoMP+fP+AFBg/77/gIIV/HwIFCn4+BAoUf/AFDL4IFDL4IFDLIYFkAEQ="))

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 980 B

View File

@ -9,9 +9,10 @@
"readme": "README.md",
"supports": ["BANGLEJS2"],
"screenshots": [
{"url":"screenshot_1.png"},
{"url":"screenshot_2.png"},
{"url":"screenshot_3.png"}],
{"url":"screenshot.png"}],
"data": [
{"name":"ha.actions.txt" }
],
"storage": [
{"name":"ha.app.js","url":"ha.app.js"},
{"name":"ha.img","url":"ha.icon.js","evaluate":true}

BIN
apps/ha/screenshot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.4 KiB