RGB switch and Lua script

Moderator: leecollings

Post Reply
Tamanar
Posts: 3
Joined: Monday 16 March 2020 13:01
Target OS: Windows
Domoticz version:
Contact:

RGB switch and Lua script

Post by Tamanar »

Hi!

I want to use an wemos d1 mini as a master and an arduino as slave to make a clock.
The clock use an RGB strip led (ws2812b). I only need to send information to the arduino with a serial liason. (because I already a code with bluetooth)
Because of that i have to program myself the wemos and not use a firmware.

With many tutorial i finally speak with my board and i can send an on/Off signal with the RGB switch: Image Image

One of help found give me a lua script which i have done some changes to send the right URL to my board.

Code: Select all

commandArray = {}
DomDevice = 'P1'; -- Votre peripherique à controler
IP = '192.168.0.32'; -- L'adresse IP de l'ESP8266
PIN = "20"; -- Le pin GPIO du servo
 

 
if devicechanged['P1'] then
   if(devicechanged[DomDevice]=='Off') then
       print ("OFF dim = "..DomDevice);
        CalcValue = 0x00;
    else if(devicechanged[DomDevice]=='On') then
        
        print ("ON dim = "..DomDevice);
        CalcValue = 0xFFFFF;
    else
        print("Other");
        DomValue = otherdevices_svalues[DomDevice];
        CalcValue=DomValue;
        --commandArray['Variable:dimmer'] = tostring(DomValue);
        print ("dim Level = "..CalcValue);
    end
    end
    runcommand = "http://" .. IP .. "/gpio?id="  ..PIN.. "&etat="..CalcValue .. "&token=123abCde"; -- Commande de Led
    print(runcommand);
    commandArray['OpenURL']=runcommand;
    print("PWM value= "..CalcValue);
end
return commandArray


But something that i can't find on the internet is that i can't get the RGB value of the color wheel.
I see on the log one i make a changes on the color wheel this:
2020-03-16 13:14:30.534 Status: setcolbrightnessvalue: ID: 1, bri: 50, color: '{m: 3, RGB: 9dff96, CWWW: 0000, CT: 0}'
2020-03-16 13:14:30.569 Status: LUA: Other
2020-03-16 13:14:30.569 Status: LUA: dim Level = 50
2020-03-16 13:14:30.569 Status: LUA: http://192.168.0.32/gpio?id=20&etat=50&token=123abCde
2020-03-16 13:14:30.570 Status: LUA: PWM value= 50
2020-03-16 13:14:30.570 Status: EventSystem: Fetching URL http://192.168.0.32/gpio?id=20&etat=50&token=123abCde after 0.2 seconds...
2020-03-16 13:14:30.570 Status: EventSystem: Script event triggered: RGBSwitch
2020-03-16 13:14:33.968 Error: Error opening url: http://192.168.0.32/gpio?id=20&etat=50&token=123abCde
2020-03-16 13:15:00.377 Error: EventSystem: in RGBSwitch: [string "-- Merci @MikeF : https://www.domoticz.com/fo..."]:11: attempt to index global 'devicechanged' (a nil value)
So what i undestand is that

Code: Select all

 DomValue = otherdevices_svalues[DomDevice
give me the brightness of the switch. But i'm interested in the RGB value (here 9dff96)

To resume

How can i get the RGB value of the RGB switch?

And my two more questions which are less important is :
what does mean the two last Error ?
The first one, i suppose that it can't open the link, but it triggered anyway the board, so it's a "non-error"
And the second one (which i get aproximatly every minutes) i suppose it's because i try to check on the device change list, but because i haven't any devices i got an error. So again a "non-error"

Thanks in advance for any help you can provide.
Tamanar
Posts: 3
Joined: Monday 16 March 2020 13:01
Target OS: Windows
Domoticz version:
Contact:

Re: RGB switch and Lua script

Post by Tamanar »

Quick update.
When i triggered my script on device i only got one error:
2020-03-17 09:19:19.480 Error: Error opening url: http://192.168.0.32/gpio?id=20&etat=88&token=123abCde

So i delete one of the two error \o/

But i still can't access to the data i need...
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: RGB switch and Lua script

Post by waaren »

Tamanar wrote: Tuesday 17 March 2020 9:21 But i still can't access to the data i need...
I have no clue how to get the color data in classic Lua but in dzVents you would use something like

Code: Select all

device.color
it returns a JSON like

Code: Select all

{"b":0,"cw":255,"g":0,"m":2,"r":0,"t":160,"ww":255}
When not yet familiar with dzVents please start with reading Get started Before implementing (~ 5 minutes). Special attention please for "In Domoticz go to Setup > Settings > Other and in the section EventSystem make sure the checkbox 'dzVents enabled' is checked. Also make sure that in the Security section in the settings you allow 127.0.0.1 to not need a password. dzVents uses that port to send certain commands to Domoticz. Finally make sure you have set your current location in Setup > Settings > System > Location, otherwise there is no way to determine nighttime/daytime state."
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Tamanar
Posts: 3
Joined: Monday 16 March 2020 13:01
Target OS: Windows
Domoticz version:
Contact:

Re: RGB switch and Lua script

Post by Tamanar »

Hi!

it returns a JSON like

Code: Select all

{"b":0,"cw":255,"g":0,"m":2,"r":0,"t":160,"ww":255}
Well i get what you said, but i can't access to each individual color. (i'am more than a beginner on Dzevent and Json)

and what is the equivalent for

Code: Select all

commandArray['OpenURL']=runcommand;
Or how can i send an http request with dzevent ?
Thanks for your help
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: RGB switch and Lua script

Post by waaren »

Tamanar wrote: Tuesday 17 March 2020 20:33 Or how can i send an http request with dzevent ?
Thanks for your help
Hope that this example will get you going.

Code: Select all

DomDevice = 'P1' -- Votre peripherique à controler
IP = '192.168.0.32' -- L'adresse IP de l'ESP8266
PIN = "20" -- Le pin GPIO du servo

return 
{
    on = 
    {
        devices = 
        {
            DomDevice,
        },
    },

    logging = 
    {
        level = domoticz.LOG_DEBUG,
        marker = color,
    },

    execute = function(dz, item)
        dz.log('State of ' .. item.name .. ' is: ' .. item.state, dz.LOG_DEBUG )

        local CalcValue, DomValue

        if item.state == 'Off' then
           CalcValue = 0x00
        elseif item.state == 'On' then
            CalcValue = 0xFFFFF
        else
            dz.log('dimlevel of ' .. item.name .. ' is' .. tostring(item.level),dz.LOG_DEBUG )
            CalcValue = item.level
        end

        local url = "http://" .. IP .. "/gpio?id="  ..PIN.. "&etat="..CalcValue .. "&token=123abCde"; -- Commande de Led
        dz.openURL(url) 

        dz.log('color of ' .. item.name .. ' is' .. item.color,dz.LOG_DEBUG )

        local colorTable = dz.utils.fromJSON(item.color) 

        dz.utils.dumpTable(colorTable)

        dz.log('Colors of ' .. item.name .. 
                'red: ' .. colorTable.r .. ', ' ..
                'green: ' .. colorTable.b .. ', ' ..
                'blue: ' .. colorTable.g .. '.',    dz.LOG_DEBUG)

    end
}
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