Numberformating on Slider

  • Platform information:
    • Hardware: Docker on synology Nas
    • openHAB version: 3.3.0

ello Community

I am an absolute beginner as far as openHAB is concerned.
Since I have a Nas, the Docker installation offered itself. So far I have been able to build or solve quite a few things. The start was a bit difficult, but you always learn something new. :blush:

What I can’t get right though, even after searching for a while, is my configuration for a slider.

I have connected a Tuya switch, and included it under Pages. The slider (configured as a dimmer) sets a countdown, which then turns off the light at 0. That works so far.
But the number on the right side of the slider bothers me. This is displayed in seconds (6h = 21600seconds). If I now manage to format the slider in hh:mm:ss, I have the problem that the time does not arrive on the MQTT broker. Nothing seems to be transmitted.
I have created a second item *_Timer and configured it with Date:Time so that the patterns for the formatting work.

I am facing a puzzle how to teach the slider a conversion that is done in hh:mm:ss and sends to MQTT the corresponding seconds. With Type Number or Number:Time it definitely doesn’t work.

Does anyone have a beginner tip for me?

greets Tim

How did you do this? Through the state description Item metadata?

I recommend using a Number:Time Item instead of a Dimmer. Then you can use a state description pattern of %1$tH:%1$tM:%1$tS to format the seconds to hours, minutes, seconds (Number:Time supports the same formatting as DateTime). I think the slider will pick that up.

You’ll have to elaborate. Doesn’t work how? Logs?

A caution on this, it kind-a sort-a works for display less than 24-hours, but it is an unsupported bodge.

I really cannot predict what it does if you also rely on it to set the Item’s default units for the commands from a slider widget.

Have a look at your events.log to figure how the UI does it. Not all the UIs might handle this the same.

You’ll need to clarify exactly what you want to send over MQTT before you can figure out how.

It should work for up to 31 days, right? At least for the formatting. As I understand it, it basically adds the seconds to epoch 0 so the formatting should work until you get to the equivalent of Feb 1, 1970.

You’ve got to hope the slider widget ignores it, maybe it does, and instead finds some sensible unit to use, maybe it does that too. The problem I foresee revolves around the Item’s default unit, as defined by ‘pattern’ metadata. A datetime formatter isn’t a sensible default unit, so what will it use instead? Could be seconds I suppose.
There’s more to “get away with” when commands are involved, rather than just display.

So,
Here are the 3 different countdown sliders.
image

Switch - 6 - Countdown
is configured with 21600 seconds (6h). This one converts the whole thing and counts.
Itemtype: Number:Time

Of course the following was also implemented here
Item Metadata: stateDescription
value: " "
config:
max: “21600”
min: "0
pattern: “%1$tH:%1$tM:%1$tS”
step: “1”
MQTT gets the number under command and counts down in state
▼2
state = 20500
command = 21600

output shows seconds and no timeformat

Switch - 6 - Test
Everything identical to Switch - 6 - Countdown
Only one thoing is changed
Itemtype: Number:Time to Itemtype: DateTime

and there you see, that the format is correct. but… no function with the slider.

The logs seem to send date values and not the numbers

2022-11-29 17:45:04.324 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'TuyaMQTT_tuyaSwitch6countdown' received command 12857
2022-11-29 17:45:04.325 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'TuyaMQTT_tuyaSwitch6countdown' predicted to become 12857
2022-11-29 17:45:04.328 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'TuyaMQTT_tuyaSwitch6countdown' changed from 11170 to 12857
2022-11-29 17:45:04.465 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'TuyaMQTT_tuyaSwitch6countdown_Time' changed from 1970-01-01T03:06:10.000+0000 to 1970-01-01T03:34:17.000+0000
2022-11-29 17:45:04.533 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'TuyaMQTT_tuyaSwitch6countdown' received command 14400
2022-11-29 17:45:04.535 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'TuyaMQTT_tuyaSwitch6countdown' predicted to become 14400
2022-11-29 17:45:04.539 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'TuyaMQTT_tuyaSwitch6countdown' changed from 12857 to 14400
2022-11-29 17:45:04.679 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'TuyaMQTT_tuyaSwitch6countdown_Time' changed from 1970-01-01T03:34:17.000+0000 to 1970-01-01T04:00:00.000+0000
2022-11-29 17:45:07.738 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'TuyaMQTT_tuyaSwitch6countdown' received command 7200
2022-11-29 17:45:07.740 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'TuyaMQTT_tuyaSwitch6countdown' predicted to become 7200
2022-11-29 17:45:07.744 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'TuyaMQTT_tuyaSwitch6countdown' changed from 14400 to 7200
2022-11-29 17:45:07.895 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'TuyaMQTT_tuyaSwitch6countdown_Time' changed from 1970-01-01T04:00:00.000+0000 to 1970-01-01T02:00:00.000+0000
2022-11-29 17:45:07.953 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'TuyaMQTT_tuyaSwitch6countdown' received command 4114
2022-11-29 17:45:07.955 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'TuyaMQTT_tuyaSwitch6countdown' predicted to become 4114
2022-11-29 17:45:07.959 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'TuyaMQTT_tuyaSwitch6countdown' changed from 7200 to 4114
2022-11-29 17:45:08.116 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'TuyaMQTT_tuyaSwitch6countdown_Time' changed from 1970-01-01T02:00:00.000+0000 to 1970-01-01T01:08:34.000+0000
2022-11-29 17:45:09.722 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'TuyaMQTT_tuyaSwitch6countdown' received command 12343
2022-11-29 17:45:09.727 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'TuyaMQTT_tuyaSwitch6countdown' predicted to become 12343
2022-11-29 17:45:09.738 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'TuyaMQTT_tuyaSwitch6countdown' changed from 4114 to 12343
2022-11-29 17:45:09.898 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'TuyaMQTT_tuyaSwitch6countdown_Time' changed from 1970-01-01T01:08:34.000+0000 to 1970-01-01T03:25:43.000+0000
2022-11-29 17:45:09.925 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'TuyaMQTT_tuyaSwitch6countdown' received command 19029
2022-11-29 17:45:09.927 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'TuyaMQTT_tuyaSwitch6countdown' predicted to become 19029
2022-11-29 17:45:09.933 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'TuyaMQTT_tuyaSwitch6countdown' changed from 12343 to 19029
2022-11-29 17:45:10.078 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'TuyaMQTT_tuyaSwitch6countdown_Time' changed from 1970-01-01T03:25:43.000+0000 to 1970-01-01T05:17:09.000+0000
2022-11-29 17:45:10.132 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'TuyaMQTT_tuyaSwitch6countdown' received command 21600
2022-11-29 17:45:10.133 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'TuyaMQTT_tuyaSwitch6countdown' predicted to become 21600
2022-11-29 17:45:10.137 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'TuyaMQTT_tuyaSwitch6countdown' changed from 19029 to 21600
2022-11-29 17:45:10.278 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'TuyaMQTT_tuyaSwitch6countdown_Time' changed from 1970-01-01T05:17:09.000+0000 to 1970-01-01T06:00:00.000+0000
2022-11-29 17:45:15.826 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'TuyaMQTT_tuyaSwitch6countdown_Time' changed from 1970-01-01T06:00:00.000+0000 to 1970-01-01T05:59:55.000+0000
2022-11-29 17:45:15.828 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'TuyaMQTT_tuyaSwitch6countdown' changed from 21600 to 21595
2022-11-29 17:45:20.825 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'TuyaMQTT_tuyaSwitch6countdown_Time' changed from 1970-01-01T05:59:55.000+0000 to 1970-01-01T05:59:50.000+0000
2022-11-29 17:45:20.828 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'TuyaMQTT_tuyaSwitch6countdown' changed from 21595 to 21590
2022-11-29 17:45:25.830 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'TuyaMQTT_tuyaSwitch6countdown_Time' changed from 1970-01-01T05:59:50.000+0000 to 1970-01-01T05:59:45.000+0000
2022-11-29 17:45:25.831 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'TuyaMQTT_tuyaSwitch6countdown' changed from 21590 to 21585
2022-11-29 17:45:30.826 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'TuyaMQTT_tuyaSwitch6countdown_Time' changed from 1970-01-01T05:59:45.000+0000 to 1970-01-01T05:59:40.000+0000
2022-11-29 17:45:30.826 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'TuyaMQTT_tuyaSwitch6countdown' changed from 21585 to 21580

MQTT can not work with changed from 1970-01-01T05:59:45.000+0000 to 1970-01-01T05:59:40.000+0000 that is clear :slight_smile:

With the Itemtype countdown I somehow don’t get along, what this can / should do at all :slight_smile:

Based on the new changes recently merged it should use the default unit (there is a default now) which would be s. But I don’t know for sure if the state description would interfere with that.

The date time formatter actually doesn’t define a unit so my hope would be it doesn’t see a unit and uses the default one.

Well, of course, because it’s a DateTime Item. It’s not a number. I’m a little surprised it sends anything at all.

Which Slider widget are you using here. oh-slider-card?

I think you can define a label property with a value along the lines of label: =items[NameOfItem].displayState and for the Number:Time example it will use the state description formatted state for the label instead of the state that it appears to be using here.

You might need to do this through the YAMl on the code tab though. Not all possible properties, particularly inherited properties, are shown in the UI form when configuring a widget.

If that means that you want a plain-number command to your openHAB Item for forwarding over MQTT, just do that.
Use a Number tpe Item, set up your slider with the limits that you want.

That leaves just the numeric display, which you can format using a little JS transformation, by specifying that in ‘pattern’ and having the widget use displayState.

here the code:

component: oh-slider-item
                            config:
                              label: =items[TuyaMQTT_tuyaSwitch6countdown].displayState
                              after: sek.
                              item: TuyaMQTT_tuyaSwitch6countdown
                              max: 21600
                              min: 0
                              step: 1
                              subtitle: Subtitle
                              title: Switch - 6 - Countdown
                          - component: oh-slider-item
                            config:
                              item: TuyaMQTT_tuyaSwitch6countdown_Time
                              max: 21600
                              min: 0
                              step: 1
                              subtitle: Subtitle
                              title: Switch - 6 - Test
                            slots: null
                          - component: oh-label-item
                            config:
                              icon: oh:time
                              item: TuyaMQTT_tuyaSwitch6countdown_Time

this don´t work.

fact is here: functional slider with seconds only sends the the command right.
changed Date from to Date
received command number (in seconds),
predicted to become number (in seconds)


2022-11-29 17:45:10.132 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'TuyaMQTT_tuyaSwitch6countdown' received command 21600
2022-11-29 17:45:10.133 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'TuyaMQTT_tuyaSwitch6countdown' predicted to become 21600
2022-11-29 17:45:10.137 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'TuyaMQTT_tuyaSwitch6countdown' changed from 19029 to 21600

the timer slider, in DateTime format have only
changed Datum from to Datum
changed from number (in seconds) to number

2022-11-29 17:45:30.826 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'TuyaMQTT_tuyaSwitch6countdown_Time' changed from 1970-01-01T05:59:45.000+0000 to 1970-01-01T05:59:40.000+0000

so the format works different

A DateTime Item is never going to work as you want with the slider and the MQTT binding. So there’s no point messing with that any further. A DateTime isn’t a number and doesn’t act like a number. It’s only ever going to work how you want with a Number.

An infinity is contained in those three words. Silently fails? Shows and error? If so what’s the error?

It’s a part of oh-slider-item (which is an important distinction because there are differences between oh-slider, oh-slider-card and oh-slider-item. But I’m not positive that label is the right property name.

And truth be told, it works as expected for me by default anyway.

value: oh-slider-item
config:
  max: 21600
  min: 0
  title: Test using Number:Seconds
  step: 1
  subtitle: Subtitle

gives me

My Item’s state description metadata is:

value: " "
config:
  pattern: "%1$tH:%1$tM:%1$tS"

And the commands received by the Item when I use the slider:

2022-11-29 13:19:55.713 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'TestNumber' received command 7242                                                        │
2022-11-29 13:19:55.715 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'TestNumber' changed from 6981 s to 7242 s

Note: the item widgets are not expected to appear alone on a Page. They are shown inside an oh-list-card widget. You don’t show the fill config but perhaps if you are putting these on a page by themselves that could be a problem.

It also might be working differently for me because I’m on the snapshots and there have been some changes made relevant to this which I might have and you might not have.

You’ll notice that the command is actually just a plain old number but when the change is processed, the default units are added automatically.

Hi,

I took the hint and updated the system to 3.4.0.M5.

here one has, as far as the UX and content of the slider, made adjustments that now a) take over the patterns and b) I can also insert blank text there, which then overwrites everything. from therefore first good.

pity are but here 2 things.

  1. the scale remains at seconds (here in the example the numerical value is seconds which would be 21600s at 6h). unfortunately you can’t use the scale with that. who wants to convert :slight_smile:

  2. if I want to convert seconds into minutes (input in minutes or hours), then I convert the seconds over steps. (e.g. 1min corresponds then step:60). one sees, how the count-down counts down, but with 30sec. then stops, is finished, but no switching condition further carries out.

must look how I can look here the log accordingly me times.

Greetings Tim

You can add tick marks and adjust the slider steps. For example, you could set the step to 60, scaleSteps to 3600 and scaleSubSteps to 60 and the slider will advance based on minutes instead of seconds and the tick marks will help orient you.

Ultimately, this is why one rarely sees sliders being used in relation to time. It’s just not a very good user experience. There’s always something.

I don’t understand what you are explaining here.

And item type should be number:time , so it‘s been displayed as hh:mm:ss