I am not sure exactly what you are looking for, but here is an example to try to put it all together:
Let’s assume you have the following items:
Switch aSwitch
Contact aContact
You can then do the following in a rule:
aSwitch.sendCommand(ON)
aContact.postUpdate(OPEN)
What is listed as Command Types in http://docs.openhab.org/concepts/items.html might be a bit confusing, but this is the type of command or state that you can give as input to the .sendCommand() or .postUpdate() methods.
Please note that not all item types (e.g. the Contact) supports the sendCommand method.
Thanks Daniel, exactly what I was looking for. I was apparently on the wrong Items page, and my Google search did not work out either!
It seems I might be on the wrong path. What I’m trying to achieve is to make a rule that updates a String item with an exec binding. I want to forward a value from another item. postUpdate seems to work as intended in the log, but it has no effect. If I understand the documentation correctly, this action just updates what the state of an item is, but don’t trigger any actions.
sendCommand, on the other hand, does not seem to work with a value. As per the documentation Daniel referred to, the commands are a fixed set of statements.
rule "a"
when
Item Hc2_Stue_Sofalys_get changed
then
logInfo("HC2", "Sofalys changed: {}", Hc2_Stue_Sofalys_get.state)
Hc2_Stue_Sofalys.postUpdate(Hc2_Stue_Sofalys_get.state)
end
rule "b"
when
Item Hc2_Stue_Sofalys changed
then
logInfo("HC2", "Sofalys manually changed: {}", Hc2_Stue_Sofalys.state)
//Hc2_Stue_Sofalys_set.postUpdate(Hc2_Stue_Sofalys.state)
Hc2_Stue_Sofalys_set.sendCommand(Hc2_Stue_Sofalys.state)
//sendCommand(Hc2_Stue_Sofalys_set, Hc2_Stue_Sofalys.state)
end
Console (when manipulating the first Item from Habpanel):
21:38:39.023 [INFO ] [smarthome.event.ItemCommandEvent ] - Item 'Hc2_Stue_Sofalys' received command 40
21:38:39.033 [INFO ] [marthome.event.ItemStateChangedEvent] - Hc2_Stue_Sofalys changed from 72 to 40
21:38:39.051 [INFO ] [g.eclipse.smarthome.model.script.HC2] - Sofalys manually changed: 40
21:38:39.056 [ERROR] [.script.engine.ScriptExecutionThread] - Rule 'b': An error occured during the script execution: Could not invoke method: org.eclipse.smarthome.model.script.actions.BusEvent.sendCommand(org.eclipse.smarthome.core.items.Item,java.lang.String) on instance: null
rule "b"
when
Item Hc2_Stue_Sofalys changed
then
logInfo("HC2", "Sofalys manually changed: {}", Hc2_Stue_Sofalys.state)
Hc2_Stue_Sofalys_set.sendCommand(Hc2_Stue_Sofalys.state.toString)
end