Hi all. I have this rule file sending the values of Hours, Minutes, Day of the Week and Date via MQTT in exactly this fashion to be read by an Arduino somewhere down the line.
The only thing that eludes me is … if the minute or the hour is less than 10 it is missing the leading 0. How can I change the formating of this? I need the hours and minutes as separate values though.
here is the rules I´m using:
import java.util.Date import java.text.SimpleDateFormat rule "publish time" when Item LocalTime_DatumUndZeit changed then var hour = (now.getHourOfDay).toString var minute = (now.getMinuteOfHour).toString var tag = (now.getDayOfWeek).toString var SimpleDateFormat df = new SimpleDateFormat( "DD|MM|YY" ) var String NewDate = df.format ( new Date() ) publish("mosquitto", "date", NewDate) publish("mosquitto", "day", tag) publish("mosquitto", "timeHour", hour) publish("mosquitto", "timeMinute", minute) end