-
Notifications
You must be signed in to change notification settings - Fork 7.7k
esp32 zigbee onLightChange unwanted results #11495
-
I am using Arduino zigbee library and ZigbeeDimmableLight profile for a simple device which requires level and on/off commands.
The device is configured as:
ZigbeeDimmableLight zbDimmableLight = ZigbeeDimmableLight(ZIGBEE_LIGHT_ENDPOINT);
And for the level/on/off devices I use the following method:
zbDimmableLight.onLightChange(setLight);
void setLight(bool state, uint8_t level) {
Serial.println("state:");
Serial.println(state);
Serial.println("level:");
Serial.println(level);
}
I use Hubitat as my Zigbee controller and I send zigbee on / off commands as:
off:
[he cmd 0x0C0F 0x0A 0x0006 0x00 {0x0A}, delay 2000]
on:
[he cmd 0x0C0F 0x0A 0x0006 0x01 {0x0A}, delay 2000]
the device id is 0A and the hub sends 00 or 01 commands to the 0x0006 cluster.
That's the only command it sends. It does not send any level command.
However, on serial monitor , I see the following output for on and off commads:
off:
state : 1
level: 0
state: 0
level: 0
on:
state : 1
level: 0
state: 1
level: 255
So the esp32 zigbee library adds unwanted commands.
When there is no level command sent from the hub, it changes the levels. And additionally it sends unwanted state commands (2 instead of 1) so I can't act according to the received command.
Why is this happening ?
@P-R-O-C-H-Y , maybe you can comment...
thanks.
Beta Was this translation helpful? Give feedback.
All reactions
This is not issue on the Zigbee library side. I have already explained.
What is does on OFF command - sending separate 2 messages:
- Send STATE
- Send LEVEL
What is does on ON command - sending separate 2 messages:
- Send STATE
- Send LEVEL
It's 2 separate messages which can be in any order. But I can't tell from the code if its final message or not. So any message have to trigger the onLightChange.
And the onLightChange
will be triggered with both parameters - state and level.
Is that understandable now? :)
Replies: 6 comments 2 replies
-
Hi @ilker-aktuna, if I get it correctly when setting to OFF you receive those 2 commands:
state : 1, level: 0 + state: 0, level: 0
when setting to ON you receive this:
state : 1, level: 0 + state: 1, level: 255
Is that correct?
Beta Was this translation helpful? Give feedback.
All reactions
-
yes, exactly.
so why is that ?
Beta Was this translation helpful? Give feedback.
All reactions
-
That's how Zigbee communication works. It's always sending level + state. And as its 2 separate messages its triggering twice the onLightChanged. So you need to check both state and level. If state is 0 keep light off whatever level is. If state is 1, check the level.
Beta Was this translation helpful? Give feedback.
All reactions
-
but I see it receives 2 x state and 2x level commands as I wrote above.
for example for the off command:
1st state : 1, level: 0
2nd state: 0, level: 0
that is 4 messages and onLightChanged triggers twice
Beta Was this translation helpful? Give feedback.
All reactions
-
So its 4 messages or 2 messages as the onLightChanged
is triggered twice?
Beta Was this translation helpful? Give feedback.
All reactions
-
I am sending only 1 message from the Hubitat controller.
onLightChanged is triggered twice.
I understand that each level command should normally trigger the onLightChanged once but with two parameters (state and level)
So normally I should expect one level and one state log (according to my code in the first post) per each command sent from hubitat.
However, I see 4 lines of log as I shared above.
So it gets triggered twice per one message from the controller.
How does that happen , and how can I distinguish between an "on" and "off" command ? Because for one "off" command I receive:
state : 1
level: 0
state: 0
level: 0
Beta Was this translation helpful? Give feedback.
All reactions
-
This is not issue on the Zigbee library side. I have already explained.
What is does on OFF command - sending separate 2 messages:
- Send STATE
- Send LEVEL
What is does on ON command - sending separate 2 messages:
- Send STATE
- Send LEVEL
It's 2 separate messages which can be in any order. But I can't tell from the code if its final message or not. So any message have to trigger the onLightChange.
And the onLightChange
will be triggered with both parameters - state and level.
Is that understandable now? :)
Beta Was this translation helpful? Give feedback.
All reactions
-
Hi,
I'm sorry ; I had some issues with the family and I didn't have a chance to come back to this thread earlier.
I understood the problem and will try a fix on the hub side.
Thanks for your answer.
Beta Was this translation helpful? Give feedback.