I use OpenHAB 4.2.2 For items reported over /rest/items/ as read-only: true, OpenHAB-Android 3.17.4-beta renders them as … read-only. In the use case described below, an MQTT channel is involved, which does not contain transformationPatternOut, or commandTopic. But when the sitemap-switch connected to the item is toggled (e.g. in BasicUI), a Groovy script is triggered, which does set several values in MQTT. So that mqtt-channel itself does not set values to MQTT, but the item associated to channel should be clickable, as its state is monitored from a Groovy script. As a work-around to get read-write status of the item I add a commandTopic="abc" to the MQTT-channel. I do not want to toggle an MQTT-value outside of script, e.g. in a transform, as it can leave the system in an inconsistent state - only one of the three properties is changed, while all of them should be changed at once, e.g. because the Groovy script right now has syntax error; or the Groovy scripting engine has not loaded yet, but the users, start clicking in the sitemap-UI toggling values.
- It should be possible to have an item in a sitemap, which is linked to an MQTT-thing/channel, and the sitemap item should be read-write, while the MQTT-thing cannot send commands.
For an mqtt channel:
Thing mqtt:topic:r9 "Реле 9" (mqtt:broker:b1) [availabilityTopic="r9/online", payloadNotAvailable="false", payloadAvailable="true"] {
Type switch : r9_manual "Реле 9" [stateTopic="r9V/rpc", transformationPattern="JSONPATH:$.result.initial_state", off="off", on="restore_last"]
}
I define an item:
Switch r9_manual "Управление[]" (gRele9) ["Switch"] {channel="mqtt:topic:r9:r9_manual"}
and put it in a sitemap:
Switch item=r9_manual mappings=[ON="Ръчно", OFF="Автоматично"] labelcolor=[OFF="green", ON="red"] visibility=[!=NULL]
For this item (thing), http://server/rest/items/r9_manual returns readOnly: true:
{"link":"http://server/rest/items/r9_manual","state":"ON",
"stateDescription":{"pattern":"","readOnly":true,"options":[]},
"metadata":{"semantics":{"value":"Point_Control_Switch","config":{"isPointOf":"gRele9"}}},
"editable":false,"type":"Switch","name":"r9_manual","label":"Управление",
"category":"none","tags":["Switch"],"groupNames":["gRele9"]}
If I add in the thing/channel commandTopic="abc", then readOnly changes to false:
Type switch : r9_manual "Реле 9" [stateTopic="r9V/rpc", transformationPattern="JSONPATH:$.result.initial_state", off="off", on="restore_last", commandTopic="abc"]
{"link":"http://server/rest/items/r9_manual","state":"ON",
"stateDescription":{"pattern":"","readOnly":false,"options":[]},
"metadata":{"semantics":{"value":"Point_Control_Switch","config":{"isPointOf":"gRele9"}}},
"editable":false,"type":"Switch","name":"r9_manual","label":"Управление",
"category":"none","tags":["Switch"],"groupNames":["gRele9"]}
For that switch I have in fact a Groovy change listener, which does several things, beyond changing a single MQTT value (it changes actually three values):
automationManager.addRule(new SimpleRule() {
String name = "Минаване на ръчно/автоматично управление Groovy"
@Override
Object execute(Action module, Map<String, ?> inputs) {
regulacia = [] ; // array of objects, including r9
final String y = inputs.event.getItemName().substring(0, 2), t = y + "/rpc" // this is calculated to r9/rpc here
if (inputs.newState == OnOffType.ON && inputs.oldState != UnDefType.NULL) {
mqtt_broker.publishMQTT(t, '{"id":10,"src":"S","method":"Script.Stop","params":{"id":1}}')
mqtt_broker.publishMQTT(t, '{"id":11,"src":"T","method":"Script.SetConfig","params":{"id":1,"config":{"enable":false}}}')
mqtt_broker.publishMQTT(t, '{"id":12,"src":"U","method":"Switch.SetConfig","params":{"id":0,"config":{"initial_state":"restore_last"}}}')
} else if (inputs.newState == OnOffType.OFF && inputs.oldState != UnDefType.NULL) {
mqtt_broker.publishMQTT(t, '{"id":20,"src":"S","method":"Script.Start","params":{"id":1}}')
mqtt_broker.publishMQTT(t, '{"id":21,"src":"T","method":"Script.SetConfig","params":{"id":1,"config":{"enable":true}}}')
mqtt_broker.publishMQTT(t, '{"id":22,"src":"U","method":"Switch.SetConfig","params":{"id":0,"config":{"initial_state":"off"}}}')
}
execute1(inputs)
}
List<Trigger> triggers = releta.collect{
TriggerBuilder.create().withId("Manual_" + it.name).withTypeUID("core.ItemStateChangeTrigger")
.withConfiguration(new Configuration([itemName: it.name + "_manual"])).build()
}
})
So when the switch is clicked, a lot of things happen. But since core says the item is read-only, OpenHAB-Android 3.17.4-beta does not allow to click it.
I use OpenHAB 4.2.2 For items reported over /rest/items/ as read-only: true, OpenHAB-Android 3.17.4-beta renders them as … read-only. In the use case described below, an MQTT channel is involved, which does not contain transformationPatternOut, or commandTopic. But when the sitemap-switch connected to the item is toggled (e.g. in BasicUI), a Groovy script is triggered, which does set several values in MQTT. So that mqtt-channel itself does not set values to MQTT, but the item associated to channel should be clickable, as its state is monitored from a Groovy script. As a work-around to get read-write status of the item I add a
commandTopic="abc"to the MQTT-channel. I do not want to toggle an MQTT-value outside of script, e.g. in a transform, as it can leave the system in an inconsistent state - only one of the three properties is changed, while all of them should be changed at once, e.g. because the Groovy script right now has syntax error; or the Groovy scripting engine has not loaded yet, but the users, start clicking in the sitemap-UI toggling values.For an mqtt channel:
I define an item:
and put it in a sitemap:
For this item (thing), http://server/rest/items/r9_manual returns readOnly: true:
{"link":"http://server/rest/items/r9_manual","state":"ON", "stateDescription":{"pattern":"","readOnly":true,"options":[]}, "metadata":{"semantics":{"value":"Point_Control_Switch","config":{"isPointOf":"gRele9"}}}, "editable":false,"type":"Switch","name":"r9_manual","label":"Управление", "category":"none","tags":["Switch"],"groupNames":["gRele9"]}If I add in the thing/channel
commandTopic="abc", then readOnly changes to false:{"link":"http://server/rest/items/r9_manual","state":"ON", "stateDescription":{"pattern":"","readOnly":false,"options":[]}, "metadata":{"semantics":{"value":"Point_Control_Switch","config":{"isPointOf":"gRele9"}}}, "editable":false,"type":"Switch","name":"r9_manual","label":"Управление", "category":"none","tags":["Switch"],"groupNames":["gRele9"]}For that switch I have in fact a Groovy change listener, which does several things, beyond changing a single MQTT value (it changes actually three values):
So when the switch is clicked, a lot of things happen. But since core says the item is read-only, OpenHAB-Android 3.17.4-beta does not allow to click it.