Profile support for time series?

Hi,

is there a Profile which supports a time series?

I’m using OH4.3 in Docker using the OpenMeteo binding to pull data and store it as a time series. Now I want to manipulate that pulled data (multiply with a fixed float value) through the channel we assigning the item. I tried to use the “Gain-Offset Correction” as well as the “EXEC” Profile, but both complain “… does not support time series.”

Certainly I can take the time series as is and use a rule to manipulate the current state - that’s what I’m doing today. But how can I manipulate the full time series future data?

Thanks!

Profiles are not written in a way that they understand time series. I would be surprised if any support them. You might be able to do something with a SCRIPT transformation but I’ve no idea what the input will look like in that case. It’ll be a String of some sort which you’d have to parse and iterate over and change each value one-by-one and then reformed into a String for output.

But there is no guarantee that something like that would work. A rule is probably your best bet.

You’ll need to pull "allStatesUntil`, iterate over each value and do your math and create a new timeseries. Then persist the timeseries.

What I don’t know is if that will replace the existing timeseries or if you need to remove the old ones first.

https://www.openhab.org/addons/transformations/vat/

Hi @laursen,

thanks for the hint. Yes that transformation works on time series - great! But I cannot use it for my case as it calculates the given value + percent(value). What I need is value * factor.

Anyhow, since we have a working implementation for a transformation on time series, I just hope that it can be extended or ported to one of the other transformations so it works for my case?!

Thanks!

Perhaps you can use (factor - 1) * 10? For example, if factor is 1.5, you should be able to just provide 50, which means 50% added?

It’s not what the profile is intended for, but it might work as a “hack”.

Sure, but I’m wondering if there is a profile for your use-case? It probably wouldn’t require much to extend other profiles to support time series, but I’m not sure which one to extend.

… yeah, I thought about playing around with the “percent” to make it work. But I also realized that what I try to do is to change the UoM. Looks like that isn’t working with the transformation. I guess I need to use a script transformation and create a new time series from the incoming one. I’m pretty sure with jruby that can be done (@jimtng).

You shouldn’t need to do a transformation or a profile to just change the UoM.

Maybe this isn’t working like it’s supposed to (in which case a bug needs to be filed) but if you set the unit metadata on your Item to the unit you want, the data should get automatically converted to that unit for you. You should never need a transformation to change units so long as the Channel is reporting the value with units.

If the Channel doesn’t report a value with units, there might be some simple ways to handle this that do take advantage of the UoM.

… well it’s both, change the value and the UoM. I’m pulling irradiation data with UoM of W/m2. I trying to convert that into energy based on my solar plant size. So the idea is to use a transformation on the incoming time series data to calculate the energy forecast. Its an easy multiplication to turn the W/m2 into Wh. When linking a Number:Energy item to the channel of the Number:Intensity thing while using the VAT transformation, no time series gets created.

Can you show me some code of how you’d convert the individual value?

A jruby profile can do it.

Link to doc for profile

Since I don’t know what you’re trying to do with the data, I’ll just give you a generic example which you can modify on your own

profile(:convert_time_series, label: "Convert Time Series") do |event, callback:, time_series:|
  next true unless event == :time_series_from_handler

  transformed_ts = TimeSeries.new
  time_series.each do |timestamp, state|
    state = state * 10 # This is an example of your data conversion
    # What you actually do is up to you
    transformed_ts.add(timestamp, state)
  end

  callback.send_time_series(transformed_ts)
  false # Tell the handler not to perform the default action
end

You can use this profile in an .items file using profile="ruby:convert_time_series". You should also be able to select it in the UI.

Thanks @jimtng, that’s exactly what I was hoping/looking for. Where do I place that code? Does it go into conf/automation/ruby/ or conf/transform? And do I call it from the “Thing To Item Transformation” field in the GUI?

Thanks!

Yes save it as give_it_a_good_name.rb and save it in conf/automation/ruby/

It is a profile so you will select it where you’d normally select a profile: in the channel to item link