openhab / openhab-js

openHAB JavaScript Library for JavaScript Scripting Automation
https://www.openhab.org/addons/automation/jsscripting/
Eclipse Public License 2.0
38 stars 31 forks source link

Function to send Item updates only in some cases #369

Open mueller-ma opened 1 month ago

mueller-ma commented 1 month ago

I have a rule "when it gets dark outside, turn on the lights to 20%": items.getItem("Lights").sendCommand("20"). However this will darken the light when it has been turned to 100% manually before. I wrapped it in a if to avoid this, but maybe a function for this could be added, similar to sendCommandIfDifferent():

This only applies to Number Items.

Feel free to close this if you think it's too niche.

florian-h05 commented 1 month ago

It's type of niche, but I see the use case.

This only applies to Number Items.

I would say Dimmer Items, not Number. Did you mean that?

mueller-ma commented 1 month ago

Hm, it applies to all Items that can have a state as a number, e.g. also Rollershutter.