Mqtt -> item -> mqtt asyncronous loop with dimmer

I have things file

Thing mqtt:topic:zigbee:dimmer01 "Dimmer01 Küche"  (mqtt:broker:MQTTBroker)@"MQTT"{
    Channels:
        Type dimmer : dimmer 			"Helligkeit"	[stateTopic="zigbee2mqtt/Dimmer01_Kueche/brightness" , commandTopic="zigbee2mqtt/Dimmer01_Kueche/set", formatBeforePublish="{\"brightness\":%s}", min=0  , max=254 ]
        Type switch : PowerSwitch 		"Schalter" 		[stateTopic="zigbee2mqtt/Dimmer01_Kueche/state"     , commandTopic="zigbee2mqtt/Dimmer01_Kueche/set/state" 	   , on="ON", off="OFF"]

}

and i have items file


Group equip_ZigBeeKuecheDimmer 						"Küche Dimmer" 			(location_Kueche,things) [Equipment]
Dimmer  Zigbee_Dimmer01_Kueche_Brightness 			"Helligkeit"				  				(equip_ZigBeeKuecheDimmer)[Point] {channel="mqtt:topic:zigbee:dimmer01:dimmer"} 
Switch 	Zigbee_Dimmer01_Kueche_State				"Schalter"									(equip_ZigBeeKuecheDimmer)[Point] {channel="mqtt:topic:zigbee:dimmer01:PowerSwitch"}

if i change the item Zigbee_Dimmer01_Kueche_Brightness the wall dimmer is responding immediately and is dimming the light just fine.
item->mqtt :+1:

but in the opposite if i change with wall Dimmer mqtt sends the dimming steps to the item and the item changes. So far so good but when the item changes it sends changes back to the mqtt.
mqtt->item->mqtt :-1:

This behaves strangely - while i dim physical on the walldimmer, dimmer changes the mqtt:brightness in multiple steps and the delay between physical change and dimmer:item change lets the light flicker back to where i started.

how to not loop mqtt->item->mqtt? just only mqtt->item and good

Any advice would be gratefully appreciated

Without knowing your dimmer: Usually there should be separated MQTT topics for control and status.

Z2M means id-uk21fw09 is the Model, ID-EU20FW09 is the right one.

Z2M Dimmer Device Page

Light

This light supports the following features: state, brightness.

  • state: To control the state publish a message to topic zigbee2mqtt/FRIENDLY_NAME/set with payload {"state": "ON"}, {"state": "OFF"} or {"state": "TOGGLE"}. To read the state send a message to zigbee2mqtt/FRIENDLY_NAME/get with payload {"state": ""}.
  • brightness: To control the brightness publish a message to topic zigbee2mqtt/FRIENDLY_NAME/set with payload {"brightness": VALUE} where VALUE is a number between 0 and 254. To read the brightness send a message to zigbee2mqtt/FRIENDLY_NAME/get with payload {"brightness": ""}.

I don’t use text configuration or zigbee, but with a generic UI thing with Zwave to Mqtt this is a dimmer channel. Maybe it will help?

channels:
  - id: Office_Lights_n
    channelTypeUID: mqtt:dimmer
    label: Office Lights
    description: null
    configuration:
      commandTopic: zwave1/2/38/0/targetValue/set
      stateTopic: zwave1/2/38/0/currentValue

Also do you have MQTT Explorer set up to verify your topics are correct and watch them in action?

also the item in the UI

I think you need transformations for state topics

Type dimmer : dimmer 			"Helligkeit"	[stateTopic="zigbee2mqtt/Dimmer01_Kueche", transformationPattern="JSONPATH:$.brightness" ........

Type switch : PowerSwitch 		"Schalter" 		stateTopic="zigbee2mqtt/Dimmer01_Kueche", transformationPattern="JSONPATH:$.state"........

I use following configuration and it works well for me:

   Thing topic LED_Kueche "LED Küche" 
      {
        Channels:
            Type switch : schalter "LED Kueche Schalter"
                [
                    stateTopic="zigbee2mqtt/LED_Kueche", transformationPattern="JSONPATH:$.state",
                    commandTopic="zigbee2mqtt/LED_Kueche/set/state", on="ON", off="OFF"
                ] 
            Type dimmer : dimmer "LED Kueche Dimmer"
                [
                    stateTopic="zigbee2mqtt/LED_Kueche", transformationPattern="REGEX:(.*brightness.*)∩JS:getZigbeeDimmer.js",
                    commandTopic="zigbee2mqtt/LED_Kueche/set/brightness_percent", min=0, max=100, step=1
                ]
      }

getZigbeeDimmer.js

(function(x){
    var json = JSON.parse(x);  
    var result = (json.brightness/2.55).toFixed(0);
    return result;
})(input)

@apella12 - Yes i have Mqtt Explorer and can see topics in action, I mean i can change the dimmer from ui and vice versa

@03chris - your stateTopic is stateTopic=“zigbee2mqtt/LED_Kueche” for state(schalter) and brightness(dimmer), so changes you make at the wall dimmer are not represented in UI.

  • If you rotate the dimmer knob can you see the dimmer changing in ui? i don´t think so.
  • if you change switch to stateTopic=“zigbee2mqtt/LED_Kueche/state” and dimmer to stateTopic=“zigbee2mqtt/LED_Kueche/brightness(or brightness_percent)” you have the same effect like me.

I was wrong. If you use ‘output: attribute’ so you don’t need any transformations.

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.