MQTT - multiple stateTopic's & transformationPatterns

I’ve a BlitzWolf socket in use which measures the power usage.

I created a thing to get my current usage:

Type number : current "Current" [ stateTopic="tele/blitzwolf1/SENSOR", transformationPattern="JSONPATH:$.ENERGY.Current" ]

This is working fine via the telemetry period (300s by default)

If I want to receive this info on demand I need to send this MQTT command cmnd/blitzwolf1/status 8, I created the same Thing but with another StateTopic & TransformationPattern:

Type number : current "Current" [ stateTopic="stat/blitzwolf1/STATUS8", transformationPattern="JSONPATH:$.StatusSNS.ENERGY.Current" ]

This is also working, but both lines are not working together.
Is there maybe another way to integrate this into one thing? I don’t want to create all things twice…

You can’t put two stateTopic in one channel
You still have ONE thing but two channels:

Type number : currentChannel1 "Current" [ stateTopic="tele/blitzwolf1/SENSOR", transformationPattern="JSONPATH:$.ENERGY.Current" ]
Type number : currentChannel2 "Current" [ stateTopic="stat/blitzwolf1/STATUS8", transformationPattern="JSONPATH:$.StatusSNS.ENERGY.Current" ]

And your item:

Number Current { channel="mqtt:topic:xxxx:currentChannel1", channel="mqtt:topic:xxxx:currentChannel2" }
1 Like

thanks for the reply

if I only can use one item, I’m happy too.
Will try it this evening.

The item is using both channels and show the last status? Right?

So I use it for Tasmota devices, too?
Normally there is a state/command topic per switch. Between some config changed the status is unknown. Intervall controlled a status will be sent by Tasmota device for each switch.

So I can use the 2nd topic to update the current item, too?

1 Like

Yes, the 2nd topic can be used to update the status on demand

I’ve made some tests…

THING

Thing mqtt:topic:mymqtt:sonoff-ABCDEFG "ElectroDragon Relay Board" (mqtt:broker:mymqtt) @ "MQTT" {
	Channels:
		Type switch : sw1 "Switch 1" [
			stateTopic="tasmota/sonoff-ABCDEFG/stat/POWER1",
			commandTopic="tasmota/sonoff-ABCDEFG/cmnd/POWER1",
			on="ON",
			off="OFF"
		]
		Type switch : sw2 "Switch 2" [
			stateTopic="tasmota/sonoff-ABCDEFG/stat/POWER2",
			commandTopic="tasmota/sonoff-ABCDEFG/cmnd/POWER2",
			on="ON",
			off="OFF"
		]
		Type switch : sw1_stat "Status Backup Switch 1" [
			stateTopic="tasmota/sonoff-ABCDEFG/stat/STATUS11",
			transformationPattern="JSONPATH:$.StatusSTS.POWER1",
			on="ON",
			off="OFF"
		]
		Type switch : sw2_stat "Status Backup Switch 2" [
			stateTopic="tasmota/sonoff-ABCDEFG/stat/STATUS11",
			transformationPattern="JSONPATH:$.StatusSTS.POWER2",
			on="ON",
			off="OFF"
		]
		Type string : version [
			stateTopic="tasmota/sonoff-ABCDEFG/stat/STATUS2",
			transformationPattern="JSONPATH:$.StatusFWR.Version"
		]
}

ITEM

// Test Board ElectroDragon
Switch mqtt_sonoff_ABCDEFG_sw1 "ED Switch 1 []" <switch> { channel="mqtt:topic:mymqtt:sonoff-ABCDEFG:sw1" }
Switch mqtt_sonoff_ABCDEFG_sw2 "ED Switch 2 []" <switch> { channel="mqtt:topic:mymqtt:sonoff-ABCDEFG:sw2" }

Switch mqtt_sonoff_ABCDEFG_sw1_stat "ED Switch 1 []" <switch> { channel="mqtt:topic:mymqtt:sonoff-ABCDEFG:sw1_stat" }
Switch mqtt_sonoff_ABCDEFG_sw2_stat "ED Switch 2 []" <switch> { channel="mqtt:topic:mymqtt:sonoff-ABCDEFG:sw2_stat" }

RULE

rule "update tasmota EletroDragon DEMO"
when
	Item mqtt_sonoff_ABCDEFG_sw1 changed or
	Item mqtt_sonoff_ABCDEFG_sw2 changed
then
	
	val actions = getActions("mqtt","mqtt:broker:mymqtt")
	actions.publishMQTT("tasmota/sonoff-ABCDEFG/cmnd/STATUS","11")

end

LOG - Buttons pushed manually at the device.

2019-10-06 15:31:50.367 [vent.ItemStateChangedEvent] - mqtt_sonoff_ABCDEFG_sw1 changed from OFF to ON
2019-10-06 15:31:50.415 [vent.ItemStateChangedEvent] - mqtt_sonoff_ABCDEFG_sw1_stat changed from OFF to ON

2019-10-06 15:31:51.815 [vent.ItemStateChangedEvent] - mqtt_sonoff_ABCDEFG_sw2 changed from OFF to ON
2019-10-06 15:31:51.878 [vent.ItemStateChangedEvent] - mqtt_sonoff_ABCDEFG_sw2_stat changed from OFF to ON

2019-10-06 15:31:53.298 [vent.ItemStateChangedEvent] - mqtt_sonoff_ABCDEFG_sw1 changed from ON to OFF
2019-10-06 15:31:53.348 [vent.ItemStateChangedEvent] - mqtt_sonoff_ABCDEFG_sw1_stat changed from ON to OFF

2019-10-06 15:31:54.557 [vent.ItemStateChangedEvent] - mqtt_sonoff_ABCDEFG_sw2 changed from ON to OFF
2019-10-06 15:31:54.645 [vent.ItemStateChangedEvent] - mqtt_sonoff_ABCDEFG_sw2_stat changed from ON to OFF

Until here everything looks ok.

Using this item code it looks ok. But without the status update

// Test Board ElectroDragon
Switch mqtt_sonoff_ABCDEFG_sw1 "ED Switch 1 []" <switch> { channel="mqtt:topic:mymqtt:sonoff-ABCDEFG:sw1" }
Switch mqtt_sonoff_ABCDEFG_sw2 "ED Switch 2 []" <switch> { channel="mqtt:topic:mymqtt:sonoff-ABCDEFG:sw2" }

Using the 2nd channel to get status updates the item within sitemap isn’t showing the real world :slight_smile:

Switch mqtt_sonoff_ABCDEFG_sw1 "ED Switch 1 []" <switch> { channel="mqtt:topic:mymqtt:sonoff-ABCDEFG:sw1", channel="mqtt:topic:mymqtt:sonoff-ABCDEFG:sw1_stat" }
Switch mqtt_sonoff_ABCDEFG_sw2 "ED Switch 2 []" <switch> { channel="mqtt:topic:mymqtt:sonoff-ABCDEFG:sw2", channel="mqtt:topic:mymqtt:sonoff-ABCDEFG:sw2_stat" }

In the log you can see that “sw1” switch from OFF to ON->OFF->ON … This looks very strange.

2019-10-06 19:25:28.096 [ome.event.ItemCommandEvent] - Item 'mqtt_sonoff_33E958_sw1' received command ON
2019-10-06 19:25:28.105 [nt.ItemStatePredictedEvent] - mqtt_sonoff_33E958_sw1 predicted to become ON
2019-10-06 19:25:28.124 [vent.ItemStateChangedEvent] - mqtt_sonoff_33E958_sw1 changed from OFF to ON
2019-10-06 19:25:28.138 [vent.ItemStateChangedEvent] - mqtt_sonoff_33E958_sw1 changed from ON to OFF
2019-10-06 19:25:28.163 [vent.ItemStateChangedEvent] - mqtt_sonoff_33E958_sw1 changed from OFF to ON
2019-10-06 19:25:28.218 [vent.ItemStateChangedEvent] - mqtt_sonoff_33E958_sw1_stat changed from OFF to ON

I just want to have a MQTT topic which shows the right status of a switch.

Any suggestions?

A switch and a relay are two very different things in Tasmota.
What exactly are you trying to detect?
Why are you using STATUS11? Not needed, remove these two channels

Within Sitemap the correct switch state isn’t shown from time to time. It shows off, even the hardware is on or the other way around.

“STATUS11” shows me all relay states of the board.
My plan was to use this to fix the Sitemap.

What do you mean exactly?

A switch is an input
A relay is an output

Again, what are you trying to read?

This is interesting.

2019-10-06 19:25:28.096 [ome.event.ItemCommandEvent] - Item 'mqtt_sonoff_33E958_sw1' received command ON
2019-10-06 19:25:28.105 [nt.ItemStatePredictedEvent] - mqtt_sonoff_33E958_sw1 predicted to become ON
2019-10-06 19:25:28.124 [vent.ItemStateChangedEvent] - mqtt_sonoff_33E958_sw1 changed from OFF to ON

This part is ordinary enough; you send a command, then autoupdate makes a prediction of the resulting state, and then applies the update.

2019-10-06 19:25:28.138 [vent.ItemStateChangedEvent] - mqtt_sonoff_33E958_sw1 changed from ON to OFF
2019-10-06 19:25:28.163 [vent.ItemStateChangedEvent] - mqtt_sonoff_33E958_sw1 changed from OFF to ON
2019-10-06 19:25:28.218 [vent.ItemStateChangedEvent] - mqtt_sonoff_33E958_sw1_stat changed from OFF to ON

Next line is curious - within a few milliseconds, an unexpected “something” changes it back to the old state.
A longer time after that in turn, another “something” changes it again to the expected result. Probably an actual MQTT message from the device.

Here’s a guess - you are fighting the binding. When autoupdate makes the ON update, that update event gets passed to both binding channels. One of those channels recently dealt with a command, one didn’t.
One or both channels I think re-asserts the “old” state that it is keeping a copy of.

I know MQTT binding is a little unusual in this area.
Most bindings will ignore “somebody else” (a rule, another channel) changing a linked Item state until they get some new incoming data event from the device.
People do have troubles with MQTT binding overwriting restore-on-startup states unexpectedly. This has shown that MQTT channels can issue state updates in the absence of an MQTT message. Different circumstances, but I suspect similar enough.

You can certainly make it “look better” by disabling autoupdate on the Item, to stop the to-and-fro.
That may or may not leave an acceptable delay before a “real” MQTT response updates your Item state.

I’ve tried something but independent what I do sitemap is showing from time to time an incorrect status.

I’ve also set PowerRetain for switch status on the relay board. In cases I need to modify the config file and to get the current real state.

Using /tele/STATE from tasmota as 2nd channel with autoupdate the button is partial not set correctly to status ON/OFF.

Using a plain switch element without autoupdate the button within the sitemap look ok, but the icon not. Button=off, Icon=on. Maybe this happens also using 2-ch and autoupdate.

Using a plain switch item with autoupdate the switch is toggle back to OFF when I switch from OFF to ON. Even MQTT shows “ON” and tele/STATE, too.

Any suggestions how I get the real status in sitemap each time?

Using “showlogs” at CLI the status looks ok. with and without autoupdate. Unfortunately the sitemap looks wrong. And this is what a “user” will see and should trust.

Refreshing the sitemap webpage the correct status is shown.

You are having troubles with tasmota, not openHAB
Read:

Maybe there is an issue with Tasmota, too. But I think there is an update issue for sitemap in OH.

Checking logs for item state the item is correct in OH Logs but not in sitemap. Using some other MQTT states was a try to “fix” this backward, without success.

I’ll do some more checks …

Hi, someone find a solution for this? I ran in same issue. I partially resolved using persistence for Tasmota item, but I don’t like it so much.

Thanks
Marco

After browsing around in the forum it seems that this is quite a widespread issue
Please post an issue on gitHub if there isn’t one already