Merge branch 'master' of github.com:espruino/BangleApps
commit
88fef317e5
|
|
@ -5,3 +5,5 @@
|
|||
0.05: Clkinfo improvements.
|
||||
0.06: Updated clkinfo icon.
|
||||
0.07: Update clock_info to avoid a redraw
|
||||
0.08: Allow swiping to switch triggers
|
||||
0.09: Improve web interface, arrows in UI
|
||||
|
|
|
|||
|
|
@ -1,20 +1,22 @@
|
|||
# Home Assistant
|
||||
This app integrates your BangleJs into the HomeAssistant.
|
||||
This app integrates your Bangle.js into the Home Assistant.
|
||||
|
||||
|
||||
# How to use
|
||||
Click on the left and right side of the screen to select the triggers that you
|
||||
configured. Click in the middle of the screen to send the trigger to HomeAssistant.
|
||||
Click on the left or right side of the screen to select the triggers that you configured.
|
||||
Swiping left or right works as well.
|
||||
|
||||
Click in the middle of the screen to send the trigger to Home Assistant via Gadgetbridge.
|
||||
|
||||

|
||||
|
||||
|
||||
# Initial Setup
|
||||
1.) First of all, make sure that HomeAssistant and the HomeAssistant Android App works.
|
||||
1.) First of all, make sure that Home Assistant and the Home Assistant Android Companion App work.
|
||||
|
||||
2.) Open your BangleJs Gadgetbridge App, click on the Settings icon of your BangleJs and enable "Allow Intent Access"
|
||||
2.) Open your Bangle.js Gadgetbridge App, click on the Settings icon of your Bangle.js and enable "Allow Intent Access"
|
||||
|
||||
3.) Enable sensor in HomeAssistant Andoird App/Configuration/Companion App/Manage Sensors/LastUpdate Trigger
|
||||
3.) Enable sensor in Home Assistant Android App/Configuration/Companion App/Manage Sensors/LastUpdate Trigger
|
||||
|
||||
4.) At the bottom of the same screen click on "Add New Intent" and enter "com.espruino.gadgetbridge.banglejs.HA"
|
||||
|
||||
|
|
@ -35,7 +37,7 @@ The following icons are currently supported:
|
|||
- fire
|
||||
|
||||
|
||||
2.) Create an "automation" in the HomeAssistant WebUI for each trigger that you created on your BangleJs in order to tell HomeAssistant what you want to control. A sample configuration is shown in the image below -- I use this trigger to open the door:
|
||||
2.) Create an "automation" in the Home Assistant WebUI for each trigger that you created on your Bangle.js in order to tell Home Assistant what you want to control. A sample configuration is shown in the image below -- I use this trigger to open the door:
|
||||
|
||||

|
||||
|
||||
|
|
@ -48,7 +50,7 @@ This app also implements two default trigger that can always be used:
|
|||
- TRIGGER -- Will be sent whenever some trigger is executed. So you could generically listen to that.
|
||||
|
||||
|
||||
# How to use the library (ha.lib.js) in my own app/clk
|
||||
# How to use the library (ha.lib.js) in my own app/clock
|
||||
This app inlcludes a library that can be used by other apps or clocks
|
||||
to read all configured intents or to send a trigger. Example code:
|
||||
|
||||
|
|
@ -74,13 +76,13 @@ ha.sendTrigger("MY_CUSTOM_TRIGGER");
|
|||
# FAQ
|
||||
|
||||
## Sometimes the trigger is not executed
|
||||
While playing and testing a bit I found that it is very important that you allow the android HomeAssistant app, as well as BangleJs Gadgetbridge app to (1) run in background and (2), disable energy optimizations for both apps.
|
||||
While playing and testing a bit I found that it is very important that you allow the android Home Assistant app, as well as Bangle.js Gadgetbridge app to (1) run in background and (2), disable energy optimizations for both apps.
|
||||
Otherwise, Android could stop one of both apps and the trigger will never be sent to Home Assistant...
|
||||
|
||||
If you still have problems, you can try another trick:
|
||||
Install "MacroDroid" from the Android AppStore and start the Home Assistant App
|
||||
each time the "com.espruino.gadgetbridge.banglejs.HA" intent is send together
|
||||
with the extra trigger: APP_STARTED. Then whenever you open the app on your BangleJs
|
||||
with the extra trigger: APP_STARTED. Then whenever you open the app on your Bangle.js
|
||||
it is ensured that Home Assistant is running...
|
||||
|
||||
## Thanks to
|
||||
|
|
@ -88,3 +90,6 @@ it is ensured that HomeAssistant is running...
|
|||
|
||||
## Creator
|
||||
- [David Peer](https://github.com/peerdavid).
|
||||
|
||||
## Contributor
|
||||
- [myxor](https://github.com/myxor)
|
||||
|
|
|
|||
|
|
@ -1,51 +0,0 @@
|
|||
<html>
|
||||
<head>
|
||||
<link rel="stylesheet" href="../../css/spectre.min.css">
|
||||
</head>
|
||||
<body>
|
||||
<h3>Upload Tigger</h3>
|
||||
<p><textarea id="triggers" style="width:500px; height:300px">
|
||||
[
|
||||
{"display": "Open", "trigger": "OPEN_DOOR", "icon":"door"},
|
||||
{"display": "Office", "trigger": "TOGGLE_LIGHT", "icon":"light"},
|
||||
{"display": "Living Room", "trigger": "OVEN", "icon":"fire"}
|
||||
]</textarea></p>
|
||||
<p><button id="upload" class="btn btn-primary">Upload</button></p>
|
||||
|
||||
<script src="../../core/lib/customize.js"></script>
|
||||
|
||||
<script>
|
||||
/*
|
||||
* Load trigger from BangleJs
|
||||
*/
|
||||
console.log("Loading trigger from BangleJs...");
|
||||
try {
|
||||
Puck.eval(`require("Storage").read(${JSON.stringify("ha.trigger.json")})`,data=>{
|
||||
if(data.length > 0){
|
||||
document.getElementById("triggers").innerHTML = data;
|
||||
console.log("Loaded trigger from BangleJs.");
|
||||
}
|
||||
});
|
||||
} catch(ex) {
|
||||
console.log("(Warning) Could not load trigger from BangleJs.");
|
||||
console.log(ex);
|
||||
}
|
||||
|
||||
/*
|
||||
* Upload trigger to BangleJs
|
||||
*/
|
||||
document.getElementById("upload").addEventListener("click", function() {
|
||||
// get the text to add
|
||||
var triggerText = document.getElementById("triggers").value;
|
||||
// send finished app (in addition to contents of app.json)
|
||||
sendCustomizedApp({
|
||||
storage:[
|
||||
{name:"ha.trigger.json", url:"ha.trigger.json", content:triggerText},
|
||||
]
|
||||
});
|
||||
console.log("Sent ha.trigger.json!");
|
||||
});
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -17,39 +17,41 @@ function draw() {
|
|||
|
||||
g.setFontAlign(-1,-1);
|
||||
var icon = trigger.getIcon();
|
||||
g.setColor(g.theme.fg).drawImage(icon, 12, H/5-2);
|
||||
g.drawString("Home", icon.width + 20, H/5);
|
||||
g.drawString("Assistant", icon.width + 18, H/5+24);
|
||||
g.setColor(g.theme.fg).drawImage(icon, 12, H/5-2-5);
|
||||
g.drawString("Home", icon.width + 20, H/5-5);
|
||||
g.drawString("Assistant", icon.width + 18, H/5+24-5);
|
||||
|
||||
g.setFontAlign(0,0);
|
||||
var ypos = H/5*3+20;
|
||||
var ypos = H/5*3+23;
|
||||
g.drawRect(W/2-w/2-8, ypos-h/2-8, W/2+w/2+5, ypos+h/2+5);
|
||||
g.fillRect(W/2-w/2-6, ypos-h/2-6, W/2+w/2+3, ypos+h/2+3);
|
||||
g.setColor(g.theme.bg).drawString(trigger.display, W/2, ypos);
|
||||
|
||||
// draw arrows
|
||||
g.setColor(g.theme.fg);
|
||||
if (position > 0) {
|
||||
g.drawLine(10, H/2, 20, H/2 - 10);
|
||||
g.drawLine(10, H/2, 20, H/2 + 10);
|
||||
}
|
||||
if (position < triggers.length -1) {
|
||||
g.drawLine(W - 10, H/2, W - 20, H/2 - 10);
|
||||
g.drawLine(W - 10, H/2, W - 20, H/2 + 10);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Bangle.on('touch', function(btn, e){
|
||||
var left = parseInt(g.getWidth() * 0.3);
|
||||
var right = g.getWidth() - left;
|
||||
var isLeft = e.x < left;
|
||||
var isRight = e.x > right;
|
||||
|
||||
if(isRight){
|
||||
Bangle.buzz(40, 0.6);
|
||||
position += 1;
|
||||
position = position >= triggers.length ? 0 : position;
|
||||
draw();
|
||||
}
|
||||
|
||||
if(isLeft){
|
||||
function toLeft() {
|
||||
Bangle.buzz(40, 0.6);
|
||||
position -= 1;
|
||||
position = position < 0 ? triggers.length-1 : position;
|
||||
draw();
|
||||
}
|
||||
|
||||
if(!isRight && !isLeft){
|
||||
function toRight() {
|
||||
Bangle.buzz(40, 0.6);
|
||||
position += 1;
|
||||
position = position >= triggers.length ? 0 : position;
|
||||
draw();
|
||||
}
|
||||
function sendTrigger() {
|
||||
ha.sendTrigger("TRIGGER");
|
||||
|
||||
// Now send the selected trigger
|
||||
|
|
@ -60,6 +62,31 @@ Bangle.on('touch', function(btn, e){
|
|||
}, 250);
|
||||
});
|
||||
}
|
||||
|
||||
Bangle.on('touch', function(btn, e){
|
||||
var left = parseInt(g.getWidth() * 0.3);
|
||||
var right = g.getWidth() - left;
|
||||
var isLeft = e.x < left;
|
||||
var isRight = e.x > right;
|
||||
|
||||
if(isLeft){
|
||||
toLeft();
|
||||
}
|
||||
if(isRight){
|
||||
toRight();
|
||||
}
|
||||
if(!isRight && !isLeft){
|
||||
sendTrigger();
|
||||
}
|
||||
});
|
||||
|
||||
Bangle.on("swipe", (lr,ud) => {
|
||||
if (lr == -1) {
|
||||
toLeft();
|
||||
}
|
||||
if (lr == 1) {
|
||||
toRight();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,52 @@
|
|||
<html>
|
||||
<head>
|
||||
<link rel="stylesheet" href="../../css/spectre.min.css">
|
||||
</head>
|
||||
<body>
|
||||
<h3>Home Assistant trigger config</h3>
|
||||
<p><textarea id="triggers" style="width:500px; height:300px">
|
||||
[
|
||||
{"display": "Open", "trigger": "OPEN_DOOR", "icon":"door"},
|
||||
{"display": "Office", "trigger": "TOGGLE_LIGHT", "icon":"light"},
|
||||
{"display": "Living Room", "trigger": "OVEN", "icon":"fire"}
|
||||
]</textarea></p>
|
||||
<p><button id="upload" class="btn btn-primary">Upload trigger</button></p>
|
||||
|
||||
<script src="../../core/lib/interface.js"></script>
|
||||
|
||||
<script>
|
||||
function onInit(){
|
||||
/*
|
||||
* Load trigger from Bangle.js
|
||||
*/
|
||||
console.log("Loading trigger from Bangle.js...");
|
||||
try {
|
||||
Util.readStorage("ha.trigger.json", data=>{
|
||||
if(data.length > 0){
|
||||
document.getElementById("triggers").innerHTML = data;
|
||||
console.log("Loaded trigger from Bangle.js.");
|
||||
}
|
||||
});
|
||||
} catch(ex) {
|
||||
console.log("(Warning) Could not load trigger from Bangle.js.");
|
||||
console.log(ex);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Upload trigger to Bangle.js
|
||||
*/
|
||||
document.getElementById("upload").addEventListener("click", function() {
|
||||
// get the text to add
|
||||
var triggerText = document.getElementById("triggers").value;
|
||||
|
||||
Util.showModal("Saving...");
|
||||
Util.writeStorage("ha.trigger.json", triggerText, ()=>{
|
||||
Util.hideModal();
|
||||
});
|
||||
console.log("Sent ha.trigger.json!");
|
||||
});
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -1,14 +1,14 @@
|
|||
{
|
||||
"id": "ha",
|
||||
"name": "Home Assistant",
|
||||
"version": "0.07",
|
||||
"description": "Integrates your BangleJS into HomeAssistant.",
|
||||
"version": "0.09",
|
||||
"description": "Integrates your Bangle.js into Home Assistant.",
|
||||
"icon": "ha.png",
|
||||
"type": "app",
|
||||
"tags": "tool,clkinfo",
|
||||
"tags": "tool,clkinfo,bluetooth",
|
||||
"readme": "README.md",
|
||||
"supports": ["BANGLEJS2"],
|
||||
"custom": "custom.html",
|
||||
"interface": "interface.html",
|
||||
"screenshots": [
|
||||
{"url":"screenshot.png"},
|
||||
{"url":"screenshot_2.png"},
|
||||
|
|
|
|||
Loading…
Reference in New Issue