Xiaomi Cube rotate  [Solved]

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
czasas
Posts: 19
Joined: Thursday 26 September 2019 21:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Xiaomi Cube rotate

Post 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 ??
Thorgal789
Posts: 815
Joined: Wednesday 15 August 2018 14:38
Target OS: -
Domoticz version:
Contact:

Re: Xiaomi Cube rotate

Post 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
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Xiaomi Cube rotate

Post 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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
czasas
Posts: 19
Joined: Thursday 26 September 2019 21:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Xiaomi Cube rotate

Post 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 ?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Xiaomi Cube rotate

Post 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.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Thorgal789
Posts: 815
Joined: Wednesday 15 August 2018 14:38
Target OS: -
Domoticz version:
Contact:

Re: Xiaomi Cube rotate

Post by Thorgal789 »

Ha yep, I m just seeing we are in dzEvent section ^^, so my question was stupid.
czasas
Posts: 19
Joined: Thursday 26 September 2019 21:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Xiaomi Cube rotate

Post by czasas »

I put this script and it doesnt return anything in domoticz log
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Xiaomi Cube rotate

Post 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.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
czasas
Posts: 19
Joined: Thursday 26 September 2019 21:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Xiaomi Cube rotate

Post 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
Thorgal789
Posts: 815
Joined: Wednesday 15 August 2018 14:38
Target OS: -
Domoticz version:
Contact:

Re: Xiaomi Cube rotate

Post 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)
czasas
Posts: 19
Joined: Thursday 26 September 2019 21:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Xiaomi Cube rotate  [Solved]

Post by czasas »

Its works, thanks guys for help !
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest