Copy Strings

Hi there, I’m struggling now for several days by doing just a simple thing.
I’m creating a string containing a value and a timestampf with this rule:

rule “Update Daily Temperature Min- and Max values”

Item Weather_Temperature received update
var Number Min
var Number Max
var String tmp
var SimpleDateFormat df = new SimpleDateFormat( “HH:mm” )

    if (Weather_Temperature.state instanceof DecimalType) {
            Min = (Weather_Temperature.minimumSince(now.toDateMidnight, "mysql").state as DecimalType)
            tmp = (Math::round(Min.floatValue*10.0)/10.0) + " °C - " + df.format(Weather_Temperature.minimumSince(now.toDateMidnight, "mysql").timestamp)
            postUpdate(Weather_Temperature_day_min, tmp)
            Max = Weather_Temperature.maximumSince(now.toDateMidnight, "mysql").state as DecimalType
            df = new SimpleDateFormat( "HH:mm" ) 
            tmp = (Math::round(Max.floatValue*10.0)/10.0) + " °C - " + df.format(Weather_Temperature.maximumSince(now.toDateMidnight, "mysql").timestamp)
            postUpdate(Weather_Temperature_day_max, tmp)


So, this gives me a daily min and max of a temperature with a timestamp when it occured. This works fine with week/month/year.

But what I want now is, to copy the string at the end of the day (23:59), at the end of the week (Sun 23:59), at the end of the month (last day of month 23:59) and at the end of the year (31.12 23:59) into a new Item as a string.

I want to see the yesterday, last week, last month and last year min and max temperature for statistical use.

To use cron jobs for those tasks is clear so far, but how can I copy this string into another String?

I’m pretty sure that it will be very easy but I really can’t get into it.

Thanks for any help :slight_smile:


a very simple (and slightly ugly) way of doing it is to set an item (MaxWeatherLastWeek, in this example) and make a rule that is triggered when the value changes.

You can use postUpdate(MaxWeatherLastWeek, Max) to set it to the relevant temperature (variable value).

If you want to do this ‘externally’ via cron, that’s possible. The REST API can be accessed very easily with Curl or something comparable. However, you would need to track the value somewhere else than a variable in your rules (these variable are ONLY accessible from the rules, AFAIK).

1 Like

It actually isn’t all that easy because you cannot get at an Item’s label from a rule.

So, as @pelnet suggests, the best way is probably to create a rule that triggers on each update and update your String Items with the new String that constructs the String the way you want it for your day, week, month, and year Items. Or you can use a cron trigger to calculate them at certain times. But either way, you will have to completely reconstruct the string because you cannot get at the labels of Items from within a rule.

1 Like


thanks for your replies!

I’m going that way, you’re suggesting!

Thank you all for your help :slight_smile: