Custom rollershutter widget with preset configuration

Thank you @daabm! You could also use a persistence provider to restore the presets at startup, that is what I do.

Did that - thanks for putting me on the right track :+1: Never thought about persistence before :see_no_evil:

Firstly: Thank you to DrRSatzteil; this is very handy!

I am stuck on this… sorry

Here’s how I understood to create the string item for 4:

I am pretty sure, I did not put the ā€œ||… with Num1/2/3… being a number between 0 and 100ā€ correctly, but after trying and trying I can’t figure it out.

When I click on ā€œPresetsā€ in the widget, nothing happens.

Or if the presets won’t work: How could I remove the part with the presets from the widget?

(My config: Windows 10 computer; Openhab 4.0.4)

Hi,

the string item can have any label you want so you can give it a meaningful name. I admit that this is pretty misleading in my description, you don’t have to care about the format at all as it is all taken care of by the rules.

Don’t give up just yet though. I’m pretty sure we can get you there. Could you show you widget configuration and also confirm that you also installed the second widget from the original post?

Wow, now thatā€˜s instant support. Thank you!

I did indeed completely overread the 2nd widget. The popover opens now!

Now, it looks like in Post 9/44:
Bildschirmfoto 2023-11-26 um 07.53.22

However, I can’t change it (click on add does nothing - swipe and delete for the wrong entry does nothing).

EDIT (I had a log posted but it was due to wrong ECMA version): I figured out how to set the scripting setting to ECMA 5.1 (needed to install Nashorn).

Now it does not do anything, but the log also shows nothing.

Oh this looks good so far. Just to make sure that it really isn’t working yet:

If you change the blinds position to let’s say 40% (or any other value) and the click on the ā€œAddā€ button the list should be updated with a value of 40%.

If you swipe the initial NULL entry to the left you should see a button that allows you to delete this preset.

If these things are not working there is still something wrong with the scripts or with the widget configuration.

Here’s my setup:

The three items for 4, 5 and 6:

The rule ā€œadd Presetsā€

configuration: {}
triggers:
  - id: "2"
    configuration:
      itemName: Storen_Preset_add_preset
    type: core.ItemCommandTrigger
conditions: []
actions:
  - inputs: {}
    id: "3"
    configuration:
      type: application/javascript;version=ECMAScript-5.1
      script: >-
        var currentPresets =
        ir.getItem('Storen_Preset_add_preset').state.toString()

        var presetsArray = currentPresets.split('|')

        var index = presetsArray.indexOf(command.toString().split(".")[0])

        if (index < 0) {
          presetsArray.push(command.toString().split(".")[0])
          presetsArray.sort(function(a, b) {
            return a - b;
          })
          var newPresets = presetsArray.join("|")
          events.sendCommand(ir.getItem('Storen_Preset_add_preset'), newPresets)
        }
    type: script.ScriptAction

The rule ā€œdelete Presetsā€

configuration: {}
triggers:
  - id: "2"
    configuration:
      itemName: Storen_Preset_delete_preset
    type: core.ItemCommandTrigger
conditions: []
actions:
  - inputs: {}
    id: "3"
    configuration:
      type: application/javascript;version=ECMAScript-5.1
      script: >-
        var currentPresets =
        ir.getItem('Storen_Preset_delete_preset').state.toString();

        var presetsArray = currentPresets.split('|');

        var index = presetsArray.indexOf(command.toString().split(".")[0]);

        if (index > -1) {
          presetsArray.splice(index, 1);
          var newPresets = presetsArray.join("|");
          events.postUpdate(ir.getItem('Storen_Preset_delete_preset'), newPresets);
        }
    type: script.ScriptAction

Problem:
When I click ā€œaddā€ in the presets popover, nothing happens.
When I swipe the ā€œNULL%ā€ and click delete, nothing happens.

No log entry that seems to be associated with this widget.

Please change the following:

In the add rule change the name of the item in the first and the second to last line to ā€œStoren_Presetā€. The item referenced there should be the item that stores all your presets as an array. I’m only talking about the script code, leave the trigger as it is now.

The same applies to the delete rule. Also use Storen_Preset there and you should be good. :+1:

Oooh, I was stupid/not reading correctly. Sorry!

It really works now! And I learned something about ECMA-versions. There’s still so much to learn. Since I am not a programmer and won’t ever be (but still appreciate to be able to customize stuff), I am very grateful for developers like you who put their products out in the world for free for the crowd and then indulge with our stupid questions.

Thank you very much for the widget and the support and have a great sunday! :bouquet:

1 Like

Hello,
I have read through all the instructions carefully and implemented them (at least I think so).
Nevertheless, I cannot add any presets.

  1. i copied the widgets from above and created them with the same names.
  2. the elements awning_presets, awning_add_presets, awning_del_presets are created and positioned accordingly in the configurations.

Nevertheless, I cannot save any presets.

There are a total of 4 awnings, all of which have their own items and rules.
Can the widget be used for multiple awnings?

configuration: {}
triggers:
  - id: "1"
    configuration:
      itemName: Markise1_add_presets
    type: core.ItemCommandTrigger
conditions: []
actions:
  - inputs: {}
    id: "3"
    configuration:
      type: application/javascript;version=ECMAScript-5.1
      script: |-
        var currentPresets = ir.getItem('Markise1_presets').state.toString()
        var presetsArray = currentPresets.split('|')
        var index = presetsArray.indexOf(command.toString().split(".")[0])
        if (index < 0) {
          presetsArray.push(command.toString().split(".")[0])
          presetsArray.sort(function(a, b) {
            return a - b;
          })
          var newPresets = presetsArray.join("|")
          events.sendCommand(ir.getItem('Markise1_presets'), newPresets)
        }
    type: script.ScriptAction

Das Widget:

component: widget:universal_shutter_v4
config:
  add_preset: Markise1_add_presets
  control: Markise_Unterdach_Control
  delete_preset: Markise1_del_presets
  footer: '=(items.Markise_Unterdach_Control.state.toString().split(".")[0]) == 0
    ? "Offen" :
    (items.Markise_Unterdach_Control.state.toString().split(".")[0])== 100 ?
    "Geschlossen" : ((items.Markise_Unterdach_Control.state).split(".")[0] + "%
    geschlossen")'
  moving: "false"
  position: Markise_Unterdach_Control
  presets: Markise1_presets
  title: Unterdach

Except that several widgets on one page do not work, I can not think of or notice.
Interesting that the position values are stored in the items Markise_Add_Presets, but not with ā€œ|ā€ characters.
Many thanks for your help!

The widget may be used for as many awnings as you like so there is no limitation to only one widget per page.

Iā€˜d say your rule and widget looks good, can you please show your item definitions?

here the item definitions:

label: Markise 1 Presets
type: String
category: ""
groupNames: []
tags: []
label: Markise 1 Add Presets
type: String
category: ""
groupNames: []
tags: []
label: Markise 1 delete Presets
type: String
category: ""
groupNames: []
tags: []

I think, there is nothing special.
Thank you very much for your quick response!!!

Yes, its that simple. Good… what’s the current state of ā€žMarkise 1 Presetsā€œ? Do you have any errors from the execution of the rule in the logs?

Oh and tell me what happens when you try to do so: you know that you can only add a preset when the current state of the awning is different from an already existing preset. So make sure that the control of the awning works as expected

in the event log are a lot of items:

[INFO ] [openhab.event.ItemCommandEvent      ] - Item 'Markise4_del_presets' received command NULL
[INFO ] [openhab.event.ItemCommandEvent      ] - Item 'Markise4_add_presets' received command 65
[INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Markise4_add_presets' changed from 66 to 65
[INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Markise2_presets' changed from 36 to 55
[INFO ] [openhab.event.ItemCommandEvent      ] - Item 'Markise2_presets' received command 55
[INFO ] [openhab.event.ItemCommandEvent      ] - Item 'Markise3_del_presets' received command NULL
[INFO ] [openhab.event.ItemCommandEvent      ] - Item 'Markise4_add_presets' received command 0
[INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Markise2_del_presets' changed from 36 to 55
[INFO ] [openhab.event.ItemCommandEvent      ] - Item 'Markise2_del_presets' received command 55

interestingly, one widget contains a value, all other 3 show ā€œNULL%ā€ for no element I can add a value, nor delete; although other positions are approached.

My openhab has version 4.2.1 and runs as a docker image on a QNAP.

This looks good except for Markise 2. It seems that you used the Markise2_presets item instead of the Markise2_add_presets item (just a guess).

But for Markise 4 I can see that your add_presets item receives commands as expected. After that, the rule should be triggered to change the Markise4_presets item state. Can you verify that the rule is running? Do you have a command to the Markise4_add_presets item set as trigger for the rule? Is anything in the openhab.log when you add a preset?

Now I have installed a switch to trigger the rule, unfortunately without success.
I have found the following entry in the openhab.log:

[e.internal.SseItemStatesEventBuilder] - Attempting to send a state update of an item which doesn't exist: Verikal_Markise_vorne_Links_Control

This is all very strange :frowning:

I’ll start the container again (but not until tonight)

[e.internal.SseItemStatesEventBuilder] - Attempting to send a state update of an item which doesn’t exist: Verikal_Markise_vorne_Links_Control

This usually means that you configured an item in a widget that does not exist (anymore). It’s probably not related especially since you have multiple devices.

I was wondering, does the ā€œreleaseOnly: trueā€ command work in this widget? If not, how can we add it because it’s a MUST, otherwise when using the slider it’s sending multiple commands. :frowning:

I haven’t tried but you should be able to add this line to the config of the oh-slider component:

releaseOnly: true