X10 Interface usage via Caddx Plugin

I have been able to test and use the X10 protocol via Home Automation and Telnet. Has anyone started working to integrate this into the Caddx Plugin?

Update:

Created the ability to send X10 messages through scenes; will post once I get the code polished a little more.

Great news. Let me know if you want to have it incorporated into the official plugin. It’s GPL licensed.

Yes, please incorporate in the project.

I have created the ability to use scenes to turn a light on/off via X10 interface using the same technique as arm modes.

I don’t really understand Lua… couldn’t figure out how to have a light device invoke. Perhapes you have a better understanding of the language and can make the necessary connections. Three general edits:

I_CaddxNX584Security.xml:

–Add–

urn:futzle-com:serviceId:CaddxNX584Security1
UserSendX10

return plugin.jobUserSendX10(lul_device, lul_settings, lul_job)


return plugin.handleReadByteResult(lul_job, lul_device, plugin.readByte(lul_data))

L_CaddxNX584Security.lua
–Add–
– jobUserSendX10(lul_device, lul_settings, lul_job)
– Invoked by advanced scene settings for Caddx
function jobUserSendX10(lul_device, lul_settings, lul_job)
debug("Job: Alarm: UserSendX10: HouseCode: " .. lul_settings.HouseCode .. " UnitCode: " .. lul_settings.UnitCode .. " FunctionCode: " .. lul_settings.X10FunctionCode .. " " .. lul_device .. " job " .. getJobId(lul_job))

--Validate HouseCode Input
--Length and Value
if (string.len(lul_settings.HouseCode) > 1 or string.byte(string.upper(lul_settings.HouseCode)) > 65 or string.byte(string.upper(lul_settings.HouseCode)) < 50 ) then
	 --House code entered was not A-P
	 debug("UserSendX10: Improper HouseCode provided")
	 debug("UserSendX10: Length: " .. string.len(lul_settings.HouseCode))
	 debug("UserSendX10: House Code Value (acceptable ragne 50 - 65): " .. string.byte(string.upper(lul_settings.HouseCode)))
	 return 2, nil
end

--Validate UnitCode Input
--Value
if tonumber(lul_settings.UnitCode) < 1 or tonumber(lul_settings.UnitCode) > 16 then
	 --Unit code entered was not 1-16
	 debug("UserSendX10: Improper UnitCode provided")
	 return 2, nil
end

--Validate X10FunctionCode
--Value
local X10FunctionCodeValue = 0 
if lul_settings.X10FunctionCode == "All units off" then X10FunctionCodeValue = 8
	elseif lul_settings.X10FunctionCode == "All lights on" then X10FunctionCodeValue = 24
	elseif lul_settings.X10FunctionCode == "On" then X10FunctionCodeValue = 40
	elseif lul_settings.X10FunctionCode == "Off" then X10FunctionCodeValue = 56
	elseif lul_settings.X10FunctionCode == "Dim" then X10FunctionCodeValue = 88
	elseif lul_settings.X10FunctionCode == "Bright" then X10FunctionCodeValue = 72
	elseif lul_settings.X10FunctionCode == "All lights off" then X10FunctionCodeValue = 104
	else
		X10FunctionCodeValue = nil
		debug("UserSendX10: Improper X10FunctionCode provided")
		return 2, nil
end		

local houseCode = string.byte(lul_settings.HouseCode) - 65
if (houseCode == nil) then return 2, nil end

local unitCode = tonumber(lul_settings.UnitCode) - 1
if (unitCode == nil) then return 2, nil end

local X10FunctionCode = X10FunctionCodeValue
if (X10FunctionCodeValue == nil) then return 2, nil end

-- Ask for this log entry.
addPendingJob(getJobId(lul_job),
	"\041" .. string.char(houseCode) .. string.char(unitCode) .. string.char(X10FunctionCode),
	{
		[29] = function(deviceId, message)
			-- Nothing more to do.  The interface will
			-- send a snapshot with the updated info RSN,
			-- and we'll update the partition device then.
			return pendingJobDone(getJobId(lul_job), 4)
		end,
		[31] = function(deviceId, message)
			return pendingJobDone(getJobId(lul_job), 2)
		end,
	}
)
debug("Job: Processing send queue")
processSendQueue()
debug("Job: Started")
-- Either the timeout or incoming task will be called next.
return 5, 10

end

S_CaddxNX584Security.xml

–Add–

UserSendX10


HouseCode
in
string


UnitCode
in
ui4


X10FunctionCode
in
string


Hi brandonharville,

That seems pretty straightforward. House Code is a letter A to P inclusive, right? Just not sure why you’re comparing with 50 (ASCII “2”) rather than 80 (ASCII “P”).

Does the alarm interface return a 0x1D Positive Acknowledge on success? The code [29] suggests yes, just like other messages.

Is there any way to know if the command succeeded (i.e., it turned on the light)? My limited understanding of X10 is that this isn’t supported by the protocol.

Related: There’s a message 0x09 X10 Command Received. Is this what you mean by “have a light device invoke”? Is the 0x09 message something that you want the plugin to be able to react to?

(Edit: missing words)

Typo: ASCII 50 should be ASCII 90.

In regards to acknowledgement this is what I get back:

08 07/26/14 8:51:30.910 JobHandler_LuaUPnP::HandleActionRequest device: 0 service: urn:micasaverde-com:serviceId:HomeAutomationGateway1 action: RunScene <0x2d329680>
08 07/26/14 8:51:30.910 JobHandler_LuaUPnP::HandleActionRequest argument SceneNum=11 <0x2d329680>
08 07/26/14 8:51:30.910 Scene::RunScene running 11 FR Light On <0x2d329680>
08 07/26/14 8:51:30.911 JobHandler_LuaUPnP::HandleActionRequest device: 4 service: urn:futzle-com:serviceId:CaddxNX584Security1 action: UserSendX10 <0x2d329680>
08 07/26/14 8:51:30.911 JobHandler_LuaUPnP::HandleActionRequest argument HouseCode=A <0x2d329680>
08 07/26/14 8:51:30.911 JobHandler_LuaUPnP::HandleActionRequest argument UnitCode=3 <0x2d329680>
08 07/26/14 8:51:30.911 JobHandler_LuaUPnP::HandleActionRequest argument X10FunctionCode=On <0x2d329680>
50 07/26/14 8:51:30.915 luup_log:3: Job: Alarm: UserSendX10: HouseCode: A UnitCode: 3 FunctionCode: On 4 job userdata: 0xb03010 <0x2b1f6000>
50 07/26/14 8:51:30.916 luup_log:3: Job: Processing send queue <0x2b1f6000>
50 07/26/14 8:51:30.916 luup_log:3: Message: Outgoing: 0x7e 0x04 0x29 0x00 0x02 0x28 0x57 0xe4 <0x2b1f6000>
50 07/26/14 8:51:30.917 luup_log:3: Job: Started <0x2b1f6000>
50 07/26/14 8:51:31.156 luup_log:3: Received good message 0x1d <0x2db29680>
50 07/26/14 8:51:31.157 luup_log:3: Message: Incoming message body: <0x2db29680>
50 07/26/14 8:51:31.157 luup_log:3: Finishing pending job userdata: 0xb03010 <0x2db29680>
04 07/26/14 8:51:31.158 <0x2db29680>

I don’t believe the interface supports confirmation that the action took place. The Caddx X10 interface is one way.

My question regarding “invoking” was in regards to getting a “Light” device setup. Not really sure how to approach this.

How about we split the difference and call it 80? I don’t believe that house codes Q to Z are valid in X10?

My question regarding "invoking" was in regards to getting a "Light" device setup. Not really sure how to approach this.

You’ll have to spell out what you’re talking about in more detail. I’m not familiar with X10 or with Caddx’s implementation of it. Here’s how I interpreted your paragraph: you want to make the plugin act like an X10 light so that it can react to a command from a controller elsewhere in the house.

Its really a Veralite question.

For example:

You can enable X10 Insteon interface on the Veralite. This allows the user to add “Light” Devices…

I dont know how to allow a user to add a “Light” device to the Veralite dashboard to interface with a light through the Caddx system via X10.

Oh, I get it, you want child devices on the dashboard, for outgoing control of X10 devices in your house, just like there are already child devices on the dashboard for the zones and partitions. You’re right, that’s a fair bit of work, and (sorry) work that won’t be done by me. It’s definitely doable. Presupposing that you are already familiar with Lua and JavaScript, with lots of liberal copying and pasting from the existing plugin code, it should “only” take you a few days to code and test.

Ill keep you posted as I work on this. In the mean time, do you think you can include the X10 items I posted earlier in the next rev?

Yes, absolutely.

Just upgraded to 80; noticed none of the X10 has been added yet.

Is it possible this could get added in the next release? I’m trying to keep from having to do manual updates.

Sorry, I’ve now submitted version 81 to code.mios.com. The action also needed to be added to D_CaddxNX584Security.json but for reasons I haven’t yet figured out it isn’t appearing in UI7’s scene device list.