How to decode Data store in the Options field in DB Topic is solved

Python and python framework

Moderator: leecollings

Post Reply
pipiche
Posts: 2016
Joined: Monday 02 April 2018 20:33
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: France
Contact:

How to decode Data store in the Options field in DB

Post by pipiche »

In order to do some debuging, I need to find out a way to decode the Options column in the domoticz Database.

Here is what I got from the following command

Code: Select all

[code]Select DeviceID, Name, Options from DeviceStatus ;

Code: Select all

d3a9|Cube|LevelActions:fHx8fHx8fHx8;LevelNames:T2ZmfFNoYWtlfFdha2V1cHxEcm9wfDkwwrB8MTgwwrB8UHVzaHxUYXB8Um90YXRpb24=;LevelOffHidden:dHJ1ZQ==;SelectorStyle:MA==;TypeName:QXFhcmE=;Zigate:eydSU1NJJzogMjQzLCAnWkRldmljZUlEJzoge30sICdUeXBlJzogJ0FxYXJhJywgJ1N0YXR1cyc6ICdpbkRCJywgJ1JJQSc6ICczJywgJ01hY0NhcGEnOiAnODAnLCAnQmF0dGVyeSc6IHt9LCAnSGVhcnRiZWF0JzogJzAnLCAnTW9kZWwnOiAnbHVtaS5zZW5zb3JfY3ViZS5hcWdsMDEnLCAnSUVFRSc6ICcwMDE1OGQwMDAyNzk4NGFlJywgJ1Byb2ZpbGVJRCc6IHt9LCAnRXAnOiB7JzAxJzogeycwMDAwJzoge30sICcwMDBjJzoge30sICcwMDEyJzoge319fX0=
Now my question is can from a python script or some other script I can decode the Options['Zigate'] and Options['TypeName'] fields ?
Zigbee for Domoticz plugin / RPI3B+ / Electrolama ZZH-P / 45 devices

If the plugin provides you value, you can support me with a donation Paypal.

Wiki is available here.

Zigbee for Domoticz FAQ
SweetPants

Re: How to decode Data store in the Options field in DB

Post by SweetPants »

These are Base64 encoded strings, using Base64 decoder you get your strings back (I hope)

T2ZmfFNoYWtlfFdha2V1cHxEcm9wfDkwwrB8MTgwwrB8UHVzaHxUYXB8Um90YXRpb24 = Off|Shake|Wakeup|Drop|90°|180°|Push|Tap|Rotation
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: How to decode Data store in the Options field in DB

Post by waaren »

pipiche wrote: Sunday 07 October 2018 15:51 In order to do some debuging, I need to find out a way to decode the Options column in the domoticz Database.
T2ZmfFNoYWtlfFdha2V1....
Now my question is can from a python script or some other script I can decode the Options['Zigate'] and Options['TypeName'] fields ?
In Lua (and dzVents) you can do this by using:

Code snippet

Code: Select all

-- Base string
local b='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/' 

-- decode function
function dec(data)
    data = string.gsub(data, '[^'..b..'=]', '')
    return (data:gsub('.', function(x)
        if (x == '=') then return '' end
        local r,f='',(b:find(x)-1)
        for i=6,1,-1 do r=r..(f%2^i-f%2^(i-1)>0 and '1' or '0') end
        return r;
    end):gsub('%d%d%d?%d?%d?%d?%d?%d?', function(x)
        if (#x ~= 8) then return '' end
        local c=0
        for i=1,8 do c=c+(x:sub(i,i)=='1' and 2^(8-i) or 0) end
        return string.char(c)
    end))
end    

local codedString = "T2ZmfFNoYWtlfFdha2V1cHxEcm9wfDkwwrB8MTgwwrB8UHVzaHxUYXB8Um90YXRpb24"
local codedString2=  "eydSU1NJJzogMjQzLCAnWkRldmljZUlEJzoge30sICdUeXBlJzogJ0FxYXJhJywgJ1N0YXR1cyc6ICdpbkRCJywgJ1JJQSc6ICczJywgJ01hY0NhcGEnOiAnODAnLCAnQmF0dGVyeSc6IHt9LCAnSGVhcnRiZWF0JzogJzAnLCAnTW9kZWwnOiAnbHVtaS5zZW5zb3JfY3ViZS5hcWdsMDEnLCAnSUVFRSc6ICcwMDE1OGQwMDAyNzk4NGFlJywgJ1Byb2ZpbGVJRCc6IHt9LCAnRXAnOiB7JzAxJzogeycwMDAwJzoge30sICcwMDBjJzoge30sICcwMDEyJzoge319fX0"
dz.log(dec(codedString),dz.LOG_FORCE)
dz.log(dec(codeString2),dz.LOG_FORCE)


Result:

Code: Select all

2018-10-07 19:53:00.727  Status: dzVents: !Info: Off|Shake|Wakeup|Drop|90°|180°|Push|Tap|Rotation
2018-10-07 19:53:00.734  Status: dzVents: !Info: {'RSSI': 243, 'ZDeviceID': {}, 'Type': 'Aqara', 'Status': 'inDB', 'RIA': '3', 'MacCapa': '80', 'Battery': {}, 'Heartbeat': '0', 'Model': 'lumi.sensor_cube.aqgl01', 'IEEE': '00158d00027984ae', 'ProfileID': {}, 'Ep': {'01': {'0000': {}, '000c': {}, '0012': {}}}}
Just be clear.. Not invented by me :)
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest