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