Time formating

I am new to the forum and OpenHAB but it appeared to me a problem
I have a variable that stores the minute (eg. 320min) and I would like to run at HH: MM 5:20
Can this be done?
Alternatively, as conwertować this variable to DATATIME and how to change DATATIME

Please provide more information of what you are trying to do, so we can offer different approaches to help. Without knowing more, all I can suggest at present is to consider using the Joda time classes in rules, and learn about those classes and how they can be used to convert values to/from DateTime objects. You could have an item like this in a .items file:

Number Minutes "minutes [%d]"
DateTime RunTime "run time [%1$tm/%1$td %1$tH:%1$tM]"

Your rules would contain things like:

import org.joda.time.*
import org.openhab.core.library.types.*

rule ConvertMinutesToDateTime
  Item Minutes changed
  var DateTime timeToRun = // ... figure out how to take your Minutes.state as DecimalType into a Joda DateTime object
  RunTime.postUpdate( new DateTimeType(timeToRun.toString) )

The above may not be what you are after, but it will give you something to think about! :smile:

1 Like

I have a built-in home automation for Arduino and now wanted to expand on the interface OpenHAB (up to now has been on the web).
All the rules were implemented on time Arduino.
I do not want to destroy everything and write the Arduino, so I thought about the adaptation of variables to openHAB.
In arduiono I set / array of variables including the time for which you want to attach individual devices. I would like to edit these times and display them in a format Time (HH: MM)

How do you want to expose information in openHAB from your Arduino? Do you want to use the HTTP binding, the MQTT binding, one of the other existing bindings, or write a new custom binding? I think you are saying that your Arduino code represents a time as a number of minutes since midnight. There are several approaches you can use with openHAB to display them as HH:MM in a UI. As the conversation thus far seems more abstract than concrete, it’s hard to say what the best approach will be.

I’m sorry for vague answers :frowning:
I’m using json connections to transfer data. I send HTTP requests and receives in response to json set. Data longer able to read and interpret, I could not only read the time from midnight to timers.
I managed to read a variable time but I still do not know how to change it.
At the moment this is my problem.

But I was wrong and can not keep update the DateTime variable.
I can not run this example that you showed me

If you included parts of your items, sitemaps, rules and transforms, it would be possible to recommend changes intended to help.

Group All
Group pietro (All)
Group parter (All)
Group garaz (All)
Group ogrod (All)
Group Wentylacja (All)
Group Weather (All)
Group Status (All)
Group Parametry (ALL)

Group Salon “Salon” (parter)
Group Kuchnia “Kuchnia” (parter)
Group Ubikacja “Ubikacja” (parter)
Group Korytaz “Korytaż” (parter)
Group:Number:AVG() TempParter “Parter [%.1f °C]”

Group Lazienka “Łazienka” (pietro)
Group Kuba “Kuba” (pietro)
Group Stas “Stasiu” (pietro)
Group Marta “Marta” (pietro)
Group Sypialnia “Sypialnia” (pietro)
Group:Number:AVG() TempPietro “Piętro [%.2f °C]”
Group:Number:AVG() Temperature “Temperatura AVG [%.2f °C]”

/* Temperatury parter*/
Number TempSalon “Salon [%.2f °C]” (Temperature, TempParter, Salon)
Number TempKuchnia “Kuchnia [%.2f °C]” (Temperature, TempParter, Kuchnia)
Number TempLazDol “Łazienka [%.2f °C]” (Temperature, TempParter, Ubikacja)
Switch GarazDoor “Drzwi garażowe” (garaz)
/Temperatury pierwsze pietro/
Number Tempsyp “Sypialnia [%.2f °C]” (Temperature, TempPietro, Sypialnia)
Number TempKuba “Kuba [%.2f °C]” (Temperature, TempPietro, Kuba)
Number TempStas “Staś [%.2f °C]” (Temperature, TempPietro, Stas)
Number TempMarta “Marta [%.2f °C]” (Temperature, TempPietro, Marta)
Number TempLazienka “Łazieka [%.2f °C]” (Temperature, TempPietro, Lazienka)
Number wilgotnosc “Wilgotność łazienka [%.2f %%]” (Wentylacja, Lazienka)
/* parametry kotłownia*/
Number piec “Piec [%.2f °C]” (garaz)
Number boiler “Boiler [%.2f °C]” (garaz)
/* Parametry zewnętrzne /
Number swiatlo “Słońce [%.2f %%]” (ogrod)
Parametry pracy */
DateTime sunset “Zachód słońca [%1$tH:%1$tM]” (Parametry)
DateTime LEDon “LEDon [%1$tH:%1$tM]” (Parametry)
Number korekta “Korekta zewętrznego [%d min]” (Parametry)
Number oswietleniezal “Poziom zal. zewnętrznego [%.2f %%]” (Parametry)
Number TempMinCO “Max. Temp. pracy CO[%.2f °C]” (Parametry)
Number TempKomfort “Temp. komfort [%.2f °C]” (Parametry)
Number TempEco “Temp. ECO [%.2f °C]” (Parametry)
Number TempZalWent “Temp. Zal. Wentylacji [%.2f °C]” (Parametry)
Number tempWentStrych “Temp. Zal. Went. Strych [%.2f °C]” (Parametry)
Number wentylzal “Poziom zal. Wentylacji [%.2f %%]” (Parametry)
Number wentylwyl “Poziom wyl. Wentylacji [%.2f %%]” (Parametry)
Number setBojler “Temp. Zadana CWU [%.2f °C]” (Parametry)

/Zmienne pomocnicze/
Number minuty

Group Weather_Chart (Weather)
Number Temp_zew “Temperatura zewnętrzna [%.2f °C]” (Weather_Chart) { http="<[http://weather.yahooapis.com/forecastrss?w=24935448&u=c:60000:XSLT(yahoo_weather_temperature.xsl)]" }
Number Zewn_Wilgotnosc “Wilgotność zewnętrzna [%.2f %%]” (Weather) { http="<[http://weather.yahooapis.com/forecastrss?w=24935448&u=c:60000:XSLT(yahoo_weather_humidity.xsl)]" }
Number Humidex_dom “Humidex [SCALE(humidex_pl.scale):%s]” (Weather) //{ getHumidex(Temp_zew, Zewn_Wilgotnosc):60000 }
Number Zewn_Temp_Max “Dzisiejsze maximum [%.1f °C]” (Weather_Chart) { http="<[http://weather.yahooapis.com/forecastrss?w=24935448&u=c:60000:XSLT(yahoo_weather_forecast_high.xsl)]" }
Number Zewn_Temp_Min “Dzisiejsze minimum [%.1f °C]” (Weather_Chart) { http="<[http://weather.yahooapis.com/forecastrss?w=24935448&u=c:60000:XSLT(yahoo_weather_forecast_low.xsl)]" }
//Number Weather_Chart_Period "Chart Period"
DateTime Zewn_LastUpdate “Ostatnia aktualizacja [%1$ta %1$tR]”

/* NTP binding demo item */
DateTime Data_dom “Data [%1$tA, %1$td.%1$tm.%1$tY]” { ntp=“Europe/Warsaw” }

import org.joda.time.*
import org.openhab.core.library.types.*
import org.openhab.core.persistence.*
import org.openhab.model.script.actions.*
import org.openhab.model.script.actions.Timer

var Timer timer = null //timer do odliczania czasu

// Creates an item that stores the last update time of this item
rule "Czas ostatniej aktualizacji temperatur"
Item Temp_zew received update
postUpdate(Zewn_LastUpdate, new DateTimeType())

// This rule will be used to test Scale transformation service
rule "Sprawdzenie humidex"
Item Temp_zew changed or
Item Zewn_Wilgotnosc changed or
Item Temp_zew received update
var Number T = Temp_zew.state as DecimalType
var Number H = Zewn_Wilgotnosc.state as DecimalType
var Number x = 7.5 * T/(237.7 + T)
var Number e = 6.112 * Math::pow(10, x.doubleValue) * H/100
var Number humidex = T + (new Double(5) / new Double(9)) * (e - 10)
postUpdate(Humidex_dom, humidex)

//ta ruls będzie odczytywać zmienne co 1 min
rule "odczyt_temperatur"
Time cron "0 * * * * ?"

var String json = sendHttpGetRequest("")
postUpdate(TempSalon, transform("JSONPATH","$.tempSalon",json))
postUpdate(TempKuchnia, transform("JSONPATH","$.tempKuchnia",json))
postUpdate(TempLazDol, transform("JSONPATH", "$.tempLazDol", json))
postUpdate(Tempsyp, transform("JSONPATH", "$.tempsyp", json))
postUpdate(TempKuba, transform("JSONPATH", "$.tempKuba", json))
postUpdate(TempStas, transform("JSONPATH", "$.tempStas", json))
postUpdate(TempMarta, transform("JSONPATH", "$.tempMarta", json))
postUpdate(TempLazienka, transform("JSONPATH", "$.tempLazienka", json))
postUpdate(wilgotnosc, transform("JSONPATH", "$.wilgotnosc", json))
postUpdate(piec, transform("JSONPATH", "$.piec", json))
postUpdate(boiler, transform("JSONPATH", "$.bojler", json))
postUpdate(swiatlo, transform("JSONPATH", "$.swiatlo", json))
//procedura konwersji INT to DATATIME
postUpdate(minuty, transform("JSONPATH", "$.sunset", json))
val DateTime startTime.postUpdate = now.getYear() + "-" + now.getMonthOfYear() + "-" + now.getDayOfMonth() + "T00:00:00")
LEDon.postUpdate( new DateTimeType(startTime.toString) )


//reguła drzwi garazowych
rule "GarrageDoor"
Item GarazDoor received command ON
var String garrage = sendHttpGetRequest(“”)
logInfo(“garaz”, “Polecenie do drzwi garażowych”)
logInfo(“garaz”, garrage)
sendCommand (GarazDoor, OFF)

reguła odczyt parametrów
rule “Startup"
System started
var String json = sendHttpGetRequest(“”)
postUpdate(korekta, transform(“JSONPATH”,”$.korekta",json))
postUpdate(oswietleniezal, transform(“JSONPATH”,"$.oswietleniezal",json))
postUpdate(TempMinCO, transform(“JSONPATH”,"$.tempzalCO",json))
postUpdate(TempKomfort, transform(“JSONPATH”,"$.komfort",json))
postUpdate(TempEco, transform(“JSONPATH”,"$.eco",json))
postUpdate(TempZalWent, transform(“JSONPATH”,"$.tempZalWent",json))
postUpdate(tempWentStrych, transform(“JSONPATH”,"$.tempWentStrych",json))
postUpdate(wentylzal, transform(“JSONPATH”,"$.wentylzal",json))
postUpdate(wentylwyl, transform(“JSONPATH”,"$.wentylwyl",json))
postUpdate(setBojler, transform(“JSONPATH”,"$.bojler",json))

rule "Test timer"
Item sunset changed
if(timer!=null) {
timer = null
var DateTime executionDateTime = now.plusSeconds(10)
val test = 90
logError(“Test timer”, String::format(“Czas logowania: %s”, executionDateTime))
timer = createTimer(executionDateTime,
logError(“Test udany”, String::format(“Parameter: %d”, sunset))


sitemap dom label=“Dom państwa Janochów”
Frame label=“Parametry wewnętrzne” {
Text item=Temperature
Text item=TempParter icon=“groundfloor”{
Text item=TempSalon
Text item=TempKuchnia
Text item=TempLazDol
Text item=TempPietro icon=“firstfloor”{
Text item=Tempsyp
Text item=TempKuba
Text item=TempStas
Text item=TempMarta
Text item=TempLazienka
Text item=wilgotnosc
Group item=garaz label=“Kotłownia” icon=“cellar” {
Text item=piec
Text item=boiler
Selection item=GarazDoor mappings=[0=“off”, 1=“ON”]
Switch item=GarazDoor
Setpoint item=setBojler minValue=40 maxValue=65 step=0.5
Group item=ogrod label=“Ogród” icon=“garden” {
Text item=swiatlo

Frame label="Parametry"{
	Group item=Parametry

Frame label="Prognoza pogody" {
	Text item=Temp_zew valuecolor=[Zewn_LastUpdate=="Uninitialized"="lightgray",Weather_LastUpdate>90="lightgray",>25="orange",>15="green",>5="orange",<=5="blue"] {
		Frame {
			Text item=Zewn_Temp_Max valuecolor=[>25="orange",>15="green",>5="orange",<=5="blue"]
			Text item=Zewn_Temp_Min valuecolor=[>25="orange",>15="green",>5="orange",<=5="blue"]
			Text item=Zewn_Wilgotnosc
			Text item=Humidex_dom
			Text item=Zewn_LastUpdate valuecolor=[Weather_LastUpdate>120="orange", Weather_LastUpdate>300="red"]
		//Frame {
		//	Switch item=Weather_Chart_Period label="Chart Period" mappings=[0="Hour", 1="Day", 2="Week"]
		//	Chart item=Weather_Chart period=h refresh=6000 visibility=[Weather_Chart_Period==0, Weather_Chart_Period=="Uninitialized"]
		//	Chart item=Weather_Chart period=D refresh=30000 visibility=[Weather_Chart_Period==1]
		//	Chart item=Weather_Chart period=W refresh=30000 visibility=[Weather_Chart_Period==2]
Frame label="Data" {
	Text item=Data_dom


I think the problem is the library joda times because I can not use the function of the library.
Do you need to install it something special?

You should only have to import org.joda.time.* to access the classes in that package from rules; no other installation is required.

I tried to use such records:
var DateTime startTime = now.getYear() + “-” + now.getMonthOfYear() + “-” + now.getDayOfMonth() + “T00:00:00”)
startTime = startTime.plusSeconds(10)
logError(“Time”, String::format(“time: %s”, startTime))

It works only correct one:
var DateTime startTime = "2015-01-28T00:00:00"
var DateTime startTime = new DateTimeType()

If you are trying to modify a variable that’s something I never did succeed and shows the error of invoce

To add 320 minutes to the start of today, try:

var DateTime startTime = now.withTimeAtStartOfDay().plusMinutes(320)

To update an openHAB DateTime item named YourStartTime with this value:

YourStartTime.postUpdate(new DateTimeType(startTime.toString))

It works,
Now the question remains how to edit the value.
Thank you very much for your help so far.

If you had a Number item, let’s call it Minutes, shown in a sitemap as a Setpoint, then you could write a rule that triggered on Item Minutes changed, and feed the (Minutes.state as DecimalType).intValue to the plusMinutes method, this would adjust the YourStartTime item as above.

You’re welcome!

using the language of html I was able to edit a time by selecting the hour and Minute and button send,
Is openhab is possible to realize such methods of data entry?

00 </ option>
01 </ option>
02 </ option>
03 </ option>
04 </ option>
05 </ option>
06 </ option>
07 </ option>
08 </ option>
09 </ option>
10 </ option>
11 </ option>
12 </ option>
13 </ option>
14 </ option>
15 </ option>
16 </ option>
17 </ option>
18 </ option>
19 </ option>
20 </ option>
21 </ option>
22 </ option>
23 </ option>
</ Select>
<Select ng-model = "OFFweekendM" style = "width: 46px">
<Option value = "0"> 00 </ option>
<Option value = "5"> 05 </ option>
<Option value = "10"> 10 </ option>
<Option value = "15"> 15 </ option>
<Option value = "20"> 20 </ option>
<Option value = "25"> 25 </ option>
<Option value = "30"> 30 </ option>
<Option value = "35"> 35 </ option>
<Option value = "40"> 40 </ option>
<Option value = "45"> 45 </ option>
<Option value = "50"> 50 </ option>
<Option value = "55"> 55 </ option>
</ Select>
<! - <Button style = "width: 50px" ng-click = "acts ( 'HwylKomfortweekend' json.HwylKomfortweekend) Acts ( 'MwylKomfortweekend' json.MwylKomfortweekend)"> Set </ button> ->
</ Div>
</ Td>

You could use either a Selection or a Switch in your sitemap with mappings for the possible minute values. This would send a command to the named item, and using a rule you could use that value to adjust a DateTime item.

whether it is possible to insert a single line item minutes and hours?

I don’t know of a way other than writing your own small bit of web code that you can interact with in a Webview widget. It would be nice to have a date/time picker UI widget.

Is there somewhere an example of using webview?
I do not understand the idea of using this item.

I google’d and found this. The point of Webview is to embed a web page into your sitemap for whatever purpose you have for it.