Qmotion Blinds

I added another 4 Qmotion blinds two weeks ago, and have updated the procedure below with all 15 channels (although I am only using 11). I also added in check of an associated device - meaning a window sensor - before I move any roller shade. If the window is closed, the command is sent, but if the window is open, nothing is transmitted. That way if the window is open, the shade can only be moved manually (well not via Vera anyway), but if closed they move the position dictated by Vera. You should customize as needed, of course…

function MoveQMotionShades(ParamString)

	local shadeChar,openAmtChar = string.match(ParamString,"(%d+),(%d+)")
	local shadeNum = tonumber(shadeChar)
	local openAmtNum = tonumber(openAmtChar)
	local CommandtoSend

	if shadeNum == 1 then
		local tripped = luup.variable_get( "urn:micasaverde-com:serviceId:SecuritySensor1", "Tripped", 26)
		if tripped == "0" then
			if openAmtNum == 100 		then CommandtoSend= string.char(0x01,0x07,0x00,0x05,0x01,0x01,0x01,0x00,0xFC) -- Channel 1 Up
			elseif openAmtNum == 75 	then CommandtoSend= string.char(0x01,0x07,0x00,0x05,0x01,0x01,0x04,0x00,0xF9) -- Channel 1 75% Up
			elseif openAmtNum == 50	then CommandtoSend= string.char(0x01,0x07,0x00,0x05,0x01,0x01,0x08,0x00,0xF5) -- Channel 1 50% Up
			elseif openAmtNum == 25	then CommandtoSend= string.char(0x01,0x07,0x00,0x05,0x01,0x01,0x0C,0x00,0xF1) -- Channel 1 25% Up
			elseif openAmtNum == 0 	then CommandtoSend= string.char(0x01,0x07,0x00,0x05,0x01,0x01,0x02,0x00,0xFF) -- Channel 1 Down
			end
		end
	elseif shadeNum == 2 then
		local tripped = luup.variable_get( "urn:micasaverde-com:serviceId:SecuritySensor1", "Tripped", 27)
		if tripped == "0" then
			if openAmtNum == 100 		then CommandtoSend= string.char(0x01,0x07,0x00,0x05,0x01,0x02,0x01,0x00,0xFF) -- Channel 2 Up
			elseif openAmtNum == 75 	then CommandtoSend= string.char(0x01,0x07,0x00,0x05,0x01,0x02,0x04,0x00,0xFA) -- Channel 2 75% Up
			elseif openAmtNum == 50	then CommandtoSend= string.char(0x01,0x07,0x00,0x05,0x01,0x02,0x08,0x00,0xF6) -- Channel 2 50% Up
			elseif openAmtNum == 25	then CommandtoSend= string.char(0x01,0x07,0x00,0x05,0x01,0x02,0x0C,0x00,0xF2) -- Channel 2 25% Up
			elseif openAmtNum == 0 	then CommandtoSend= string.char(0x01,0x07,0x00,0x05,0x01,0x02,0x02,0x00,0xFC) -- Channel 2 Down
			end
		end
	elseif shadeNum == 3 then
		local tripped = luup.variable_get( "urn:micasaverde-com:serviceId:SecuritySensor1", "Tripped", 28)
		if tripped == "0" then
			if openAmtNum == 100 		then CommandtoSend= string.char(0x01,0x07,0x00,0x05,0x01,0x03,0x01,0x00,0xFE) -- Channel 3 Up
			elseif openAmtNum == 75 	then CommandtoSend= string.char(0x01,0x07,0x00,0x05,0x01,0x03,0x04,0x00,0xFB) -- Channel 3 75% Up
			elseif openAmtNum == 50	then CommandtoSend= string.char(0x01,0x07,0x00,0x05,0x01,0x03,0x08,0x00,0xF7) -- Channel 3 50% Up
			elseif openAmtNum == 25	then CommandtoSend= string.char(0x01,0x07,0x00,0x05,0x01,0x03,0x0C,0x00,0xF3) -- Channel 3 25% Up
			elseif openAmtNum == 0 	then CommandtoSend= string.char(0x01,0x07,0x00,0x05,0x01,0x03,0x02,0x00,0xFD) -- Channel 3 Down
			end
		end
	elseif shadeNum == 4 then
		local tripped = luup.variable_get( "urn:micasaverde-com:serviceId:SecuritySensor1", "Tripped", 21)
		if tripped == "0" then
			if openAmtNum == 100 		then CommandtoSend= string.char(0x01,0x07,0x00,0x05,0x01,0x04,0x01,0x00,0xF9) -- Channel 4 Up
			elseif openAmtNum == 75 	then CommandtoSend= string.char(0x01,0x07,0x00,0x05,0x01,0x04,0x04,0x00,0xFC) -- Channel 4 75% Up
			elseif openAmtNum == 50	then CommandtoSend= string.char(0x01,0x07,0x00,0x05,0x01,0x04,0x08,0x00,0xF0) -- Channel 4 50% Up
			elseif openAmtNum == 25	then CommandtoSend= string.char(0x01,0x07,0x00,0x05,0x01,0x04,0x0C,0x00,0xF4) -- Channel 4 25% Up
			elseif openAmtNum == 0 	then CommandtoSend= string.char(0x01,0x07,0x00,0x05,0x01,0x04,0x02,0x00,0xFA) -- Channel 4 Down
			end
		end
	elseif shadeNum == 5 then
	-- Non-opening window, no need to check sensor
			if openAmtNum == 100 		then CommandtoSend= string.char(0x01,0x07,0x00,0x05,0x01,0x05,0x01,0x00,0xF8) -- Channel 5 Up
			elseif openAmtNum == 75 	then CommandtoSend= string.char(0x01,0x07,0x00,0x05,0x01,0x05,0x04,0x00,0xFD) -- Channel 5 75% Up
			elseif openAmtNum == 50	then CommandtoSend= string.char(0x01,0x07,0x00,0x05,0x01,0x05,0x08,0x00,0xF1) -- Channel 5 50% Up
			elseif openAmtNum == 25	then CommandtoSend= string.char(0x01,0x07,0x00,0x05,0x01,0x05,0x0C,0x00,0xF5) -- Channel 5 25% Up
			elseif openAmtNum == 0 	then CommandtoSend= string.char(0x01,0x07,0x00,0x05,0x01,0x05,0x02,0x00,0xFB) -- Channel 5 Down
			end
	elseif shadeNum == 6 then
		local tripped = luup.variable_get( "urn:micasaverde-com:serviceId:SecuritySensor1", "Tripped", 25)
		if tripped == "0" then
			if openAmtNum == 100 		then CommandtoSend= string.char(0x01,0x07,0x00,0x05,0x01,0x06,0x01,0x00,0xFB) -- Channel 6 Up
			elseif openAmtNum == 75 	then CommandtoSend= string.char(0x01,0x07,0x00,0x05,0x01,0x06,0x04,0x00,0xFE) -- Channel 6 75% Up
			elseif openAmtNum == 50	then CommandtoSend= string.char(0x01,0x07,0x00,0x05,0x01,0x06,0x08,0x00,0xF2) -- Channel 6 50% Up
			elseif openAmtNum == 25	then CommandtoSend= string.char(0x01,0x07,0x00,0x05,0x01,0x06,0x0C,0x00,0xF6) -- Channel 6 25% Up
			elseif openAmtNum == 0 	then CommandtoSend= string.char(0x01,0x07,0x00,0x05,0x01,0x06,0x02,0x00,0xF8) -- Channel 6 Down
			end
		end
	elseif shadeNum == 7 then
		local tripped = luup.variable_get( "urn:micasaverde-com:serviceId:SecuritySensor1", "Tripped", 22)
		if tripped == "0" then
			if openAmtNum == 100 		then CommandtoSend= string.char(0x01,0x07,0x00,0x05,0x01,0x07,0x01,0x00,0xFA) -- Channel 7 Up
			elseif openAmtNum == 75 	then CommandtoSend= string.char(0x01,0x07,0x00,0x05,0x01,0x07,0x04,0x00,0xFF) -- Channel 7 75% Up
			elseif openAmtNum == 50	then CommandtoSend= string.char(0x01,0x07,0x00,0x05,0x01,0x07,0x08,0x00,0xF3) -- Channel 7 50% Up
			elseif openAmtNum == 25	then CommandtoSend= string.char(0x01,0x07,0x00,0x05,0x01,0x07,0x0C,0x00,0xF7) -- Channel 7 25% Up
			elseif openAmtNum == 0 	then CommandtoSend= string.char(0x01,0x07,0x00,0x05,0x01,0x07,0x02,0x00,0xF9) -- Channel 7 Down
			end
		end
	elseif shadeNum == 8 then
		local tripped = luup.variable_get( "urn:micasaverde-com:serviceId:SecuritySensor1", "Tripped", 23)
		if tripped == "0" then
			if openAmtNum == 100 		then CommandtoSend= string.char(0x01,0x07,0x00,0x05,0x01,0x08,0x01,0x00,0xF5) -- Channel 8 Up
			elseif openAmtNum == 75 	then CommandtoSend= string.char(0x01,0x07,0x00,0x05,0x01,0x08,0x04,0x00,0xF0) -- Channel 8 75% Up
			elseif openAmtNum == 50	then CommandtoSend= string.char(0x01,0x07,0x00,0x05,0x01,0x08,0x08,0x00,0xFC) -- Channel 8 50% Up
			elseif openAmtNum == 25	then CommandtoSend= string.char(0x01,0x07,0x00,0x05,0x01,0x08,0x0C,0x00,0xF8) -- Channel 8 25% Up
			elseif openAmtNum == 0 	then CommandtoSend= string.char(0x01,0x07,0x00,0x05,0x01,0x08,0x02,0x00,0xF6) -- Channel 8 Down
			end
		end
	elseif shadeNum == 9 then
		local tripped = luup.variable_get( "urn:micasaverde-com:serviceId:SecuritySensor1", "Tripped", 23)
		if tripped == "0" then
			if openAmtNum == 100 		then CommandtoSend= string.char(0x01,0x07,0x00,0x05,0x01,0x09,0x01,0x00,0xF4) -- Channel 9 Up
			elseif openAmtNum == 75 	then CommandtoSend= string.char(0x01,0x07,0x00,0x05,0x01,0x09,0x04,0x00,0xF1) -- Channel 9 75% Up
			elseif openAmtNum == 50	then CommandtoSend= string.char(0x01,0x07,0x00,0x05,0x01,0x09,0x08,0x00,0xFD) -- Channel 9 50% Up
			elseif openAmtNum == 25	then CommandtoSend= string.char(0x01,0x07,0x00,0x05,0x01,0x09,0x0C,0x00,0xF9) -- Channel 9 25% Up
			elseif openAmtNum == 0 	then CommandtoSend= string.char(0x01,0x07,0x00,0x05,0x01,0x09,0x02,0x00,0xF7) -- Channel 9 Down
			end
		end
	elseif shadeNum == 10 then
		local tripped = luup.variable_get( "urn:micasaverde-com:serviceId:SecuritySensor1", "Tripped", 24)
		if tripped == "0" then
			if openAmtNum == 100 		then CommandtoSend= string.char(0x01,0x07,0x00,0x05,0x01,0x0A,0x01,0x00,0xF7) -- Channel 10/A Up
			elseif openAmtNum == 75 	then CommandtoSend= string.char(0x01,0x07,0x00,0x05,0x01,0x0A,0x04,0x00,0xF2) -- Channel 10/A 75% Up
			elseif openAmtNum == 50	then CommandtoSend= string.char(0x01,0x07,0x00,0x05,0x01,0x0A,0x08,0x00,0xFE) -- Channel 10/A 50% Up
			elseif openAmtNum == 25	then CommandtoSend= string.char(0x01,0x07,0x00,0x05,0x01,0x0A,0x0C,0x00,0xFA) -- Channel 10/A 25% Up
			elseif openAmtNum == 0 	then CommandtoSend= string.char(0x01,0x07,0x00,0x05,0x01,0x0A,0x02,0x00,0xF4) -- Channel 10/A Down
			end
		end
	elseif shadeNum == 11 then
		local tripped = luup.variable_get( "urn:micasaverde-com:serviceId:SecuritySensor1", "Tripped", 24)
		if tripped == "0" then
			if openAmtNum == 100 		then CommandtoSend= string.char(0x01,0x07,0x00,0x05,0x01,0x0B,0x01,0x00,0xF6) -- Channel 11/B Up
			elseif openAmtNum == 75 	then CommandtoSend= string.char(0x01,0x07,0x00,0x05,0x01,0x0B,0x04,0x00,0xF3) -- Channel 11/B 75% Up
			elseif openAmtNum == 50	then CommandtoSend= string.char(0x01,0x07,0x00,0x05,0x01,0x0B,0x08,0x00,0xFF) -- Channel 11/B 50% Up
			elseif openAmtNum == 25	then CommandtoSend= string.char(0x01,0x07,0x00,0x05,0x01,0x0B,0x0C,0x00,0xFB) -- Channel 11/B 25% Up
			elseif openAmtNum == 0 	then CommandtoSend= string.char(0x01,0x07,0x00,0x05,0x01,0x0B,0x02,0x00,0xF5) -- Channel 11/B Down
			end
		end
	elseif shadeNum == 12 then
	-- Future Use
			if openAmtNum == 100 		then CommandtoSend= string.char(0x01,0x07,0x00,0x05,0x01,0x0C,0x01,0x00,0xF1) -- Channel 12/C Up
			elseif openAmtNum == 75 	then CommandtoSend= string.char(0x01,0x07,0x00,0x05,0x01,0x0C,0x04,0x00,0xF4) -- Channel 12/C 75% Up
			elseif openAmtNum == 50	then CommandtoSend= string.char(0x01,0x07,0x00,0x05,0x01,0x0C,0x08,0x00,0xF8) -- Channel 12/C 50% Up
			elseif openAmtNum == 25	then CommandtoSend= string.char(0x01,0x07,0x00,0x05,0x01,0x0C,0x0C,0x00,0xFC) -- Channel 12/C 25% Up
			elseif openAmtNum == 0 	then CommandtoSend= string.char(0x01,0x07,0x00,0x05,0x01,0x0C,0x02,0x00,0xF2) -- Channel 12/C Down
			end
	elseif shadeNum == 13 then
	-- Future Use
			if openAmtNum == 100 		then CommandtoSend= string.char(0x01,0x07,0x00,0x05,0x01,0x0D,0x01,0x00,0xF0) -- Channel 13/D Up
			elseif openAmtNum == 75 	then CommandtoSend= string.char(0x01,0x07,0x00,0x05,0x01,0x0D,0x04,0x00,0xF5) -- Channel 13/D 75% Up
			elseif openAmtNum == 50	then CommandtoSend= string.char(0x01,0x07,0x00,0x05,0x01,0x0D,0x08,0x00,0xF9) -- Channel 13/D 50% Up
			elseif openAmtNum == 25	then CommandtoSend= string.char(0x01,0x07,0x00,0x05,0x01,0x0D,0x0C,0x00,0xFD) -- Channel 13/D 25% Up
			elseif openAmtNum == 0 	then CommandtoSend= string.char(0x01,0x07,0x00,0x05,0x01,0x0D,0x02,0x00,0xF3) -- Channel 13/D Down
			end
	elseif shadeNum == 14 then
	-- Future Use
			if openAmtNum == 100 		then CommandtoSend= string.char(0x01,0x07,0x00,0x05,0x01,0x0E,0x01,0x00,0xF3) -- Channel 14/E Up
			elseif openAmtNum == 75 	then CommandtoSend= string.char(0x01,0x07,0x00,0x05,0x01,0x0E,0x04,0x00,0xF6) -- Channel 14/E 75% Up
			elseif openAmtNum == 50	then CommandtoSend= string.char(0x01,0x07,0x00,0x05,0x01,0x0E,0x08,0x00,0xFA) -- Channel 14/E 50% Up
			elseif openAmtNum == 25	then CommandtoSend= string.char(0x01,0x07,0x00,0x05,0x01,0x0E,0x0C,0x00,0xFE) -- Channel 14/E 25% Up
			elseif openAmtNum == 0 	then CommandtoSend= string.char(0x01,0x07,0x00,0x05,0x01,0x0E,0x02,0x00,0xF0) -- Channel 14/E Down
			end
	elseif shadeNum == 15 then
-- Future Use
			if openAmtNum == 100 		then CommandtoSend= string.char(0x01,0x07,0x00,0x05,0x01,0x0F,0x01,0x00,0xF2) -- Channel 15/F Up
			elseif openAmtNum == 75 	then CommandtoSend= string.char(0x01,0x07,0x00,0x05,0x01,0x0F,0x04,0x00,0xF7) -- Channel 15/F 75% Up
			elseif openAmtNum == 50	then CommandtoSend= string.char(0x01,0x07,0x00,0x05,0x01,0x0F,0x08,0x00,0xFB) -- Channel 15/F 50% Up
			elseif openAmtNum == 25	then CommandtoSend= string.char(0x01,0x07,0x00,0x05,0x01,0x0F,0x0C,0x00,0xFF) -- Channel 15/F 25% Up
			elseif openAmtNum == 0 	then CommandtoSend= string.char(0x01,0x07,0x00,0x05,0x01,0x0F,0x02,0x00,0xF1) -- Channel 15/F Down
			end
	end


	-- Connect and Send Command

	local socket = require("socket")
	host = "192.168.0.123"
	c = assert(socket.connect(host, 4999))
	c:settimeout(5)

	local sres, serr = c:send(CommandtoSend)
	print("Send:", sres, serr)
	local data, rerr = c:receive(5)
	luup.log (data)
	print ("Receive:", data, rerr)

	c:close()

end

As before it is called as

MoveQMotionShades ("10,25")

or if you want a delay

luup.call_delay("MoveQMotionShades",40,"10,25")

And this is designed to work with a Global Cache iTach IP2SL connected to a Qmotion Qconnect via custom serial cable. This config allows Vera control via IP, as well as control via other applications like iRule custom remote controls.