is it possible to read and compare the color of philips hue bulbs in dzvents?  [Solved]

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

Moderator: leecollings

Post Reply
kitopopo
Posts: 59
Joined: Monday 03 December 2018 11:49
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

is it possible to read and compare the color of philips hue bulbs in dzvents?

Post by kitopopo »

Hi dear friends,

I have some philips hue bulbs that sometimes light up a yellow color (this is philips default yellow color and this happens when they lose power)
For my taste this color is horrible and I would like to make a script to be able to read the color of the bulbs and if it is the same color as yellow to be able to change to my favorite color.

Through zigbe2mqtt and mosquitto I can read the color of the bulb using the command:

Code: Select all

sudo mosquitto_pub -h 127.0.0.1 -t zigbee2mqtt/0x00178xxxxxxxxxxxx/get -m '{"color":""}'
after sending this mqtt message I can see the color in the domoticz log

Code: Select all

2021-01-04 19:43:45.446 (zigbe2mqtt) MQTT message: zigbee2mqtt/Philips hue1 {'brightness': 254, 'color': {'hue': 82, 'saturation': 56, 'x': 0.4575, 'y': 0.4101}, 'color_temp': 165, 'linkquality': 49, 'state': 'ON'}
I'm not sure if from dzvents or from json or a maybe using a bash script it would be possible to read the color and compare the color.

Thanks for your help, best regards
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: is it possible to read and compare the color of philips hue bulbs in dzvents?

Post by waaren »

kitopopo wrote: Monday 04 January 2021 19:52 I'm not sure if from dzvents or from json or a maybe using a bash script it would be possible to read the color and compare the color.
dzVents can read color and compare it against a given one but because to bulb does not send anything to domoticz when it becomes powerless nor when the power is restored you would need a time triggered script that looks every minute what the color is. To me that sounds as overkill but you may have another view on this.

using JSON

http://<domoticz IP:domoticz port>/json.htm?type=devices&rid=IDX
Spoiler: show

Code: Select all

{
"ActTime": 1609788600,
"AstrTwilightEnd": "18:49",
"AstrTwilightStart": "06:45",
"CivTwilightEnd": "17:26",
"CivTwilightStart": "08:09",
"DayLength": "07:57",
"NautTwilightEnd": "18:09",
"NautTwilightStart": "07:25",
"ServerTime": "2021-01-04 20:30:00",
"SunAtSouth": "12:47",
"Sunrise": "08:48",
"Sunset": "16:46",
"app_version": "2020.2 (build 12815)",
"result": [
{
"AddjMulti": 1,
"AddjMulti2": 1,
"AddjValue": 0,
"AddjValue2": 0,
"BatteryLevel": 255,
"Color": "{\"b\":84,\"cw\":0,\"g\":196,\"m\":3,\"r\":254,\"t\":0,\"ww\":0}",
"CustomImage": 0,
"Data": "On",
"Description": "",
"DimmerType": "abs",
"Favorite": 0,
"HardwareDisabled": false,
"HardwareID": 12,
"HardwareName": "Hue",
"HardwareType": "Philips Hue Bridge",
"HardwareTypeVal": 38,
"HaveDimmer": true,
"HaveGroupCmd": false,
"HaveTimeout": false,
"ID": "00000002",
"Image": "Light",
"IsSubDevice": false,
"LastUpdate": "2021-01-04 20:29:04",
"Level": 75,
"LevelInt": 75,
"MaxDimLevel": 100,
"Name": "LM46 table left",
"Notifications": "false",
"PlanID": "0",
"PlanIDs": [
0
],
"Protected": false,
"ShowNotifications": true,
"SignalLevel": "-",
"Status": "On",
"StrParam1": "",
"StrParam2": "",
"SubType": "RGBWW",
"SwitchType": "Dimmer",
"SwitchTypeVal": 7,
"Timers": "false",
"Type": "Color Switch",
"TypeImg": "dimmer",
"Unit": 1,
"Used": 1,
"UsedByCamera": false,
"XOffset": "0",
"YOffset": "0",
"idx": "156"
}
],
"status": "OK",
"title": "Devices"
}

dzVents script

Code: Select all

local scriptVar = 'getColor Hue'
return
{
    on =
    {
        timer =
        {
            'every minute',
        },
    },

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

    execute = function(dz)
        local bulbs = {156, 1734 } -- Hue bulbs
        local hueDefaultColor =
        {
            red = 0,
            green = 0,
            blue = 0,
        }
        local betterColor =
        {
            red = 255,
            green = 115,
            blue = 200,
            brightness = 33,
        }


        local function isEqualColor(c1, c2)
            return ( c1.red == c2.red and c1.green == c2.green and c1.blue == c2.blue )
        end

        for _, id in ipairs(bulbs) do
            bulb = dz.devices(id)
            dz.utils.dumpTable(bulb.getColor())
            if bulb.active then
                bulbColor = bulb.getColor()
                if isEqualColor(hueDefaultColor, bulb.getColor()) then
                    bulb.setRGB(betterColor.red, betterColor.green, betterColor.blue)
                    bulb.dimTo(betterColor.brightness)
                end
            end
        end

    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
kitopopo
Posts: 59
Joined: Monday 03 December 2018 11:49
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: is it possible to read and compare the color of philips hue bulbs in dzvents?

Post by kitopopo »

Hello mr @waaren, thank you for your reply, you do a great job, thank you for your dedication.

The script works almost perfectly, it correctly detects the default color of philips but there seems to be a bug in the green color, when I try to set cool white as the desired color, the color is always executed RGB: ff00ff

Code: Select all

setcolbrightnessvalue: ID: 175, bri: 39 , color: '{m: 1, RGB: ff00ff, CWWW: 0000, CT: 0}'
however if I run the rgb colors separately (255,0,0), (0,255,0) and (0,0,255) then they all run correctly. I can't get the rgb color (255,255,255) which I think would be cool white.

Regrading the script trigger, you are right, this check is exacerbated every minute, but as I have a shelly that controls the turning on of the philips hue, I could choose the shelly as the trigger. for example: 15 seconds after the shelly = on executes the script. I have never put a delay on a trigger, I will try to find a way. Thanks, best regard
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: is it possible to read and compare the color of philips hue bulbs in dzvents?

Post by waaren »

kitopopo wrote: Monday 04 January 2021 23:43 The script works almost perfectly, it correctly detects the default color of philips but there seems to be a bug in the green color, when I try to set cool white as the desired color, the color is always executed RGB: ff00ff
you could tryagain after replacing the lines

Code: Select all

                    bulb.setRGB(betterColor.red, betterColor.green, betterColor.blue)
                    bulb.dimTo(betterColor.brightness)
with

Code: Select all

                    bulb.setColor(betterColor.red, betterColor.green, betterColor.blue, betterColor.brightness)
to see if that gives a better result.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
kitopopo
Posts: 59
Joined: Monday 03 December 2018 11:49
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: is it possible to read and compare the color of philips hue bulbs in dzvents?  [Solved]

Post by kitopopo »

waaren wrote: Tuesday 05 January 2021 0:04
kitopopo wrote: Monday 04 January 2021 23:43 The script works almost perfectly, it correctly detects the default color of philips but there seems to be a bug in the green color, when I try to set cool white as the desired color, the color is always executed RGB: ff00ff
you could tryagain after replacing the lines

Code: Select all

                    bulb.setRGB(betterColor.red, betterColor.green, betterColor.blue)
                    bulb.dimTo(betterColor.brightness)
with

Code: Select all

                    bulb.setColor(betterColor.red, betterColor.green, betterColor.blue, betterColor.brightness)
to see if that gives a better result.
Dear @waaren,

Now the scripts works correctly. thanks very much.
I'm really grateful to you, best regrads
kitopopo
Posts: 59
Joined: Monday 03 December 2018 11:49
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: is it possible to read and compare the color of philips hue bulbs in dzvents?

Post by kitopopo »

kitopopo wrote: Tuesday 05 January 2021 0:25
waaren wrote: Tuesday 05 January 2021 0:04
kitopopo wrote: Monday 04 January 2021 23:43 The script works almost perfectly, it correctly detects the default color of philips but there seems to be a bug in the green color, when I try to set cool white as the desired color, the color is always executed RGB: ff00ff
you could tryagain after replacing the lines

Code: Select all

                    bulb.setRGB(betterColor.red, betterColor.green, betterColor.blue)
                    bulb.dimTo(betterColor.brightness)
with

Code: Select all

                    bulb.setColor(betterColor.red, betterColor.green, betterColor.blue, betterColor.brightness)
to see if that gives a better result.
Dear @waaren,

Now the scripts works correctly. thanks very much.
I'm really grateful to you, best regrads
Hi dear @waaren,


I have been able to thoroughly test the script and find three small problems that I do not know how to solve.

-------

1) If I select as bettercolor for example r: 10, g: 10 and b: 10, brightness 100, the following pattern is sent to the bulbs:

Code: Select all

Debug: getColor Hue: OpenURL: url = http://127.0.0.1:xxxx/json.htm?type=command&param=setcolbrightnessvalue&idx=368&brightness=100&color={"m":3,"t":0,"cw":0,"ww":0,"r":10,"g":10,"b":10}
According to the frame sent, the brightness received by the bulbs is not 100, the brightness received by the bulbs is 7
MQTT publish: topic \'zigbee2mqtt/lamps\', payload \'{"brightness":7,"color":{"hue":82,"saturation":56,"x":0.3227,"y":0.329},"color_temp":165,"state":"ON"}\''}
the brightness increases depending on the rgb values ​​you choose, 255,255,255 would be the maximum brightness.

I think this is because mode = 3 is used in the sending sequence. I have done tests sending the command directly with the browser and I think that using mode = 1 or mode = 2 the brightness would be correct.

--------

2) The reading of the colors that the script performs every minute I think is not correct either. If I choose as betterColour the colors r: 200, g: 100, b: 50,

Code: Select all

Debug: getColor Hue: OpenURL: url = http://127.0.0.1:xxx/json.htm?type=command&param=setcolbrightnessvalue&idx=368&brightness=100&color={"m":3,"t":0,"cw":0,"ww":0,"r":200,"g":100,"b":50}
the colors read by dzvents and that appear in the log in the next few minutes are:

Code: Select all

2021-01-09 19:19:00.685 Status: dzVents: > red: 255
2021-01-09 19:19:00.685 Status: dzVents: > green: 128
2021-01-09 19:19:00.685 Status: dzVents: > blue: 66
if i'm not wrong i think the script should read r: 200, g: 100, b: 50,

--------

3) If at the time the sequence is sent to the bulbs I turn off the bulbs, the sequence is permanently with error in the log until they receive power again, is there any way to cancel the queue? maybe using .cancelQueuedCommands() after the shelly is turned off
2021-01-09 19:36:53.362 Error: (zigbe2mqtt) A Zigbee publish error occured for device 'Philips hue2' with error message: Publish 'set' 'color' to 'Philips hue2' failed: 'Error: Command 0x001788010494a4d3/11 lightingColorCtrl.moveToColor({"transtime":0,"colorx":21148,"colory":21561}, {"timeout":10000,"disableResponse":false,"disableRecovery":false,"disableDefaultResponse":false,"direction":0,"srcEndpoint":null,"reservedBits":0,"manufacturerCode":null,"transactionSequenceNumber":null}) failed (Data request failed with error: 'No network route' (205))'
2021-01-09 19:36:53.362 Error: (zigbe2mqtt) A Zigbee publish error occured for device 'Philips hue1' with error message: Publish 'set' 'color' to 'Philips hue1' failed: 'Error: Command 0x0017880104dc1f87/11 lightingColorCtrl.moveToColor({"transtime":0,"colorx":21148,"colory":21561}, {"timeout":10000,"disableResponse":false,"disableRecovery":false,"disableDefaultResponse":false,"direction":0,"srcEndpoint":null,"reservedBits":0,"manufacturerCode":null,"transactionSequenceNumber":null}) failed (Data request failed with error: 'No network route' (205))'

2021-01-09 19:37:12.079 Error: (zigbe2mqtt) A Zigbee publish error occured for device 'Philips hue4' with error message: Publish 'set' 'color' to 'Philips hue4' failed: 'Error: Command 0x00178801049496be/11 lightingColorCtrl.moveToColor({"transtime":0,"colorx":21148,"colory":21561}, {"timeout":10000,"disableResponse":false,"disableRecovery":false,"disableDefaultResponse":false,"direction":0,"srcEndpoint":null,"reservedBits":0,"manufacturerCode":null,"transactionSequenceNumber":null}) failed (Data request failed with error: 'No network route' (205))'
2021-01-09 19:37:12.181 Error: (zigbe2mqtt) A Zigbee publish error occured for device 'Philips hue3' with error message: Publish 'set' 'color' to 'Philips hue3' failed: 'Error: Command 0x0017880104dc1794/11 lightingColorCtrl.moveToColor({"transtime":0,"colorx":21148,"colory":21561}, {"timeout":10000,"disableResponse":false,"disableRecovery":false,"disableDefaultResponse":false,"direction":0,"srcEndpoint":null,"reservedBits":0,"manufacturerCode":null,"transactionSequenceNumber":null}) failed (Data request failed with error: 'No network route' (205))'


Thank you for your dedication again. Is possible solve this problems?

quiet there is no rush, answer when you have time, thank you very much

a cordial greeting, best regard
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: is it possible to read and compare the color of philips hue bulbs in dzvents?

Post by waaren »

kitopopo wrote: Saturday 09 January 2021 19:44 1) If I select as bettercolor for example r: 10, g: 10 and b: 10, brightness 100, the following pattern is sent to the bulbs:
I think this is because mode = 3 is used in the sending sequence. I have done tests sending the command directly with the browser and I think that using mode = 1 or mode = 2 the brightness would be correct.
If you need more control over what is sent to your light, you can use the other available parameters in setColor.
From the wiki:
setColor(r, g, b, br, cw, ww, m, t): Function. Sets the light to requested color. r, g, b required, others optional. Supports command options. Meaning and limits of parms can be found here
You can also construct your own url and send it from dzVents with domoticz.openURL()
2) The reading of the colors that the script performs every minute I think is not correct either. If I choose as betterColour the colors r: 200, g: 100, b: 50,
if i'm not wrong i think the script should read r: 200, g: 100, b: 50,
dzVents can only report values it gets from the domoticz Event system and these are the values it receives. There are many different types of colour lights and they do not all use the same underlying code. One known issue is that the color in the database is only updated after a second comand (like switchOn() ). Until then the color is only in a part of memory not accessible to the eventsystem and therefore not accessible to dzVents.
3) If at the time the sequence is sent to the bulbs I turn off the bulbs, the sequence is permanently with error in the log until they receive power again, is there any way to cancel the queue? maybe using .cancelQueuedCommands() after the shelly is turned off
Not in domoticz. Maybe you have more luck with ZigBee2MQTT devs?
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: Google [Bot] and 1 guest