Page 1 of 1
Xiaomi Gateway - Setting light color
Posted: Sunday 03 December 2017 13:26
by misfit
I can dim the light with 'level (%)' but how to set RGB color? (Tried to put hex value in 'number' block but seems thats not the right way
Thanks!
Re: Xiaomi Gateway - Setting light color
Posted: Sunday 03 December 2017 14:54
by DAVIZINHO
i make it in dzvents scripts with this code:
Code: Select all
local sceneCmd = 'curl -s -i -H "Accept: application/json" "http://192.168.1.4:8084/json.htm?type=command¶m=setcolbrightnessvalue&idx=20&hue=236&brightness=1&iswhite=false"'
os.execute(sceneCmd)
change the ip and port to conect
change the idx (20 in my case)
change de colour (236 in my case)
and change the brightness (1 in my case)
Re: Xiaomi Gateway - Setting light color
Posted: Monday 04 December 2017 19:07
by misfit
I see this skeleton when creating a new dzvents script:
Code: Select all
return {
on = {
devices = {
'myDevice'
}
},
execute = function(domoticz, device)
domoticz.log('Device ' .. device.name .. ' was changed', domoticz.LOG_INFO)
end
}
How to utilize your code, if lets say i want to set the color when a user variable changing? (I set the variable with a timed blocky event.)
Re: Xiaomi Gateway - Setting light color
Posted: Wednesday 06 December 2017 6:58
by Schorschi
Hi,
i also try to set the colour of the Xiaomi Gateway with a LUA Script.
But i can only set the brightness with:
commandArray['Xiaomi RGB Gateway']='Set Level:100'
I also tried to set RGB values with Set Level but it does not work.
I don't know which command is needed to set this configuration.
Can some one explain me how to find out this information? Maybe also basicaly how to do it on other devices?
Logfile only shows Set Level if i change the colour in the web interface.
thx.
Re: Xiaomi Gateway - Setting light color
Posted: Wednesday 06 December 2017 14:00
by Schorschi
Hello,
i am again.
I also tried this in my lua script:
Code: Select all
local sceneCmd = 'curl -s -i -H "Accept: application/json" "http://192.168.178.55:9898/json.htm?type=command¶m=setcolbrightnessvalue&idx=1&hue=236&brightness=100&iswhite=false"'
exec_success = os.execute(sceneCmd)
But the LED light don't switch on and the variable exec_success is nul.
How can i test this os command separately?
If i try it on my console and get no error.
Domosticz is running on an raspi 1. And connected to Xiaomi Gateway V2.
Any ideas?
Thx.
Re: Xiaomi Gateway - Setting light color
Posted: Wednesday 06 December 2017 14:19
by DAVIZINHO
y use this comand in a dzvents script and works perfect
Re: Xiaomi Gateway - Setting light color
Posted: Thursday 07 December 2017 10:15
by Schorschi
Hi,
i get running this command in my lua device script.
But sometimes i get an error => scirpt run for more then 10 seconds ....
Is my raspi 1 to slow???
Some one same experiance? Maybe any ideas?
Thx.
Re: Xiaomi Gateway - Setting light color
Posted: Monday 12 February 2018 13:00
by QSKONE
Hi,
Can you add some printscreens = examples how they work?
Thanks
Re: Xiaomi Gateway - Setting light color
Posted: Monday 12 February 2018 15:30
by Schorschi
Hi,
here an example of my lua script.
Addapt your ip and port of your domoticz device
Code: Select all
Red = 0xFF0000 --(255,0,0)
GatewayColour = Red
local sceneCmd = 'curl -s -i -H "Accept: application/json" "http://192.168.10.1:8080/json.htm?type=command¶m=setcolbrightnessvalue&idx=1&hex=0x'..string.format("%x", GatewayColour)..'&brightness=100&iswhite=false"'
os.execute(sceneCmd)
Re: Xiaomi Gateway - Setting light color
Posted: Tuesday 13 February 2018 16:56
by QSKONE
Thanks mate, but i am absolute beginner , try to write first script ever .Can you add complete from A to Z script?
Re: Xiaomi Gateway - Setting light color
Posted: Tuesday 13 February 2018 17:40
by hekm77
QSKONE wrote: ↑Tuesday 13 February 2018 16:56
If interesting, You can try.
You must create two Dummy Switch, type - Dimmer:
miGateway Hue and
miGateway Bri
In the script , enter your username, password, ip and port domoticz.
- Spoiler: show
- 111.png (94.86 KiB) Viewed 6546 times
dzVents 2.4.x
- Spoiler: show
Code: Select all
return {
on = {
devices = {
'miGateway Hue',
'miGateway Bri'
}
},
logging = {
level = domoticz.LOG_ERROR
},
execute = function(dz, item)
local Gateway = dz.devices('Xiaomi Gateway RGB')
local HueDevice = dz.devices('miGateway Hue')
local BriDevice = dz.devices('miGateway Bri')
url = "http://username:password@ip_ddomoticz:port_domoticz/json.htm?type=command&dparam=setcolbrightnessvalue&"
if HueValue == nil then HueValue = 0 end
if BriValue == nil then BriValue = 0 end
function GatewayOn()
SetScene = 'curl -s '..'"'..url..'idx="'..Gateway.idx..'"&hue="'..HueValue..'"&brightness="'..BriValue..'"&iswhite=false" &'
dz.utils.osExecute('('..SetScene..' > /dev/null)&')
end
HueValue = dz.utils.round(HueDevice.level * 3.59),0
BriValue = BriDevice.level
if (item.name == 'miGateway Hue') then
if (item.state ~= 'Off') then
if (BriDevice.state == 'Off') then
BriValue = BriDevice.lastLevel
GatewayOn()
BriDevice.dimTo(BriDevice.lastLevel).silent()
item.dimTo(item.level).silent()
else
GatewayOn()
end
else
Gateway.switchOff().checkFirst().silent()
BriDevice.switchOff().checkFirst().silent()
end
end
if (item.name == 'miGateway Bri') then
if (item.state ~= 'Off') then
if (HueDevice.state == 'Off') then
HueValue = dz.utils.round(HueDevice.lastLevel * 3.59),0
GatewayOn()
HueDevice.dimTo(HueDevice.lastLevel).silent()
item.dimTo(item.level).silent()
else
GatewayOn()
end
else
Gateway.switchOff().checkFirst().silent()
HueDevice.switchOff().checkFirst().silent()
end
end
end
}
Re: Xiaomi Gateway - Setting light color
Posted: Tuesday 13 February 2018 20:20
by QSKONE
hekm77 many thanks. Domoticz Xiaomi Wiki must including your script because it's very helpful.
Re: Xiaomi Gateway - Setting light color
Posted: Monday 04 June 2018 2:44
by MarnixO
On a Synology i got an error :
2018-06-04 02:37:37.094 Error: dzVents: Error: ...icz/var/scripts/dzVents/generated_scripts/Xiaomi RGB.lua:26: attempt to index field 'utils' (a nil value)
Re: Xiaomi Gateway - Setting light color
Posted: Wednesday 19 September 2018 22:13
by Schorschi
Hi,
to set color for the xiaomi gateway is not working in the last domoticz beta and current gateway fw.
I try it with my old script but can't change the color. The gateway switch always to the last manually selected color.
Code: Select all
---------------------------------------------------------------------------------------------------
-- Gateway Colour
commandArray['Xiaomi_RGB_Gateway']='Set Level:'..tostring(GatewayBrightness) -- set brightness LED light from Gateway
-- change colour of gateway
local sceneCmd = 'curl -s -i -H "Accept: application/json" "http://192.168.178.62:8083/json.htm?
type=command¶m=setcolbrightnessvalue&idx=1&hex=0x'..string.format("%x", GatewayColour)..'&brightness=100&iswhite=false"'
os.execute(sceneCmd)
any idea?