Rule change without change at initialization

Hi,

i have two widgets. A multiswitch to change a lot of items. with the other widget (dropdown) i change the items for the multiswitch.

I use a change rule for the multiswitch:
Item A change or Item B change …

If the dropdown item change i want initialize the multiswitch with the saved state of the items.

My problem is, if i initialize the items also the multiswitch rule fired with the item change.

Could i write a rule that only fired if the dropdown not changed?
Or could i use a rule that only fired if a item change only about the multiswitch widget?
Or how can i initialize items but not with system start?

I hope one of you can help me.

Then, don’t initialize them?
A rule triggered by Item change can use previousState to detect a change from a NULL state, so you know this is the first change since boot.

I need allways a new initialize if i change the item in the dropdown Widget because the item values for the Multiswitch Widget are changed.
So its not a real initialize from Null to an other value. Its loading other values from an other Dataset for the same items.

my example:
dropdown include a list of Hardware switches.
the Multiswitch include a list of outputs (lamp, shutters…)
If i select the switch in the living room i select the lamp Output maybe the shutter of the living room.
Now i change the Hardware switch in the dropdown. i select the switch for the kitchen. Now i have to load the values for the kitchen Switch in the Multiswitch.
Its a setup for mapping inputs and outputs.

It’s not that clear what your problem is.

I think I understand what you say - you have a dropdown on the UI and when you select an option, it triggers a rule to “do stuff”.

Are you “pre-filling” the dropdown option at system boot? And that unwantedly triggers the “do stuff” rule?

At the simplest - don’t pre-fill the dropdown.

But maybe you’d like to, so that the UI represents some old selection, that’s fair enough.

Selections in the UI always generate Item commands.
If you have a rule triggered from command, it will not get triggered when an Item is postUpdated by your own code or by restore-on-startup.

Maybe I do misunderstand, but it sounds to me as if you do a selection with the dropdown on which you select an option and do have another item (multiswitch) which does trigger the real action/ rule. In this case I would trigger the rule by the multiswitch and check the actually selected dropdown element.

Yes its exactly this case. the dropdown change trigger the rule for the multiswitch.
And this is my problem.

I need the Information if and how long the event go on.

rule init
when item dropdown changed then

if (saveVariable1.state ==“ON”)
{ MultiswitchValiable1 = “ON”}
else
{ MultiswitchValiable1 = “OFF”}
if (saveVariable2.state ==“ON”)
{ MultiswitchValiable2 = “ON”}
else
{ MultiswitchValiable2 = “OFF”}

… the same for all other variables

end

rule work
when item MultiswitchValiable changed then

if (MultiswitchValiable1 == “ON”)
{saveVariable1.state =“ON”}
if (MultiswitchValiable2 == “ON”)
{saveVariable2.state =“ON”}

end

If rule init trigger i dont want the trigger for the rule work. But how?
Maybe with a return in the rule work? But i dont find something how “if (dropdown changed) {return}”.
Maybe i can use a temp Item only for this situation. But how?
I dont know when i have to write this item and when the dropdown change is finished.
Maybe i can use a special event? But i found nothing.

And i need this rule init because i want to use this two widgets for a lot of items. I dont want for each dropdown item an own widget.

I hope you unterstand me :-/

Not that well, but let’s try.

Please post your rule snippets in code fences, so that they don’t get messed about by the forum text formatting.

The rules as posted obviously don’t work, it would probably help to show us your real rules.

Now, so far as I can make out, you want to alter some Items states in one rule. But you have a different rule triggered by those Items changing - and you don’t want that rule triggered when those Items change.

It would probably help if you told us or showed us what you are actually trying to do, rather than telling us how you want to fix it. There may be better ways.

This might or might not help -

rule "init"
   when Item dropdown changed
then
   if ( some condition) {
       Multivariable.postUpdate( some new value)
          // note postUpdate will not trigger other rule
   }
end

rule "work"
when
   Item Multivariable received command
then
   if (receivedCommand == some value) {
      // do stuff
   }
end

It sounds like you are referring to Habpanel widgets. A screenshot would help! It sounds to me like you have a widget with several switches in it. Instead of adding even more switches and cluttering up the widget, you have a second widget with a dropdown that changes the functionality of the switches. Like a dropdown to select a room, and switches to control the devices in that room.

How about creating all of the switch widgets and link them to actual Items, and use ng-if to hide them based on the value of the Item linked to the dropdown widget? This wouldn’t require any rules, and there’s probably an example in the Habpanel area.

Thanks all for help. I fixed the problem with the command “postUpdate”.

Now i cant change left the dorpdown and load the settings in the right Multiswitch without any effect.