Publish group update (state change) to MQTT

I have quite simple scenario, still I struggle to make it work.
I have several switches (heatings in each room) grouped in one group:

Switch Bedroom_Heating “Heating” (Bedroom, gHeating)
Switch LivingRoom_Heating “Heating” (LivingRoom, gHeating) etc…
Group:Switch:OR(ON, OFF) gHeating “Heating” (Home)

In a sitemap I can see all the switches and the master (group) switch, it behaves as expected (when at least one switch is ON, the group switch is ON). Now, I understand, that when the state of group switch is updated (because of the change of one of its members) no command is received by the group. But update is received. Now, I want to publish such change to MQTT, so I used this:

Group:Switch:OR(ON, OFF) gHeating “Heating” (Home) {mqtt=">[shrapovo:test/cidla/cmnd/kotel/power:state:*:${state}]"}

(originally I used command but that cannot work). This however, doesn’t work either. Why?

PS: I know I can e.g. publish directly from the rule using MQTT action, or I can have another Switch item for the master switch and sendCommand to it whener the group switch receives an update.

Are you wanting to just publish each of your items when they change? If so could you post all your items.

No. The scenario is that the individual switches indicate whether it is necessary to heat in particular room (and to open the valve) and the master (group) switch indicates whether the kettle/boiler should be powered on/off. So I want to publish a change of a group gHeating. If I click on the sitemap directly on the master switch, the command is sent (because the click on UI sends a command, I get that). However, if I change e.g. Bedroom_heating switch, the gHeating receives an update (I know that because I made a rule

rule kotel
when
	Item gHeating received update
then
	logInfo("Debug","Kotel received an update")
end

But such update does not trigger sending the MQTT message. Although, the docs https://www.openhab.org/addons/bindings/mqtt1/#item-configuration-for-outbound-messages says:

type - ‘state’ or ‘command’. Indicates whether the receiving of a status update or command triggers the sending of an outbound message.

So it should send it. But it doesn’t.:face_with_raised_eyebrow:

Here you have two items that are part of gHeating group but no mqtt info. Are all items communicating via mqtt and have you verified mqtt is setup correctly.?

The Group is not an item, the mqtt info should be for each item.
Example:

Switch OfficeLight "Office Light" <light> ["Lighting"] 
	{mqtt=">[pibroker:cmnd/sonoff55/POWER:command:*:default],
	<[pibroker:stat/sonoff55/POWER:state:default]" }

Number OfficeLight_Motion "Office Light Motion" <light>
	{mqtt="<[pibroker:stat/sonoff55/SENSOR:state:default]" }

Two items, one switch with mqtt="> to send a command and mqtt="< to get the state. The other item only gets info mqtt="< b/c it’s a motion sensor.

I am not sure if you are answering my questions. Let me answer yours:

  1. Yes, MQTT is setup correctly
  2. I don’t know how Group is handled, whether it is an item or not, but having my setup when I click in the Basic UI on the Group switch (which looks like this in the sitemap: Switch item=gHeating label=“Heating” ) the MQTT message is sent. If I click on one of the sub-switches and such click changes the state of the gHeating switch (i.e. all the sub-switches are OFF and I click on one of them so it goes ON, the Group switch also goes ON because it is an OR switch), no MQTT message is sent. I suspect it is because no command was received on the Group switch. But why does it not register state change (as I mentioned in the previous post, linking the docs).

https://community.openhab.org/t/design-pattern-working-with-groups-in-rules/20512

You will find a list of good examples.

Your MQTT outbound syntax is incorrect:

Group:Switch:OR(ON, OFF) gHeating “Heating” (Home) { mqtt=">[shrapovo:test/cidla/cmnd/kotel/power:state:*:default]" }

What is incorrect? What you have written is in fact the same as I had there (state:*:${state}), at least according to documentation. And I don’t see any errors in logs (and I saw some when I had incorrect syntax before). So that won’t be the problem I think …

So if you are right, do you see anything in the logs?
I have the same config on a group item and it works.
Add spaces after the { and before the}
The binding parser can be picky sometimes.

I don’t see any error in the logs, so the syntax is ok. I have changed it to your syntax so it now looks like this:

Switch    Bedroom_Heating          "Heating"        <heating>       (Bedroom, gHeating)    
Switch    LivingRoom_Heating       "Heating"        <heating>       (LivingRoom, gHeating)
Switch    KidsRoom_Heating         "Heating"        <heating>       (KidsRoom, gHeating)    
Switch    Bathroom_Heating         "Heating"        <heating>       (Bathroom, gHeating)       
Group:Switch:OR(ON, OFF) gHeating "Heating" <heating> (Home) { mqtt=">[shrapovo:test/cidla/cmnd/kotel/power:state:*:default]" }

Sitemap:

	Frame {
		Default item=Bedroom_Heating label="Bedroom"
		Default item=LivingRoom_Heating label="Living Room"
		Default item=KidsRoom_Heating label="Kids Room"
		Default item=Bathroom_Heating label="Bathroom"
		Switch item=gHeating label="Heating"
	}

rules:

rule test
when	
	Item Bedroom_Heating received update
then
	logInfo("Debug","Bedroom received update")
end

rule test2
when	
	Item Bedroom_Heating received command
then
	logInfo("Debug","Bedroom received command")
end

rule kotel
when
	Item gHeating received command
then
	logInfo("Debug","gHeating received command")
end

rule kotel2
when
	Item gHeating received update
then
	logInfo("Debug","gHeating received update")
end

I have recorded the scenario that I am talking about. See, when I click directly on Heating a command is received and MQTT message is sent. When I click on Bathroom switch, Heating is updated (so a state is changed) but no MQTT message is sent.

Where are the mqtt bindings for the items?

They are not bound yet, it doesn’t matter at the moment. Why do you guys always need to ask unnecessary questions? I have posted a problem, a discrepancy between theory (what documentation says) and praxis (what is happening in reality) and haven’t got any answer.

I want to check your mqtt config. So YES, the question is relevant.
If you don’t want help, good bye

Have you seen in the video (gif) above that the messages are received correctly?
To put you more into my situation, I have installed my first openHab setup last year. It worked, including mqtt bindings, but it was a mess. I haven’t used much of the openHab features (like groups at all) so I wanted to make it better, so I started this test environment (see the mqtt topic) and I stumbled right at the beginning. And it’s been like 15+ posts and all we discuss here is where did I make a mistake. Which is fine, in 99 % of cases the mistake is between the keyboard and a chair, I get it. So I tried to answer all your questions, now I posted a video showing that the MQTT binding is working fine, that the Group:Switch is working as a group switch and that the update is not publishing to MQTT. So please understand, that I am a little bit tired of saying the same all over again.
Would you please have a look at the video and tell me, if this is how it should behave? I sort of expect, that someone will come and say: “Well, GroupItem when receives an update from its member does not propagate it to bound channel. This a feature/bug. Deal with it, make a workaround or report the bug.” Or, that someone says: “You have incorrectly configured this and this”. That’s what is happening so far but nothing was proved to be incorrectly configured yet.

Hi,
thanks @shrap for bringing up this question. I struggled with the same in the past and did not further investigate. The problem ist not the MQTT but the questions why is the message send when the group switch is operated from the UI, but not when any of the group member switches is changed and the state of the group switch therefore changes as well.
Right?
Marcel

Exactly. First I thought that he update message is not received by the group at all, but it is as one can see from the log (in the video above). I have now tried regular item (Switch) setup like this

Switch    Test <heating> { mqtt=">[shrapovo:test/cidla/cmnd/test/power:state:*:default]" }

so essentialy the same as the group switch before. And I made a rule for the Bedroom switch:

rule Bedroom2
when	
	Item Bedroom_Heating received command
then
	logInfo("Debug","Bedroom received command")
	Test.postUpdate(receivedCommand)
end

and to check what input the Test item receives, I added

rule test
when
	Item Test received command
then
	logInfo("Debug","Test received command")
end

rule test2
when
	Item Test received update
then
	logInfo("Debug","Test received update")
end

And surprisingly (or maybe not), it works as expected, i.e. when I click on the Bedroom switch, an update (not command) is sent to Test switch and that update is published to MQTT. So the problem is when the updated item is GroupItem, then the MQTT outbound message is not sent. From my point of view it is a bug (or at least it needs to be documented).

1 Like

Did you file a bug report about this?

No, I did not. Should I? Can you point me to where could I do that?