i d like to change the state of an item in another OH instance via the rest api.
here is what i ve got already but it doesnt seem to work:
rule "aslivesend"
when
Time cron " 1 * * * * ?"
then
if(helper.state==NULL){
sendCommand(helper,OFF)
}
if(internal.state==NULL){
sendCommand(internal,OFF)
}
logInfo("alive","alive executed state:"+internal.state.toString())
if(internal.state.toString()=="ON"){
sendHttpPutRequest("http://172.24.1.153:8080/rest/items/external/state", "text/plain","OFF")
sendCommand(internal,OFF)
internal.persist
logInfo("alive","Alivemessage send to 172.24.1.153 MSG:OFF")
}
else if(internal.state.toString()=="OFF"){
sendHttpPutRequest("http://172.24.1.153:8080/rest/items/external/state", "text/plain","ON")
sendCommand(internal,ON)
internal.persist
logInfo("alive","Alivemessage send to 17.24.1.153 MSG:ON")
}
end
before you ask me what its supposed to do,
I have 2 instances of OH running at the same time i ve created 3 switch items
1)external
2)internal
3)helper
internal is like a dummy switch i use to toggle
external is supposed to be changed via the rest api
helper is supposed to track if external changed within the last 1minute 30 seconds
so it is basically a crossover changing of items so i can test if the other instance is still running
ok so if anybody has an idea the problem occours rather curious to me since i added some logs and it seems that the item change will be executed but the item change of internal never happens so it executes the same thing every time.
new code:
rule "aslivesend"
when
Time cron " 1 * * * * ?"
then
if(helper.state==NULL){
sendCommand(helper,OFF)
}
if(internal.state==NULL){
sendCommand(internal,OFF)
}
logInfo("alive","alive executed state:"+internal.state.toString())
if(internal.state.toString()=="ON"){
logInfo("alive","internal==ON executed")
sendHttpPutRequest("http://172.24.1.153:8080/rest/items/external/state", "text/plain","OFF")
logInfo("alive","HTTPPut executed")
sendCommand(internal,OFF)
logInfo("alive","changed internal new state:"+internal.state.toString())
internal.persist
logInfo("alive","alive check done executing Alivemessage send to 172.24.1.153 MSG:OFF")
}
else if(internal.state.toString()=="OFF"){
logInfo("alive","internal==OFF executed")
sendHttpPutRequest("http://172.24.1.153:8080/rest/items/external/state", "text/plain","ON")
logInfo("alive","HTTPPut executed")
sendCommand(internal,ON)
logInfo("alive","changed internal new state:"+internal.state.toString())
internal.persist
logInfo("alive","alive check done executingAlivemessage send to 17.24.1.153 MSG:ON")
}
end
This will try to ping hostname on port every 60 seconds and if the host is up and the port open then whatever Switch this gets linked to is set to ON. If the port goes down or the host does off the network the Switch will go to OFF.