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;
}
});
}
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
MDAR
(Stuart Hanlon, UK importer of Velbus hardware)
2
I’ve only just discovered epoch time format, would using that make the maths work?
I think DLS rules can happily convert DateTime Items to Epoch
Thank you for your answer. I find out that my Sonos one can’t get the next timer value. Sometimes it works, but most the time the Sonos one get the value of the current time. I think so it isn’t possible to display a date that difference is negativ.
Thanks also.
MDAR
(Stuart Hanlon, UK importer of Velbus hardware)
4
I thought you said it was a Time remaining until an Alexa alarm?
Rather than a Sonos thing.
For the Alexa issue, isn’t it just a sum like remaining time = Alexa Timer as Epoch - now as Epoch
The Sonos one have a builtin Alexa.I thought this alexa does not have the “next timer” feature.
I tell the sonos one that it should set a timer and the build in Alexa handle it. But the time I get for the “next timer” channel on this Thing is the current time not the time wenn the timer ends.
And yes i thing it should just be this simple for remaining time.
TypeError: Cannot read property 'state' of null
at updateClock (asd.js:13)
at Object.<anonymous> (asd.js:33)
at Object.invoke (vendor.js:42)
at R.instance (vendor.js:91)
at n (vendor.js:66)
at g (vendor.js:59)
at vendor.js:59
at vendor.js:656
at vendor.js:132
at m.$eval (vendor.js:147)
I have never developed web applications. If you tell me about browser dev tools console I have no idea what that is. I hope I still found the right output.