Xiaomi Gateway - Setting light color

Moderator: leecollings

Post Reply
misfit
Posts: 18
Joined: Wednesday 29 November 2017 11:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Xiaomi Gateway - Setting light color

Post 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!
DAVIZINHO
Posts: 234
Joined: Sunday 27 August 2017 18:00
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Spain
Contact:

Re: Xiaomi Gateway - Setting light color

Post 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&param=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)
misfit
Posts: 18
Joined: Wednesday 29 November 2017 11:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Xiaomi Gateway - Setting light color

Post 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.)
Schorschi
Posts: 25
Joined: Thursday 30 November 2017 22:09
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Xiaomi Gateway - Setting light color

Post 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.
Schorschi
Posts: 25
Joined: Thursday 30 November 2017 22:09
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Xiaomi Gateway - Setting light color

Post 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&param=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.
DAVIZINHO
Posts: 234
Joined: Sunday 27 August 2017 18:00
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Spain
Contact:

Re: Xiaomi Gateway - Setting light color

Post by DAVIZINHO »

y use this comand in a dzvents script and works perfect
Schorschi
Posts: 25
Joined: Thursday 30 November 2017 22:09
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Xiaomi Gateway - Setting light color

Post 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.
QSKONE
Posts: 38
Joined: Monday 12 February 2018 12:56
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: Xiaomi Gateway - Setting light color

Post by QSKONE »

Hi,
Can you add some printscreens = examples how they work?
Thanks
Schorschi
Posts: 25
Joined: Thursday 30 November 2017 22:09
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Xiaomi Gateway - Setting light color

Post 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&param=setcolbrightnessvalue&idx=1&hex=0x'..string.format("%x", GatewayColour)..'&brightness=100&iswhite=false"'
		os.execute(sceneCmd)
QSKONE
Posts: 38
Joined: Monday 12 February 2018 12:56
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: Xiaomi Gateway - Setting light color

Post by QSKONE »

Thanks mate, but i am absolute beginner , try to write first script ever .Can you add complete from A to Z script?
hekm77
Posts: 45
Joined: Thursday 09 February 2017 18:31
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Contact:

Re: Xiaomi Gateway - Setting light color

Post 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
111.png (94.86 KiB) Viewed 6540 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
}
QSKONE
Posts: 38
Joined: Monday 12 February 2018 12:56
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: Xiaomi Gateway - Setting light color

Post by QSKONE »

hekm77 many thanks. Domoticz Xiaomi Wiki must including your script because it's very helpful.
MarnixO
Posts: 18
Joined: Sunday 24 September 2017 12:02
Target OS: Raspberry Pi / ODroid
Domoticz version: V4.10199
Location: Destelbergen Belgium
Contact:

Re: Xiaomi Gateway - Setting light color

Post 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)
Schorschi
Posts: 25
Joined: Thursday 30 November 2017 22:09
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Xiaomi Gateway - Setting light color

Post 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&param=setcolbrightnessvalue&idx=1&hex=0x'..string.format("%x", GatewayColour)..'&brightness=100&iswhite=false"'
		os.execute(sceneCmd)

any idea?
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests