Switch control problem

I have a switch to control a modbus relay.


I created a simple widget with a switch :
image
configareted as usual:
image
when I click, switch will change a state and modbus relay also switch on/off
My problem is, that I also want create a rule for automatic switching of this relay. As a first step I tried send only simple instruction :
Modbus_Data_relay_2_807_Value_as_Switch.state = ON
problem is, that switch will change a state to ON only for a second (maybe shorter) and then will switch back to OFF
Really don’t know why.

Try sendCommand("Modbus_Data_relay_2_807_Value_as_Switch.state",ON) instead

don’t work

But you showed me a way :

this works
Modbus_Data_relay_2_807_Value_as_Switch.sendCommand(ON)
thanks

My mistake, should be sendCommand(“Modbus_Data_relay_2_807_Value_as_Switch",ON)

This is the prefered way (don’t remember why but you’ll find clues in the forum)

That one might not work too. The sendCommand Action requires two Strings as arguments, the name of the Item and the command as a String. So sendCommand(“Modbus_Data_relay_2_807_Value_as_Switch","ON") would definitely work.

Quite the opposite actually. In Rules DSL the preferred way is to use the sendCommand on the Item instead of using the Action. The reason is method on the Item:

  • can accept the command/state enums. (e.g. ON, PLAY, CLOSED, etc.)
  • is much better at converting between acceptable types
  • this is personal opinion, but it reads better for the human.

The Action is preferred in situations where the Item name isn’t known up front (e.g. the name was constructed through string concatenation in the rule).

2 Likes

Ok @rlkoshak - I’ll stay away from users on the forum :crazy_face: :wink:

Gold!