Xiaomi Gateway - Setting light color

Post Reply
misfit
Posts: 15
Joined: Wednesday 29 November 2017 12:03
Target OS: Raspberry Pi
Domoticz version:
Contact:

Xiaomi Gateway - Setting light color

Post by misfit » Sunday 03 December 2017 14:26

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: 85
Joined: Sunday 27 August 2017 18:00
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Xiaomi Gateway - Setting light color

Post by DAVIZINHO » Sunday 03 December 2017 15:54

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: 15
Joined: Wednesday 29 November 2017 12:03
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Xiaomi Gateway - Setting light color

Post by misfit » Monday 04 December 2017 20:07

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: 28
Joined: Thursday 30 November 2017 23:09
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Xiaomi Gateway - Setting light color

Post by Schorschi » Wednesday 06 December 2017 7:58

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: 28
Joined: Thursday 30 November 2017 23:09
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Xiaomi Gateway - Setting light color

Post by Schorschi » Wednesday 06 December 2017 15:00

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: 85
Joined: Sunday 27 August 2017 18:00
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Xiaomi Gateway - Setting light color

Post by DAVIZINHO » Wednesday 06 December 2017 15:19

y use this comand in a dzvents script and works perfect

Schorschi
Posts: 28
Joined: Thursday 30 November 2017 23:09
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Xiaomi Gateway - Setting light color

Post by Schorschi » Thursday 07 December 2017 11:15

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: 3
Joined: Monday 12 February 2018 13:56
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Xiaomi Gateway - Setting light color

Post by QSKONE » Monday 12 February 2018 14:00

Hi,
Can you add some printscreens = examples how they work?
Thanks

Schorschi
Posts: 28
Joined: Thursday 30 November 2017 23:09
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Xiaomi Gateway - Setting light color

Post by Schorschi » Monday 12 February 2018 16:30

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: 3
Joined: Monday 12 February 2018 13:56
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Xiaomi Gateway - Setting light color

Post by QSKONE » Tuesday 13 February 2018 17:56

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 19:31
Target OS: Raspberry Pi
Domoticz version: beta
Contact:

Re: Xiaomi Gateway - Setting light color

Post by hekm77 » Tuesday 13 February 2018 18:40

QSKONE wrote:
Tuesday 13 February 2018 17: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 312 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:[email protected]_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: 3
Joined: Monday 12 February 2018 13:56
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Xiaomi Gateway - Setting light color

Post by QSKONE » Tuesday 13 February 2018 21:20

hekm77 many thanks. Domoticz Xiaomi Wiki must including your script because it's very helpful.

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests