Page 1 of 1

Xiaomi Cube rotate

Posted: Friday 04 October 2019 19:31
by czasas
Hello I have some logs from Xiaomi Cube like this:

2019-10-04 19:20:12.562 (Conbee) onMessage called
2019-10-04 19:20:12.562 (Conbee) ### WebSocket Data : {'state': {'buttonevent': 7000, 'gesture': 0, 'lastupdated': '2019-10-04T17:20:12'}, 'r': 'sensors', 'uniqueid': '00:15:8d:00:02:9b:f6:2a-02-0012', 'e': 'changed', 'id': '3', 't': 'event'}
2019-10-04 19:20:12.563 (Conbee) ### Update device (Cube) : {'sValue': '20', 'nValue': 20}
2019-10-04 19:20:12.918 (Conbee) onHeartbeat called
2019-10-04 19:20:12.918 (Conbee) ### Update device (Cube) : {'sValue': 'Off', 'nValue': 0}
2019-10-04 19:20:13.074 (Conbee) onMessage called
2019-10-04 19:20:13.074 (Conbee) ### WebSocket Data : {'state': {'buttonevent': -4782, 'gesture': 8, 'lastupdated': '2019-10-04T17:20:13'}, 'r': 'sensors', 'uniqueid': '00:15:8d:00:02:9b:f6:2a-03-000c', 'e': 'changed', 'id': '4', 't': 'event'}
2019-10-04 19:20:13.074 (Conbee) ### Update device (Conbee - lumi.sensor_cube.aqgl01 4) : {'sValue': '-4782', 'nValue': -4782}
2019-10-04 19:20:22.902 (Conbee) onHeartbeat called
2019-10-04 19:20:22.902 (Conbee) ### Update device (Conbee - lumi.sensor_cube.aqgl01 4) : {'sValue': 'Off', 'nValue': 0}


And variable:

local Cube_angle = 'Cube'

how to assign to variable angle from logs? I know that is nValue, or {'state': {'buttonevent': -4782. but have to aby idea how to her this.

It should be somethink like that :
(Cube_angle).stare.buttonevent ??

Re: Xiaomi Cube rotate

Posted: Friday 04 October 2019 20:06
by Thorgal789
The cube have 2 device
"cube" for state (numeric/bool value), device id = 3
"Conbee - lumi.sensor_cube.aqgl01 4" for angle, device id = 4

So if you want to retreive angle value, try the second device.
To retreive value are you using LUA or Dzevent ? And you are right, just ask for nvalue.

Code: Select all

if devicechanged['deCONZ - Angle Cube Xioami'] then
    print ( 'Debug : '..devicechanged['deCONZ - Angle Cube Xioami'] )
end

Re: Xiaomi Cube rotate

Posted: Friday 04 October 2019 20:17
by waaren
czasas wrote: Friday 04 October 2019 19:31 how to assign to variable angle from logs? I know that is nValue, or {'state': {'buttonevent': -4782. but have to aby idea how to her this.
Assuming the names of your cube devices start with XCube you could use something like the below script to get the state(s)

Code: Select all

return {
    on = { devices = { 'XCube*' } },

    execute = function(dz, item )
        dz.log(item.name .. " state: " .. item.state,dz.LOG_FORCE)
        dz.log(item.name .. " nValue: ".. item.nValue,dz.LOG_FORCE)
    end
}

Re: Xiaomi Cube rotate

Posted: Friday 04 October 2019 20:48
by czasas
So if my device in domoticz is cube_device
This should be :

Code: Select all

return {
    on = { devices = { 'cube_device' } },

    execute = function(domoticz, cube_device )
        domoticz.log(cube_device.name .. " state: " .. cube_device.state,domoticz.LOG_FORCE)
        domoticz.log(cube_device.name .. " nValue: ".. cube_device.nValue,domoticz.LOG_FORCE)
    end
}
Its correct ?

Re: Xiaomi Cube rotate

Posted: Friday 04 October 2019 21:05
by waaren
czasas wrote: Friday 04 October 2019 20:48 So if my device in domoticz is cube_device
Its correct ?
Yes, but if you use

Code: Select all

return {
    on = { devices = { 'cube*' } },

    execute = function(dz, item )
        dz.log(item.name .. " state: " .. item.state,dz.LOG_FORCE)
        dz.log(item.name .. " nValue: ".. item.nValue,dz.LOG_FORCE)
    end
}
The code will do the same and is more generic so you can use it with only one small change for many devices.

Re: Xiaomi Cube rotate

Posted: Friday 04 October 2019 21:23
by Thorgal789
Ha yep, I m just seeing we are in dzEvent section ^^, so my question was stupid.

Re: Xiaomi Cube rotate

Posted: Friday 04 October 2019 21:39
by czasas
I put this script and it doesnt return anything in domoticz log

Re: Xiaomi Cube rotate

Posted: Friday 04 October 2019 21:49
by waaren
czasas wrote: Friday 04 October 2019 21:39 I put this script and it doesnt return anything in domoticz log
If the device is defined in domoticz and the state or nValue is updated in a standard way the script should react to a movement of the cube.
Change cube* to * in the script to catch any device.

Re: Xiaomi Cube rotate

Posted: Friday 04 October 2019 22:12
by czasas
I put * instead device name and it seems like script is looking for nValue for all devices in utility tab, but I dont see any Cube device in Utility.. I have only cube im switch tab

Re: Xiaomi Cube rotate

Posted: Friday 04 October 2019 22:21
by Thorgal789
If all is ok you will have
1 device in swich tab (for state)
1 device in utility (for angle)
Take a look in setting/device, perhaps it is not activated yet. Device that are not activated don't trigger (Conbee - lumi.sensor_cube.aqgl01 4)

Re: Xiaomi Cube rotate  [Solved]

Posted: Saturday 05 October 2019 12:43
by czasas
Its works, thanks guys for help !