Exec.persist not passing arguments

I try to pass the state of a temperature sensor (Number LivingTemp) to a shell script using exec.persist but cannot find the right syntax to get it working.

I’d like to pass date/time and the LivingTemp.state in the following, where $1 should be the date/time and $2 the temperature value:
Strategies {
everyMinute : “0 * * * * ?”
}
Items {
LivingTemp -> “/bin/sh /home/stan/test.sh $1 $2” : strategy = everyMinute
}

Can somebody explain the mechanism to use exec.persist. I read the wiki but have dificulty to understand. I can make it work without passing arguments to the script but that is useless for my application.

This binding uses the Java String.Formatter class to format the output. The state of the item is stored in %1 and the timesamp is stored in %2. The $tX and $s are how you tell the Formatter to format the data. For example, %2$tY means take the second argument (which we know is the timestamp), convert it to a date time, and give me the Year as four digits.

So using the formatting syntax you can define how the values look in your call to your script. For example:

".bin/sh /home/stan/test.sh %2$tY-%2$tm-%2$td-%2$tT %1$s"

will use date format of YYYY-MM-DD-HH:MM:SS.

If you want a different timestamp format, see the Date Time Conversions section of the String.Formatter documentation. For example, if you used %2$s the date will be a single number that represents the number of milliseconds since midnight January 1, 1970.

Thanks Rich for the quick reply.