Hello Openhab community,
I have the problem that I want a widget that shows me the remaining time of my Alexa timer. I tried to calculate the difference with two items and then output the result. in a rule that would be easy but then I would have status changes every second. so i tried to write a widget with an additional javascript. My best result was this:
timer.js
angular
.module('app.widgets')
.controller('MyWidgetCtrl', testCtrl);
testCtrl.$inject = ['$scope', 'OHService'];
function testCtrl($scope, OHService) {
var vm = this;
vm.myvalue = "testing123";
OHService.onUpdate($scope, 'AAktuellesDatum', function () {
var item1 = OHService.getItem('AktuellesDatum');
var item2 = OHService.getItem('BasementEchoNextTimer');
if (item1) {
vm.myitem = item2.state - item1.state;
}
});
}
Widget
<div oc-lazy-load="['/static/timer.js']">
<div ng-controller="MyWidgetCtrl as myctrl">
<input class="form-control" type='text' ng-model="myctrl.myitem" />
</div>
</div>
But the two dates cannot be subtracted. The current update would be just as high as with the rule. So it would be better if the widget is updated secondarily and takes the current time itself.
Since I have no idea about JavaScript, it is difficult for me to understand how I have to write the script.
Any ideas? thank you for reading