Decode JOSN Sting

Moderator: leecollings

Post Reply
jannnfe
Posts: 30
Joined: Tuesday 30 January 2018 0:27
Target OS: Linux
Domoticz version: Beta
Location: Germany
Contact:

Decode JOSN Sting

Post by jannnfe »

Hey,
I have a string like this:

Code: Select all

{"b":122,"cw":0,"g":128,"m":3,"r":255,"t":0,"ww":0}
How can I get the r, g and b value from that string?
I like to write a script that catches the RGB from Virtual Device Color picking and send it over Http to my ESPEasy firmware.
I already managed to get the Color Values from device.

Thanks :)
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Decode JOSN Sting

Post by waaren »

jannnfe wrote: Thursday 01 November 2018 19:36 I have a string like {"b":122,"cw":0,"g":128,"m":3,"r":255,"t":0,"ww":0}
How can I get the r, g and b value from that string?
This should do it

Code: Select all

-- getJSON
  
return {
    on      =       {   timer = { "every minute"  }},    
    
    execute = function(dz)
    
        colorTable = dz.utils.fromJSON('{"b":122,"cw":0,"g":128,"m":3,"r":255,"t":0,"ww":0}')
    
        print ("b:  " .. colorTable.b)
        print ("cw: " .. colorTable.cw)
        print ("g:  " .. colorTable.g)
        print ("m:  " .. colorTable.m)
        print ("r:  " .. colorTable.r)
        print ("t:  " .. colorTable.t)
        print ("ww: " .. colorTable.ww)
       
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
jannnfe
Posts: 30
Joined: Tuesday 30 January 2018 0:27
Target OS: Linux
Domoticz version: Beta
Location: Germany
Contact:

Re: Decode JOSN Sting

Post by jannnfe »

You are the best. Thank you very much I did not think about the dzVents utils. Many Thanks :)
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest