How to edit the time of a DateTime item

Hi,

I’m trying to find a way to edit the time of a DateTime item.

I have defined the following item:

DateTime  pool_prog1_step1_on  "Pool: Prog1 - Step 1 - Time ON"  ( gPoolProg1Step1 )  { channel="plclogo:datetime:plc_pool:VW27:time" }

The returned DateTime value is:

2022-03-29T10:00:55.481837+0200

I’m trying to edit the time only (hours + minutes) but I don’t find the right way.
I have defined in the layout editor an oh-input-card as follow:

component: oh-input-card
config:
  item: pool_prog1_step1_on
  type: time
  sendButton: true
slots: null

but the current time value is empty:


If I type and submit a value, it works but the new value is not shown.

If I modifiy the input card to update the date:

component: oh-input-card
config:
  item: pool_prog1_step1_on
  type: date
  sendButton: true
slots: null

the date is correctly displayed:

Any idea how to display and edit the time like the date?
Thanks for your help

I don’t have a solution for you,but it might help to clarify what you are trying to do.

Poking buttons on the UI sends commands to Items. In the case of a datetime, the default OH ‘autoupdate’ feature would usually cause the command to get reflected in the Item state as well.

You cannot edit Item states as such; you can only command or update a complete new value. So your widget must create a complete datetime, presumably using the existing state as a template, or perhaps ‘now’ from the UI viewpoint, and blend in the user input.

A completely alternative approach is to use some intermediary Item (say representing minutes after midnight, or a clock time as a string, or whatever) and use that in your widget. When the intermediate Item is commanded, a rule can act on that and update the ‘real’ datetime Item.

1 Like

rossko57 is correct. The date input sends only a formatted date and the time input sends only a formatted time. The OH DateTime Item uses the SimpleDateFormat java class to parse the command it receives into it’s state value. The way SimpleDateFormat works it can accept a date without an associated time (it just creates a datetime at midnight of that date), but is cannot parse just a time value with no date. So, the date input succeeds but the time input does not.

If I were to work around this problem, I would probably use the approach rossko57 suggested with a proxy Item and a rule. However, depending on exactly how this information is going to be used there might be other solutions:

  • Does the time value really need to be stored as a DateTime or can you just store it as a string in a String Item? If you’re using this information in a rule, it may be just as easy to parse a formatted time string into the information you need as it is a datetime value.
  • The datetime-local input type will present a date picker and a time picker and provide a formatted datetime string that will be properly parsed into a DateTime Item. If you don’t mind having the extraneous date picker you could just use that.
1 Like

Thanks for your answers.
The time I’m reading from à PLC (Siemens Logo!) is a setpoint I want to change. It is a Double word which is converted in DateTime by the PLCLogo binding. As no date is specified, the current OpenHAB date is added.
Effectively I could retrieve the time as a number and edit it but I would use an easy way to edit the existing time like with the time input type.
The datetime-local input type seems to give something similar to the time input type (existing date/time are not displayed):

Is there a way to ‘create’ a time item which can be displayed and edited similarly to the time type ?

Hmmm, that seems to be a problem with the display of the datetime-local value. There must be an issue with the way the input is parsing the item state. If you use the datetime-local and check your logs you should see that the item is changing state even if the input is not displaying it.

Here’s a simple version of something that might do what you’re looking for:

uid: DTtest
props:
  parameterGroups: []
  parameters: []
tags: []
component: oh-list-card
config: {}
slots:
  default:
    - component: oh-input-item
      config:
        title: ="DT Test (" + dayjs(items.Door_BackDoor_Status_TS.state).format('LT') + ")"
        type: datetime-local
        item: Door_BackDoor_Status_TS
        sendButton: true

You can see that when the input value is sent, the time shown in the label does change so the item is receiving the command, the input just doesn’t display the new value.
DTtest

Hi Justin,
Thanks for this info. Effectively I have seen the change is correctly applied.
I have finally found a convenient alternative in https://community.openhab.org/t/time-picker/118865 that seems to make the job I expect. I would prefer to have something similar to the time input type but…
Animation

For sure some improvements are possible but I need to better understand the widget creation.