diff --git a/apps/ha/README.md b/apps/ha/README.md index 520d562d8..2a037cd68 100644 --- a/apps/ha/README.md +++ b/apps/ha/README.md @@ -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 -Info icons created by Freepik - Flaticon diff --git a/apps/ha/actions.html b/apps/ha/actions.html new file mode 100644 index 000000000..cb0ed9db1 --- /dev/null +++ b/apps/ha/actions.html @@ -0,0 +1,31 @@ + +
+ + + + +Actions:
+Click
+ + + + + + diff --git a/apps/ha/ha.app.js b/apps/ha/ha.app.js index 25f5e0580..029165dea 100644 --- a/apps/ha/ha.app.js +++ b/apps/ha/ha.app.js @@ -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(); diff --git a/apps/ha/ha.icon.js b/apps/ha/ha.icon.js index 8dbab8357..0b71898f3 100644 --- a/apps/ha/ha.icon.js +++ b/apps/ha/ha.icon.js @@ -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=")) \ No newline at end of file diff --git a/apps/ha/ha.png b/apps/ha/ha.png index c73813025..8fce958e4 100644 Binary files a/apps/ha/ha.png and b/apps/ha/ha.png differ diff --git a/apps/ha/metadata.json b/apps/ha/metadata.json index d112fa297..065bb0fa7 100644 --- a/apps/ha/metadata.json +++ b/apps/ha/metadata.json @@ -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} diff --git a/apps/ha/screenshot.png b/apps/ha/screenshot.png new file mode 100644 index 000000000..4125df314 Binary files /dev/null and b/apps/ha/screenshot.png differ diff --git a/apps/ha/screenshot_1.png b/apps/ha/screenshot_1.png deleted file mode 100644 index 97d42a896..000000000 Binary files a/apps/ha/screenshot_1.png and /dev/null differ diff --git a/apps/ha/screenshot_2.png b/apps/ha/screenshot_2.png deleted file mode 100644 index 2d25dd4e6..000000000 Binary files a/apps/ha/screenshot_2.png and /dev/null differ diff --git a/apps/ha/screenshot_3.png b/apps/ha/screenshot_3.png deleted file mode 100644 index 782e4a195..000000000 Binary files a/apps/ha/screenshot_3.png and /dev/null differ