History data in custom widget via Rest API and javascript

Hi,

I would like to utilize the Rest API for getting persistence historic data. I want to build a Widget where I can show power usage today, this week, this year ext. I could do this by creating dedicated items for this and create a rule that fills that items but I wont have historic data as this would start of today and, as we have this data already in persistence it seems logical to just get that data from the Rest API.

I could use the oh-webframe-card widget, but that requires placement of files with the static folder and you cant really use the custom widget properties. I wish to create a more user friendly widget which can use javascript within the Yaml structure.

Can this somehow be done? Perhaps with lazy loading some functions which you can use in the custom widgets?

component: oh-label-card
config:
  title: Power meter test
  label: =fetch('/rest/persistence/items/<the_item>?starttime=2023-01-01&page=1&pagelength=1').then(response => response.json()).then(data => console.log(data.data[0].state))

Thanks in advance!

No. Not at this time. Don’t be fooled by what is already possible in widget expressions. That is not javascript. That is a lightweight, javascript-like expression parser.

To bad, would be a great enhancement.

Thanks!

1 Like