OH3 formatting variables in emails

*Dear Community,

first of all I would like to gratulate allof you for building such a great project like OpenHAB !!

We have started last week and installed among others the OpenWeather (“OneCall”) and the Mail binding. Both do work properly, so we get data like forecasted temperature etc… and can display it in the UI (sorry to be proud :wink: )

However, when writing the variables in the email text using a rule:
"<br><b>Temperatur morgens</b> OneCallAPIweatherandforecast_ForecastToday_Morningtemperature
we expect to get somnething like -1,0°C, but it writes
**Temperatur morgens** OneCallAPIweatherandforecast_ForecastToday_Morningtemperature (Type=NumberItem, State=-1.02 °C, Label=Morning Temperature, Category=Temperature, Tags=[Point], Groups=[Vorhersage_Heute])

I imagine we have to display only the State and format the variable using something like [%.0f°] however don’t know where…

Thanks for any clue, for sure it’s easy!
thanks to you in advance!!

Platform information:

  • Hardware: Raspberry
  • OS: _Raspbian / Ubuntu
  • Java Runtime Environment: which java platform is used and what version
  • openHAB version: 3
  • Issue of the topic: please be detailed explaining your issue
  • Please post configurations (if applicable):
    • Items configuration related to the issue
    • Sitemap configuration related to the issue
    • Rules code related to the issue
    • Services configuration related to the issue
  • If logs where generated please post these here using code fences:

Welcome @alamak

We all know this feeling - no shame feeling proud here, even if it’s only the beginning :slight_smile:

Just add a .state.toString after your item-name and you should be good to go. Currently it outputs all the available data of your item as you’ve not defined what exactly you want to see.

2 Likes
OneCallAPIweatherandforecast_ForecastToday_Morningtemperature.state

Or maybe

OneCallAPIweatherandforecast_ForecastToday_Morningtemperature.state.toString()

@RGroll beat me to it, but luckily we agree!

3 Likes

Dear RGroll & [hafniumzinc],

Thanks a lot for so quick answers!
Adding .state.toString after the variables is enough!

the result in the e-mail is like

Vorhersage für heute 2021-01-03T12:00:00.000+0100
Wetterlage Mäßiger Schnee
Temperatur morgens -1.02 °C
Temperatur tagsüber 1.57 °C

By the way, is there any reference where I can find how to write the date like 03.01.2021 and change number of digits after the comma etc ?

Thanks again for this quick answer!
A.

You are on the right track with the string formatting. As long as you define your items in a textual file, you would do that in an items file. I cannot guide you with defining items via GUI as I do not use that yet.

For all possible formatting options you may want to look here.

1 Like

I could finaly come to the same result using the following :thinking::

  val Datum = OneCallAPIweatherandforecast_ForecastToday_Timestamp.state.toString
  val Jahr  = Datum.substring(0,4)
  val Monat = Datum.substring(5,7)
  val Tag   = Datum.substring(8,10)
  val email_Text = "<u><b>Vorhersage für heute</b></u> " 
                 + Tag + "." + Monat + "." +  Jahr