Get color of RGBW device in dzVents  [Solved]

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

Moderator: leecollings

bramski
Posts: 45
Joined: Thursday 20 July 2017 16:26
Target OS: -
Domoticz version:
Contact:

Get color of RGBW device in dzVents

Post by bramski »

I am trying to create a color picker for my ambilight TV so I can control the color from domoticz.
Got a python script up and running which I can use to switch the effect and color of the ambilight.
Also created an RGB dummy device in domoticz.
Next I wanted to create a small dzVents scripts which listens to changes on the dummy device and passes the color to the python script accordingly. However I cannot access any color information for the device within my dzVents script.

I tried to dump all properties, but the color information is empty.

Code: Select all

domoticz.devices('Ambilight color').dump()
Am I missing something or is this not implemented?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Get color of RGBW device in dzVents

Post by waaren »

bramski wrote: Tuesday 11 December 2018 20:13 I am trying to create a color picker for my ambilight TV so I can control the color from domoticz.
Got a python script up and running which I can use to switch the effect and color of the ambilight.
Also created an RGB dummy device in domoticz.
Next I wanted to create a small dzVents scripts which listens to changes on the dummy device and passes the color to the python script accordingly. However I cannot access any color information for the device within my dzVents script.

I tried to dump all properties, but the color information is empty.

Code: Select all

domoticz.devices('Ambilight color').dump()
Am I missing something or is this not implemented?
If I dump the attrubutes of a RGBW device in dzVents I get the color info. What is your result for type, subtype and device-adapters ?

Code: Select all

: > hardwareTypeValue: 38
: > state: Set Color
: > switchType: Dimmer
: > _data:
: >     data:
: >         hardwareType: Philips Hue Bridge
: >         hardwareTypeValue: 38
: >         icon: dimmer
: >         hardwareName: Hue
: >         _state: Set Color
: >         color: {"b":130,"cw":0,"g":211,"m":3,"r":254,"t":0,"ww":0}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
bramski
Posts: 45
Joined: Thursday 20 July 2017 16:26
Target OS: -
Domoticz version:
Contact:

Re: Get color of RGBW device in dzVents

Post by bramski »

Thanks for checking waaren. How did you get this nested output? I see the following in my log:

Code: Select all

2018-12-11 21:57:17.526 Status: dzVents: > hardwareType: Dummy (Does nothing, use for virtual switches only)
2018-12-11 21:57:17.526 Status: dzVents: > color:
2018-12-11 21:57:17.526 Status: dzVents: > protected: false
2018-12-11 21:57:17.526 Status: dzVents: > maxDimLevel: 100
2018-12-11 21:57:17.526 Status: dzVents: > unit: 1
2018-12-11 21:57:17.526 Status: dzVents: > hardwareID: 4
2018-12-11 21:57:17.526 Status: dzVents: > hardwareName: Dummy
2018-12-11 21:57:17.526 Status: dzVents: > _nValue: 10
2018-12-11 21:57:17.526 Status: dzVents: > icon: dimmer
2018-12-11 21:57:17.526 Status: dzVents: > hardwareTypeValue: 15
2018-12-11 21:57:17.526 Status: dzVents: > levelVal: 1
Could you also try with a dummy device?
bramski
Posts: 45
Joined: Thursday 20 July 2017 16:26
Target OS: -
Domoticz version:
Contact:

Re: Get color of RGBW device in dzVents

Post by bramski »

Hmm I tried to print just the color now and it is working 10 times in a row now:

Code: Select all

print(triggeredItem.color)
I did get very inconsistent output when dumping using dump(), no color attribute or empty color attribute. Also other missing attributes.
poudenes
Posts: 667
Joined: Wednesday 08 March 2017 9:42
Target OS: Linux
Domoticz version: 3.8993
Location: Amsterdam
Contact:

Re: Get color of RGBW device in dzVents

Post by poudenes »

Interesting. Now I want know how we can use the output to set a bulb to same value....

Then you can store the color, change the color and later set it back to original color


Verzonden vanaf mijn iPhone met Tapatalk Pro
RPi3 B+, Debain Stretch, Domoticz, Homebridge, Dashticz, RFLink, Milight, Z-Wave, Fibaro, Nanoleaf, Nest, Harmony Hub, Now try to understand pass2php
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Get color of RGBW device in dzVents

Post by waaren »

Do you look at the log using the GUI or at the OS level ?
bramski wrote:Hmm I tried to print just the color now and it is working 10 times in a row now:

Code: Select all

print(triggeredItem.color)
I did get very inconsistent output when dumping using dump(), no color attribute or empty color attribute. Also other missing attributes.
Verstuurd vanaf mijn ONEPLUS A6003 met Tapatalk

Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
bramski
Posts: 45
Joined: Thursday 20 July 2017 16:26
Target OS: -
Domoticz version:
Contact:

Re: Get color of RGBW device in dzVents

Post by bramski »

waaren wrote: Wednesday 12 December 2018 16:13 Do you look at the log using the GUI or at the OS level ?
bramski wrote:Hmm I tried to print just the color now and it is working 10 times in a row now:

Code: Select all

print(triggeredItem.color)
I did get very inconsistent output when dumping using dump(), no color attribute or empty color attribute. Also other missing attributes.
Verstuurd vanaf mijn ONEPLUS A6003 met Tapatalk
I did use the GUI. Just checked by tailing the domoticz.log and the data is shown correctly there. So it seems to be a problem with the log parsing in the domoticz UI.
bramski
Posts: 45
Joined: Thursday 20 July 2017 16:26
Target OS: -
Domoticz version:
Contact:

Re: Get color of RGBW device in dzVents

Post by bramski »

poudenes wrote: Wednesday 12 December 2018 10:31 Interesting. Now I want know how we can use the output to set a bulb to same value....

Then you can store the color, change the color and later set it back to original color


Verzonden vanaf mijn iPhone met Tapatalk Pro
I don't really understand your use case. Of which kind of bulb do you want to control the color? When you are using Hue, Innr, Tradfi, Fibaro RGBW etc. you will have a native RGBW device in domoticz anyway, so no need for a dummy RGBW device.
galinette
Posts: 68
Joined: Monday 11 December 2017 22:57
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Get color of RGBW device in dzVents

Post by galinette »

bramski wrote: Wednesday 12 December 2018 19:55 I don't really understand your use case. Of which kind of bulb do you want to control the color? When you are using Hue, Innr, Tradfi, Fibaro RGBW etc. you will have a native RGBW device in domoticz anyway, so no need for a dummy RGBW device.
Just imagine you have a lot of light bulbs, and want to create a virtual one which controls all at once with and event...
Haubke
Posts: 10
Joined: Saturday 27 February 2016 20:38
Target OS: Linux
Domoticz version:
Contact:

Re: Get color of RGBW device in dzVents

Post by Haubke »

Do you have any sugestions how to use this?

I want a similar thing.
I have a spot light with 3 gu10 bulbs. Every bulb has its own switch. Now i want to create a dummy switch where i can set the color to all three devices simultanouasly.

I want to sync color to multiple devices
Server running MQTT and Google assistent.
Server 2 running domoticz. 20+ lsc gu10 rgb bulbs.
Pir sensors. Nest hello, nest thermostat.Many more to come
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Get color of RGBW device in dzVents

Post by waaren »

Haubke wrote: Sunday 03 November 2019 18:49 I have a spot light with 3 gu10 bulbs. Every bulb has its own switch. Now i want to create a dummy switch where i can set the color to all three devices simultanouasly. I want to sync color to multiple devices
So one master virtual RGBW type light and if that changes state or color the 'slave'lights should follow ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Haubke
Posts: 10
Joined: Saturday 27 February 2016 20:38
Target OS: Linux
Domoticz version:
Contact:

Re: Get color of RGBW device in dzVents

Post by Haubke »

Yes thats exactly what i want. I have 3 lsc action gu10 bulbs. Only thing is a can not change color on the fly. Because there are three light, i can but then i need to do every bulb manualy. Or make a scene. Wich will have only one programmed color

I'm srr for my english. Not my native language.
Server running MQTT and Google assistent.
Server 2 running domoticz. 20+ lsc gu10 rgb bulbs.
Pir sensors. Nest hello, nest thermostat.Many more to come
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Get color of RGBW device in dzVents

Post by waaren »

You could try this dzVents script.


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 disabled' is not 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."

Code: Select all

return
{
    on = { devices = { 'masterRGB' }}, -- change to name of your 'master' colorswitch
     
    logging = { level = domoticz.LOG_DEBUG },

    execute = function(dz, item)
        local slaves =
        { 
            'slaveRGB1', -- change to the names of your 'slave' colorswitches
            'slaveRGB2',
            'slaveRGB3',
        }
        
        -- No changes required below this line
        
    	_G.logMarker =  _G.moduleLabel

        local function setColor(target, source, delay)
            local delay = delay or 0
            local source = source or item
            local switchOnURL = dz.settings['Domoticz url'] .. '/json.htm?type=command&param=switchlight&idx=target.id&switchcmd=On'
            local colorURL = dz.settings['Domoticz url'] ..
                        '/json.htm?type=command&param=setcolbrightnessvalue' ..
                        '&idx=' .. target.id   .. '&brightness=' .. source.level .. '&color=' .. source.color
            dz.openURL(colorURL)
            dz.openURL(switchOnURL).afterSec(0.2)
            
            dz.log('Color set to ' .. source.color .. '( brightness: ' .. source.level ..')',dz.LOG_DEBUG )
        end

        for index, value in pairs(slaves) do
            if item.state == 'Off' then
                dz.devices(value).switchOff()
             else
                setColor(dz.devices(value))
            end
        end
    end
}
if the script does not fully work as expected please include the domoticz log and device type / subtype (from the devices tab) of master and slaves.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Haubke
Posts: 10
Joined: Saturday 27 February 2016 20:38
Target OS: Linux
Domoticz version:
Contact:

Re: Get color of RGBW device in dzVents

Post by Haubke »

First of all, Thank you for your reply.

the devices are RGBWW.

ive found a script that is working for a milight i think.
The lights i'm using are flashed with tasmota. so i can change color true http, or mqtt.

ive found a script that is kinda working. only thing is i dont get the colors thrue. dimming is working.

Code: Select all

--[[ LEDSlaveDemo.lua (tested and working on dzVents 2.4.6) but probably also working on earlier versions
  ]]--
 
return {
    on = { devices = {"Woonkamer lamp" } },
    
    logging =   {       level   =   domoticz.LOG_DEBUG,                  -- switch to LOG_INFO when results are OK 
                        marker  =   "LEDSlaveDemo" },                                           

    data    =   {      setColor         = { initial = true },           -- This is necessary because color does not follow in the first pass
                       dimLevel         = { initial = 50   }, 
                       color            = { initial = {}   }}, 
                       
    execute = function(dz, trigger)
        local slave   = dz.devices("LED 1")
        local slave1   = dz.devices("LED 2")
        local slave2   = dz.devices("LED 3")
        dz.log("Master ( name / state / level / color )  ( " .. 
                        trigger.name .. " / " .. 
                        trigger.state .. " / " .. 
                        trigger.level .. " / " .. 
                        trigger.color .. " )",dz.LOG_DEBUG)
        
        colorTable = dz.utils.fromJSON(trigger.color)                       -- convert color (a json string) to a Lua table
        
        if trigger.state ~= "Off" and trigger.level > 0 then                -- State can be "On", "Off" or "set Color" 
            dz.data.dimLevel =  trigger.level
            dz.data.color    =  trigger.color
            slave.setRGB(  colorTable.r, colorTable.g, colorTable.b )
            slave1.setRGB(  colorTable.r, colorTable.g, colorTable.b )
            slave2.setRGB(  colorTable.r, colorTable.g, colorTable.b )
            slave.dimTo(tonumber(dz.data.dimLevel))
            slave1.dimTo(tonumber(dz.data.dimLevel))
            slave2.dimTo(tonumber(dz.data.dimLevel))
            if dz.data.setColor then                                        -- We need to trigger the script another time as the color 
                dz.data.dimLevel =  trigger.level                           -- does not follow the first pass. Does not seem timing but looks like    
                trigger.dimTo(dz.data.dimLevel)                             -- dzVents is not yet updated with right color values from master
                dz.data.setColor = false                                  
            else
                dz.data.setColor = true
            end 
        else
            slave.switchOff()
            slave1.switchOff()
            slave2.switchOff()
        end
    end
}
trying to get this to work properly. ive already seen functions Getcolor and Setcolor in dzvents.
ive done a lot of programming, never done lua.

i will see what you have made me.

thank you for your time.
Server running MQTT and Google assistent.
Server 2 running domoticz. 20+ lsc gu10 rgb bulbs.
Pir sensors. Nest hello, nest thermostat.Many more to come
Haubke
Posts: 10
Joined: Saturday 27 February 2016 20:38
Target OS: Linux
Domoticz version:
Contact:

Re: Get color of RGBW device in dzVents

Post by Haubke »

i get the following log,

Code: Select all

2019-11-04 00:07:15.939 Status: dzVents: Write file: /home/domoticz/domoticz/scripts/dzVents/generated_scripts/test master/slave.lua
2019-11-04 00:07:23.658 (rgbww spots) Color Switch (Woonkamer lamp)
2019-11-04 00:07:23.642 Status: setcolbrightnessvalue: ID: 2, bri: 64, color: '{m: 3, RGB: ffd9e9, CWWW: 0000, CT: 0}'
2019-11-04 00:07:24.676 (rgbww spots) Color Switch (Woonkamer lamp)
2019-11-04 00:07:24.669 Status: setcolbrightnessvalue: ID: 2, bri: 64, color: '{m: 3, RGB: ff2bb0, CWWW: 0000, CT: 0}'
2019-11-04 00:07:25.651 (rgbww spots) Color Switch (Woonkamer lamp)
2019-11-04 00:07:25.645 Status: User: Admin initiated a switch command (2/Woonkamer lamp/On)
2019-11-04 00:10:02.542 (rgbww spots) Color Switch (Woonkamer lamp)
2019-11-04 00:10:02.519 Status: setcolbrightnessvalue: ID: 2, bri: 64, color: '{m: 3, RGB: 47ff53, CWWW: 0000, CT: 0}'
2019-11-04 00:10:03.469 (rgbww spots) Color Switch (Woonkamer lamp)
2019-11-04 00:10:03.463 Status: User: Admin initiated a switch command (2/Woonkamer lamp/On)
no errors :D
but no output to other leds.
Server running MQTT and Google assistent.
Server 2 running domoticz. 20+ lsc gu10 rgb bulbs.
Pir sensors. Nest hello, nest thermostat.Many more to come
Haubke
Posts: 10
Joined: Saturday 27 February 2016 20:38
Target OS: Linux
Domoticz version:
Contact:

Re: Get color of RGBW device in dzVents  [Solved]

Post by Haubke »

thank you it is working.

i made a mistake why it was't working. i put a / in the scripts name. :roll:

only thing is i need to refresh the color twice to get the correct output.
like
if i change from lets say white to red, then i choose green. the leds would become red.
only if i already have the lights on. so it looks like color change is a loop afterwards internally in domoticz?
doesnt matter that much. if i push the button on it will work;)

thank you very much,
Server running MQTT and Google assistent.
Server 2 running domoticz. 20+ lsc gu10 rgb bulbs.
Pir sensors. Nest hello, nest thermostat.Many more to come
eserero
Posts: 17
Joined: Monday 25 June 2018 23:41
Target OS: Windows
Domoticz version:
Contact:

Re: Get color of RGBW device in dzVents

Post by eserero »

I have the same problem as @Haubke,
the color temperature seems to be updating only the second time.

anyone know how to resolve that?

[update] - OK, seems like when I query the virtual switch color, it gives me the color before the change, so that only after I finish the event, the change is updated. I"m using device.color then turn it to json.

I can resolve it by putting a device.switchOn() line, but this slows things significantly.

anyone know how to pull from the virtual switch the color AFTER update and not before the update?
Last edited by eserero on Monday 18 November 2019 22:55, edited 1 time in total.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Get color of RGBW device in dzVents

Post by waaren »

eserero wrote: Monday 18 November 2019 22:33 I have the same problem as @Haubke,
the color temperature seems to be updating only the second time.

anyone know how to resolve that?
You could try to add an extra switchOn.afterSec(0.3)
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
eserero
Posts: 17
Joined: Monday 25 June 2018 23:41
Target OS: Windows
Domoticz version:
Contact:

Re: Get color of RGBW device in dzVents

Post by eserero »

waaren wrote: Monday 18 November 2019 22:51
eserero wrote: Monday 18 November 2019 22:33 I have the same problem as @Haubke,
the color temperature seems to be updating only the second time.

anyone know how to resolve that?
You could try to add an extra switchOn.afterSec(0.3)
HA - just updated my post with the same... but it slows things a lot.... looking for a way to pull the real data
eserero
Posts: 17
Joined: Monday 25 June 2018 23:41
Target OS: Windows
Domoticz version:
Contact:

Re: Get color of RGBW device in dzVents

Post by eserero »

OK - just for completeness, I eventually implemented a solution that uses switchOn to capture the change, but in order not to update the real lights twice and cause a delay, I included a toggle parameter in the "data" section - if its 0, then I just run change its value to 1, then run device.switchOn() and exist the event, the switchOn even will trigger the event again, then I see that the toggle paramter is 1 - in which case I change it back to 0 then run the original function.
Ugly but works.

I wonder if this behavior is a bug in domoticz, I'll try to open a bug.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 0 guests