Created
October 25, 2020 13:40
-
-
Save hacki11/0a3bfbd3c5bc7d6ed460a43799687736 to your computer and use it in GitHub Desktop.
Basic ioBroker iOS14 Widget
This file contains hidden or 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
// First draft of fetching values from iobroker datapoints with iobroker.web adapter | |
let host = args.widgetParameter; | |
if (!host) | |
host = "http://<iobroker-ip>:8087" | |
console.log(host) | |
let widget = await createWidget() | |
Script.setWidget(widget) | |
widget.presentSmall() | |
Script.complete() | |
async function createWidget() { | |
const list = new ListWidget() | |
try { | |
const line1 = list.addText(await getValue("sourceanalytix.0.mqtt__0__gas__value.currentYear.consumed.01_currentDay") + " m³") | |
line1.font = Font.boldSystemFont(18) | |
line1.textColor = Color.green() | |
const line2 = list.addText(await getValue("sourceanalytix.0.mqtt__0__power__counter.currentYear.consumed.01_currentDay") + " kwh") | |
line2.font = Font.boldSystemFont(18) | |
line2.textColor = Color.orange() | |
return list | |
} catch(err) { | |
const errorList = new ListWidget() | |
errorList.addText(err) | |
return errorList | |
} | |
} | |
async function getValue(point) { | |
try { | |
let req = new Request(host + "/getPlainValue/" + point) | |
let value = await req.loadString() | |
console.log(value) | |
return value; | |
} catch(err) { | |
console.error(err) | |
return "n/a" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment