[SOLVED] Convert a date to Sunday

Hi,
i have a temperature like -5.25 °C and want to convert it to -5 °C. What can I do?
The item is:

{{itemValue('OpenWeatherMapWeatherAndForecast_ForecastTomorrow_MinimumTemperature')

From OpenWeather Binding I get a date for the weather forecasts like

06.01.2019

I want to convert this date to eg. Sunday.

Can anybody help? :wink:

Thanks
Tobias

Please post your items file

I edited my first post, cause the first problem is solved.

The item of the observation time is:

OpenWeatherMapWeatherAndForecast_Current_ObservationTime
DateTime

eg: 08.01.2019

I believe its this way round

{{itemValue('OpenWeatherMapWeatherAndForecast_ForecastTomorrow_MinimumTemperature') |  '%.0f °C'  }}

Untested though

Hi Cris,
this works for me:

{{itemValue('OpenWeatherMapWeatherAndForecast_ForecastTomorrow_MinimumTemperature').split('.')[0] }} °C

Please don’t. Others might have your problem. Rather post the solution you had.
Alison it makes follow up answer like mine look silly.

1 Like

You are right, sorry.
For my second question i have currently no solution. Do you have any idea?

Thanks
Tobias

Use the formating:

DateTime OWB_Forecast_Date "Date of forecast [%1$tEEEE]"

In this case I have to create a new item, right? Do you know a way where I can convert the existing OWB item and convert it in my HABPanel widget?

No
Just put it in an items file
Remove the link in the paperUI
Create an items file
Put the item as show above:

DateTime OWB_Forecast_Date "Date of forecast [%1$tEEEE]" { channel="OWBchannel" }

Replace the channel with the correct channel in the paperUI

Ahh ok sorry, clear.
The value if the new item is:

2019-01-07T12:00:00.000+0100

What i need is: Monday.

Do you know what I have to do?

You need another item (a String item)
And a rule

Sorry for asking again …
I added a rule to convert the iso Date to a string.

rule "test"
when
   Item Test_Switch changed
then
    var dateToString = OWB_Forecast_Date.state.toString.split("T").get(0)

    OWB_Forecast_DateString.postUpdate(dateToString )
end

The date “dateToString” is now in format:

2019-01-08

The items are:

DateTime OWB_Forecast_Date "Date of forecast [%1$tEEEE]" { channel="openweathermap:weather-and-forecast:1254777:local:forecastTomorrow#time-stamp" }
String OWB_Forecast_DateString "Date of forecast string"

What is the next step?

Hello,

OWB_Forecast_Date.getDayOfWeek 

should return the day of the week(1-7).

Just translate it in a rule:

if (OWB_Forecast_Date.getDayOfWeek==1) {
    OWB_Forecast_Weekday = "monday" 
}
else if (OWB_Forecast_Date.getDayOfWeek==2) {
    OWB_Forecast_Weekday = "tuesday" 
}
else if (OWB_Forecast_Date.getDayOfWeek==3) {
    OWB_Forecast_Weekday = "wednesday" 
}....

Best,
Olli

Ahh I think I have a solution.

I created a template widget with:

{{itemValue('OWB_Forecast_Date') | date:'EEEE'}}

Now it works fine :wink:

Thanks all

I guess this is HABPanel stuff? If yes, please change the category to Apps & Services -> HABPanel

The rules way is:

rule "test"
when
   Item Test_Switch changed
then
    OWB_Forecast_DateString.postUpdate(OWB_Forecast_Date.state.toString("EEEE"))
end
1 Like

Ah ok, make sense. Thanks a lot!!