Skip to content

Instantly share code, notes, and snippets.

@hacki11
Created October 25, 2020 13:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hacki11/0a3bfbd3c5bc7d6ed460a43799687736 to your computer and use it in GitHub Desktop.
Save hacki11/0a3bfbd3c5bc7d6ed460a43799687736 to your computer and use it in GitHub Desktop.
Basic ioBroker iOS14 Widget
// 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