hello,
In Openhab 2.x, when a Rule issued a postUpdate(item, state)
to an item, the item state will be updated in Openhab, and the item will also re-publish it’s state via linked MQTT message.
Subscribed devices external to OH would also receive notification of the state change.
Observed behaviour in OH3.x
In Openhab 3.x… the same Rule, successfully updates the state of the Item in Openhab interfaces, however, no MQTT message is published from the item that has now changed it’s state.
Question
Is there a different approach/command I can use to tell the switch Item to re-publish it’s state via MQTT?
Thing
Thing topic AllKitchenLightsSwitch "AllKitchenLightsSwitch .thing" @ "Group Switches" {
Channels:
Type switch : light "AllKitchenLightsSwitch .thing"[
commandTopic="myhome/HMI/page0/group/KitchenAllLights/switch/state", transformationPattern="MAP:switchboard.map",
stateTopic="myhome/group/KitchenAllLights/switch/command",
postCommand=true]
}
example
Rule
rule "KitchenAllLightsSwitch state OFF"
when
Item gAllKitchenLights changed to OFF
then
logInfo( "RULE KitchenAllLightsSwitch state", "gAllKitchenLights Received state OFF. State=" + gAllKitchenLights.state + ". KitchenAllLightsSwitch status is now OFF");
//only change the status of the swich when any all group lights are OFF. Don't send a command this will turn all the lights OFF!
postUpdate(AllKitchenLightsSwitch, OFF);
end
What do I use this for?
I have bunch of switch Items linked to a group (gAllLightsGswitch)
When any group members are ON, I set the status of a Switch AllKitchenLightsSwitch "All Kitchen Lights switch" (gAllLightsGswitch)
to ON.
This allows me to have a switch that can turn on all group members, or turn off all group members from a single switch.
As group members are turned on, the group switch item is correctly updated in OH3 interfaces.
I use the published MQTT state message to update the state of a button on external devices (Arduino touch screen controller) with the status of the switch.
If I Command the group switch manually by triggering the thing switch, or Item, all MQTT messages are published correctly.
Maybe there is a configuration parameter similar to isCommand=True
that changes the behaviour of State updates?
Worst case, I guess I can update the Rule to publish the required MQTT state message to the broker. The downside to this approach is the MQTT topic is then maintained in multiple locations. Once in the Thing and Item, and another copy of it manually maintained in the Rule. Not the end of the world.
YAML
UID: mqtt:topic:pi4MqttBroker:AllKitchenLightsSwitch
label: AllKitchenLightsSwitch .thing
thingTypeUID: mqtt:topic
configuration: {}
bridgeUID: mqtt:broker:pi4MqttBroker
location: Group Switches
channels:
- id: light
channelTypeUID: mqtt:switch
label: AllKitchenLightsSwitch .thing
description: null
configuration:
postCommand: true
retained: false
formatBeforePublish: "%s"
commandTopic: myhome/HMI/page0/group/KitchenAllLights/switch/state
transformationPattern: MAP:switchboard.map
stateTopic: myhome/group/KitchenAllLights/switch/command
off: "0"
on: "1"