Page 1 of 1

Xiaomi Cube buttonevent

Posted: Tuesday 04 August 2020 19:40
by kispalsz
Hi!

I want to fit dzVents rules to rotate the cube (90 degrees from one side to the other), it would be important to know in the rule from which side the cube turns to which side.
This is listed in the log.

'buttonevent': 2001,

I use Conbee 2 stick with deconz.
https://github.com/dresden-elektronik/d ... issues/138

Here is the buttonevent codes:
x000 for push, so 1000, 2000, 3000, 4000, 5000, 6000;
x00x for double tap, so 1001, 2002, 3003, 4004, 5005, 6006;
x00o for 180° flip (where o = 7 - x), so 1006, 2005, 3004, 4003, 5002, 6001;
x00y for 90° flip (where y ≠ x and y ≠ 7 - x), so 1002, 1003, 1004, 1005, 2001, 2003, 2004, 2006, 3001, 3002, 3005, 3006, 4001, 4002, 4005, 4006, 5001, 5003, 5004, 5006, 6002, 6003, 6004, 6005;
7007 for shake;
7008 for drop (EDITED);
7000 for wakeup (the cube sends raw value 2 when I just tap it after a while).


Code: Select all

2020-08-04 19:20:09.830 (deCONZ-Zigbee) ### WebSocket Data : {'e': 'changed', 'id': '20', 'r': 'sensors', 'state': {'buttonevent': 2001, 'gesture': 3, 'lastupdated': '2020-08-04T17:20:09.814'}, 't': 'event', 'uniqueid': '00:15:8d:00:04:2f:1f:9f-02-0012'}
2020-08-04 19:20:09.831 (deCONZ-Zigbee) ### Update device (deCONZ-Zigbee - lumi.sensor_cube.aqgl01 20) : {'nValue': 40, 'sValue': '40'}
2020-08-04 19:20:09.831 (deCONZ-Zigbee - lumi.sensor_cube.aqgl01 20) Updating device from 0:'Off' to have values 40:'40'.
2020-08-04 19:20:10.127 (deCONZ-Zigbee) Pushing 'onCommandCallback' on to queue
2020-08-04 19:20:10.172 (deCONZ-Zigbee) Processing 'onCommandCallback' message
2020-08-04 19:20:10.173 (deCONZ-Zigbee) Calling message handler 'onCommand'.
2020-08-04 19:20:10.173 (deCONZ-Zigbee) onCommand called for Unit 18: Parameter 'Set Level', Level: 100, Hue:
2020-08-04 19:20:10.173 (deCONZ-Zigbee) Send Command /api/C94AB24840/lights/5/state with {'on': True, 'bri': 254} (0 in buffer)
2020-08-04 19:20:10.174 (deCONZ-Zigbee) Making Request : http://127.0.0.1:8088/api/C94AB24840/lights/5/state with params {'on': True, 'bri': 254}
2020-08-04 19:20:10.196 (deCONZ-Zigbee) Request Return : [{"success":{"/lights/5/state/on":true}},{"success":{"/lights/5/state/bri":254}}]
2020-08-04 19:20:10.196 (deCONZ-Zigbee) Classic Data : [{'success': {'/lights/5/state/on': True}}, {'success': {'/lights/5/state/bri': 254}}]
2020-08-04 19:20:10.098 Status: dzVents: Info: Handling events for: "deCONZ-Zigbee - lumi.sensor_cube.aqgl01 20", value: "90°"
In the websocket section, "buttonevent" specifies the direction and side of rotation.

How can this be applied in dzvents ( buttonevent)?

Re: Xiaomi Cube buttonevent

Posted: Tuesday 04 August 2020 22:19
by waaren
kispalsz wrote: Tuesday 04 August 2020 19:40 I want to fit dzVents rules to rotate the cube (90 degrees from one side to the other), it would be important to know in the rule from which side the cube turns to which side.

In the websocket section, "buttonevent" specifies the direction and side of rotation.
How can this be applied in dzvents ( buttonevent)?
dzVents works with the values it receive from the domoticz eventSystem (these can be found in <domoticz dir>/scripts/dzVents/domoticzData.lua when you activate log Level Debug for dzVents in the settings). If other values are required they have to be send to dzVents via the customEvents mechanism or retrieved by dzVents using a openURL() call.

Can the deConz send the required information via one of these routes to dzVents ?

Re: Xiaomi Cube buttonevent

Posted: Tuesday 04 August 2020 23:56
by kispalsz
Hi!

I If I turn on dzvents debug, that's all I see.

I have a rule with that name : "E-Aqara-Cube" , but it just interprets rotation. No direction.
IF I understand correctly what you wrote the websocket parts can't catch the dzvents.

This:

Code: Select all

### WebSocket Data : {'e': 'changed', 'id': '20', 'r': 'sensors', 'state': {'buttonevent': 4002, 'gesture': 3, 'lastupdated': '2020-08-04T21:40:12.296'}, 't': 'event', 'uniqueid': '00:15:8d:00:04:2f:1f:9f-02-0012'}
Then you should pass this value to the event system. And this should be implemented and modified in the deconz plugin?

The debug log:

Code: Select all

2020-08-04 23:40:12.299 (deCONZ-Zigbee) Pushing 'ReadEvent' on to queue
2020-08-04 23:40:12.306 (deCONZ-Zigbee) Processing 'ReadEvent' message
2020-08-04 23:40:12.306 (deCONZ-Zigbee) Received 181 bytes of data
2020-08-04 23:40:12.307 (deCONZ-Zigbee) 81 7e 00 b1 7b 22 65 22 3a 22 63 68 61 6e 67 65 64 22 2c 22 �.ѻ"e":"changed","
2020-08-04 23:40:12.307 (deCONZ-Zigbee) 69 64 22 3a 22 32 30 22 2c 22 72 22 3a 22 73 65 6e 73 6f 72 id":"20","r":"sensor
2020-08-04 23:40:12.307 (deCONZ-Zigbee) 73 22 2c 22 73 74 61 74 65 22 3a 7b 22 62 75 74 74 6f 6e 65 s","state":{"buttone
2020-08-04 23:40:12.307 (deCONZ-Zigbee) 76 65 6e 74 22 3a 34 30 30 32 2c 22 67 65 73 74 75 72 65 22 vent":4002,"gesture"
2020-08-04 23:40:12.307 (deCONZ-Zigbee) 3a 33 2c 22 6c 61 73 74 75 70 64 61 74 65 64 22 3a 22 32 30 :3,"lastupdated":"20
2020-08-04 23:40:12.307 (deCONZ-Zigbee) 32 30 2d 30 38 2d 30 34 54 32 31 3a 34 30 3a 31 32 2e 32 39 20-08-04T21:40:12.29
2020-08-04 23:40:12.307 (deCONZ-Zigbee) 36 22 7d 2c 22 74 22 3a 22 65 76 65 6e 74 22 2c 22 75 6e 69 6"},"t":"event","uni
2020-08-04 23:40:12.307 (deCONZ-Zigbee) 71 75 65 69 64 22 3a 22 30 30 3a 31 35 3a 38 64 3a 30 30 3a queid":"00:15:8d:00:
2020-08-04 23:40:12.307 (deCONZ-Zigbee) 30 34 3a 32 66 3a 31 66 3a 39 66 2d 30 32 2d 30 30 31 32 22 04:2f:1f:9f-02-0012"
2020-08-04 23:40:12.307 (deCONZ-Zigbee) 7d .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. }
2020-08-04 23:40:12.307 (deCONZ-Zigbee) Pushing 'onMessageCallback' on to queue
2020-08-04 23:40:12.307 (deCONZ-Zigbee) Processing 'onMessageCallback' message
2020-08-04 23:40:12.308 (deCONZ-Zigbee) Calling message handler 'onMessage'.
2020-08-04 23:40:12.308 (deCONZ-Zigbee) onMessage called
2020-08-04 23:40:12.308 (deCONZ-Zigbee) ### WebSocket Data : {'e': 'changed', 'id': '20', 'r': 'sensors', 'state': {'buttonevent': 4002, 'gesture': 3, 'lastupdated': '2020-08-04T21:40:12.296'}, 't': 'event', 'uniqueid': '00:15:8d:00:04:2f:1f:9f-02-0012'}
2020-08-04 23:40:12.309 (deCONZ-Zigbee) ### Update device (deCONZ-Zigbee - lumi.sensor_cube.aqgl01 20) : {'nValue': 40, 'sValue': '40'}
2020-08-04 23:40:12.310 (deCONZ-Zigbee - lumi.sensor_cube.aqgl01 20) Updating device from 0:'Off' to have values 40:'40'.
2020-08-04 23:40:12.850 (deCONZ-Zigbee) Pushing 'onCommandCallback' on to queue
2020-08-04 23:40:12.852 (deCONZ-Zigbee) Processing 'onCommandCallback' message
2020-08-04 23:40:12.852 (deCONZ-Zigbee) Calling message handler 'onCommand'.
2020-08-04 23:40:12.852 (deCONZ-Zigbee) onCommand called for Unit 18: Parameter 'Set Level', Level: 100, Hue:
2020-08-04 23:40:12.853 (deCONZ-Zigbee) Send Command /api/C94AB24840/lights/5/state with {'on': True, 'bri': 254} (0 in buffer)
2020-08-04 23:40:12.853 (deCONZ-Zigbee) Making Request : http://127.0.0.1:8088/api/C94AB24840/lights/5/state with params {'on': True, 'bri': 254}
2020-08-04 23:40:12.876 (deCONZ-Zigbee) Request Return : [{"success":{"/lights/5/state/on":true}},{"success":{"/lights/5/state/bri":254}}]
2020-08-04 23:40:12.877 (deCONZ-Zigbee) Classic Data : [{'success': {'/lights/5/state/on': True}}, {'success': {'/lights/5/state/bri': 254}}]
2020-08-04 23:40:12.447 Status: dzVents: Debug: Dumping domoticz data to /home/pi/domoticz/scripts/dzVents/domoticzData.lua
2020-08-04 23:40:12.713 Status: dzVents: Debug: Processing device-adapter for deCONZ-Zigbee - lumi.sensor_cube.aqgl01 20: Switch device adapter
2020-08-04 23:40:12.715 Status: dzVents: Debug: dzVents version: 3.0.2
2020-08-04 23:40:12.715 Status: dzVents: Debug: Event triggers:
2020-08-04 23:40:12.715 Status: dzVents: Debug: - Device: deCONZ-Zigbee - lumi.sensor_cube.aqgl01 20
2020-08-04 23:40:12.819 Status: dzVents: Info: Handling events for: "deCONZ-Zigbee - lumi.sensor_cube.aqgl01 20", value: "90°"
2020-08-04 23:40:12.819 Status: dzVents: Info: ------ Start internal script: E-Aqara-Cube: Device: "deCONZ-Zigbee - lumi.sensor_cube.aqgl01 20 (deCONZ-Zigbee)", Index: 365
2020-08-04 23:40:12.822 Status: dzVents: Debug: Processing device-adapter for deCONZ-Zigbee - E-N-Vilagitas1: RGB(W) device adapter
2020-08-04 23:40:12.823 Status: dzVents: Debug: Processing device-adapter for deCONZ-Zigbee - E-N-Vilagitas1: Switch device adapter
2020-08-04 23:40:12.823 Status: dzVents: Debug: Constructed timed-command: Set Level 100
2020-08-04 23:40:12.824 Status: dzVents: Info: ------ Finished E-Aqara-Cube
2020-08-04 23:40:12.824 Status: dzVents: Debug: Commands sent to Domoticz:
2020-08-04 23:40:12.824 Status: dzVents: Debug: - deCONZ-Zigbee - E-N-Vilagitas1 = Set Level 100
2020-08-04 23:40:12.825 Status: dzVents: Debug: =====================================================
2020-08-04 23:40:13.423 Status: dzVents: Debug: Dumping domoticz data to /home/pi/domoticz/scripts/dzVents/domoticzData.lua
2020-08-04 23:40:14.948 (deCONZ-Zigbee) Pushing 'onHeartbeatCallback' on to queue
2020-08-04 23:40:14.989 (deCONZ-Zigbee) Processing 'onHeartbeatCallback' message
2020-08-04 23:40:14.989 (deCONZ-Zigbee) Calling message handler 'onHeartbeat'.
2020-08-04 23:40:14.989 (deCONZ-Zigbee) onHeartbeat called
2020-08-04 23:40:14.990 (deCONZ-Zigbee) ### Update device (deCONZ-Zigbee - lumi.sensor_cube.aqgl01 20) : {'nValue': 0, 'sValue': 'Off'}
2020-08-04 23:40:14.990 (deCONZ-Zigbee - lumi.sensor_cube.aqgl01 20) Updating device from 40:'40' to have values 0:'Off'.

Re: Xiaomi Cube buttonevent

Posted: Wednesday 05 August 2020 0:39
by waaren
kispalsz wrote: Tuesday 04 August 2020 23:56 I If I turn on dzvents debug, that's all I see.
What is in /home/pi/domoticz/scripts/dzVents/domoticzData.lua for device lumi.sensor_cube.aqgl01 20 when you just flipped the cube ?

Re: Xiaomi Cube buttonevent

Posted: Wednesday 05 August 2020 9:12
by kispalsz
The cube has 2 devices, an analog rotation value, and a selector.

Code: Select all

        [145] = {
                ["switchType"] = "On/Off";
                ["timedOut"] = false;
                ["id"] = 364;
                ["deviceType"] = "General";
                ["changed"] = false;
                ["subType"] = "Custom Sensor";
                ["batteryLevel"] = 100;
                ["baseType"] = "device";
                ["switchTypeValue"] = 0;
                ["lastUpdate"] = "2020-08-05 00:33:17";
                ["lastLevel"] = 0;
                ["description"] = "";
                ["data"] = {
                        ["hardwareName"] = "deCONZ-Zigbee";
                        ["sensorType"] = 1;
                        ["_nValue"] = 0;
                        ["hardwareID"] = 4;
                        ["protected"] = false;
                        ["unit"] = 46;
                        ["hardwareTypeValue"] = 94;
                        ["sensorUnit"] = "degree";
                        ["icon"] = "Custom";
                        ["hardwareType"] = "deCONZ plugin";
                        ["_state"] = "Off";
                };
                ["signalLevel"] = 12;
                ["name"] = "deCONZ-Zigbee - Mi Magic Cube";
                ["deviceID"] = "00:15:8d:00:04:2f:1f:9f-03-000c";
                ["rawData"] = {
                        [1] = "Off";
                };
                ["protected"] = false;
        };
        [146] = {
                ["switchType"] = "Selector";
                ["timedOut"] = false;
                ["id"] = 365;
                ["deviceType"] = "Light/Switch";
                ["changed"] = true;
                ["subType"] = "Selector Switch";
                ["batteryLevel"] = 100;
                ["baseType"] = "device";
                ["switchTypeValue"] = 18;
                ["lastUpdate"] = "2020-08-05 09:08:06";
                ["lastLevel"] = 0;
                ["description"] = "";
                ["data"] = {
                        ["hardwareName"] = "deCONZ-Zigbee";
                        ["usedByCamera"] = false;
                        ["levelOffHidden"] = true;
                        ["levelActions"] = "||||||||";
                        ["_nValue"] = 40;
                        ["hardwareID"] = 4;
                        ["protected"] = false;
                        ["unit"] = 47;
                        ["levelNames"] = "Off|Shak|Wake|Drop|90°|180°|Push|Tap";
                        ["maxDimLevel"] = 100;
                        ["levelVal"] = 40;
                        ["icon"] = "Light";
                        ["hardwareTypeValue"] = 94;
                        ["hardwareType"] = "deCONZ plugin";
                        ["_state"] = "90°";
                };
                ["signalLevel"] = 12;
                ["name"] = "deCONZ-Zigbee - lumi.sensor_cube.aqgl01 20";
                ["deviceID"] = "00:15:8d:00:04:2f:1f:9f-02-0012";
                ["rawData"] = {
                        [1] = "40";
                };
                ["protected"] = false;
        };

Re: Xiaomi Cube buttonevent

Posted: Wednesday 05 August 2020 10:39
by waaren
kispalsz wrote: Wednesday 05 August 2020 9:12 The cube has 2 devices, an analog rotation value, and a selector.
Seems like the conBee sends to both the nValue and the sValue to set the level of the selector but only sValue is used in domoticz for this.

If conBee would only send the required level to sValue and the direction integer to nValue then dzVents could work with that.

sValue: required level: '0','10','20','30','40','50','60'
nValue: direction integer: 1000, 2000, 3000, 4000, 5000, 6000, 1001, 2002, 3003, 4004, 5005, 6006, 1006, 2005, 3004, 4003, 5002, 6001, 1002, 1003, 1004, 1005, 2001, 2003, 2004, 2006, 3001, 3002, 3005, 3006, 4001, 4002, 4005, 4006, 5001, 5003, 5004, 5006, 6002, 6003, 6004, 6005, 7007, 7008, 7000

Re: Xiaomi Cube buttonevent

Posted: Thursday 06 August 2020 18:07
by Thorgal789
Ha nice, good idea @waaren , I haven't tried that. We are not forced to use 10 in nvalue and "10" in svalue in same time ?

Re: Xiaomi Cube buttonevent

Posted: Thursday 06 August 2020 18:34
by waaren
Thorgal789 wrote:We are not forced to use 10 in nvalue and "10" in svalue in same time ?
Indeed. Domoticz only use the svalue to determine the level for a selector type device.





Re: Xiaomi Cube buttonevent

Posted: Thursday 06 August 2020 18:55
by Thorgal789
waaren wrote: Thursday 06 August 2020 18:34 Indeed. Domoticz only use the svalue to determine the level for a selector type device.

Ok so first, good new, it works ^^
But i have problem to retreive the value using LUA (not using dz)
print (devicechanged['deCONZ - Switch'])
print (otherdevices_svalues['deCONZ - Switch'])
Give me "40" and "wake", I can't have the nvalue, and I don't see it in the JSON.

Re: Xiaomi Cube buttonevent

Posted: Thursday 06 August 2020 19:30
by waaren
Thorgal789 wrote: Thursday 06 August 2020 18:55 Ok so first, good new, it works ^^
But i have problem to retreive the value using LUA (not using dz)
print (devicechanged['deCONZ - Switch'])
print (otherdevices_svalues['deCONZ - Switch'])
Give me "40" and "wake", I can't have the nvalue
update using

Code: Select all

http://<domoticz IP: domoticz POrt>/json.htm?type=command&nvalue=2001&idx=<deconz idx>&param=udevice&svalue=30
Lua script

Code: Select all

commandArray = {}

-- loop through all the changed devices
for deviceName,deviceValue in pairs(devicechanged) do
        print ("Device based event fired on '"..deviceName.."', value '"..tostring(deviceValue).."'");
        print('nValue:: ' .. devicechanged_ext.nvalue)
      end

return commandArray
log from Lua code

Code: Select all

2020-08-06 19:25:04.814  Status: LUA: Device based event fired on 'deconz', value 'Level3'
2020-08-06 19:25:04.814  Status: LUA: nValue:: 2001

dzVents script:

Code: Select all

return {
	on = {
		devices = {
			'deconz',
		}
	},
	
	logging = 
	
	{
        level = domoticz.LOG_DEBUG,    
        marker = 'deconz',
    },

	execute = function(dz, item)
		dz.log('Device ' .. item.name .. ' sValue: ' .. item.sValue .. ', nValue: ' .. item.nValue, dz.LOG_DEBUG)
	end
}
log from dzVents code

Code: Select all

2020-08-06 19:25:04.809  Status: dzVents: Info: Handling events for: "deconz", value: "Level3"
2020-08-06 19:25:04.809  Status: dzVents: Info: deconz: ------ Start internal script: Script #3: Device: "deconz (Virtual)", Index: 453
2020-08-06 19:25:04.809  Status: dzVents: Debug: deconz: Device deconz sValue: Level3, nValue: 2001
2020-08-06 19:25:04.810  Status: dzVents: Info: deconz: ------ Finished Script #3


Re: Xiaomi Cube buttonevent  [Solved]

Posted: Thursday 06 August 2020 20:03
by Thorgal789
Thx a lot ^^. So usefull. I will update the plugin