JSR223/Javascript: Item switch changes state but doesn't do anything

I have a rule (JSR223/Javascript) working which runs every couple of minutes, checks the outdoor and indoor temperatures, and sets the a switch item to ON or OFF according to whether the indoor temperature is higher or lower. I see the switch change state in PaperUI. All good. The switch item is linked to a thing which writes a value to a Modbus register to open or close the bypass valve of the ventilation machine. If I operate the switch manually, it changes the state of the bypass and I see it reflected in the bypass state values read out from the relevant registers. However, when the switch state is changed from the rule, the bypass state doesn’t change. What am I missing? Here is the relevant snippet.

var itemBypassSwitch = getItem('BrinkDataWriteBypassValve6006_ValueAsSwitch');

itemBypassSwitch.state = ON;

I imagine some kind of update or notification is missing.

Try events.sendCommand(itemBypassSwitchState, ON) instead of assigning .state=ON.

See https://openhab-scripters.github.io/openhab-helper-libraries/Guides/But%20How%20Do%20I.html#send-a-command-to-an-item


Spot on:

 sendCommand(itemBypassSwitch, ON);

Thanks! :grinning:

It’s important to grasp the distinction between command and state in openHAB, and how bindings usually interact.

You might not yet have found events.log, where you can see what poking the UI does to Items.

1 Like

I certainly have found events.log, and I noticed the difference between setting the state and using command, but I’m new in all this.