Index: /L_sPhoneUI.lua
===================================================================
--- /L_sPhoneUI.lua	(revision 20)
+++ /L_sPhoneUI.lua	(revision 30)
@@ -5,7 +5,17 @@
 		return
 	end
+	
+	sPh_LAYOUT_PFX = 'https://download1.mios.com/L_sPhoneUI_layout'
+	g_is_remote = 0
 
 	function string:template(variables)
-		return (self:gsub('%%{(.-)}%%', function (key) return tostring(variables[key] or '') end))
+		return (self:gsub('{%%(.-)%%}', function (key) return tostring(variables[key] or _G[key] or '') end))
+	end
+	
+	function flag(v)
+		if( v==nil or tonumber(v)==0 ) then
+			return '0'
+		end
+		return '1'
 	end
 
@@ -18,7 +28,7 @@
 	luup.register_handler("lug_sPhoneRequest_action_js","sPhone_action_js")
 
-	luup.log (("L_sPhoneUI running version: %{version_branch}%.%{version_major}%.%{version_minor}%"):template(luup))
-
-	local html_header = [[
+	luup.log (("L_sPhoneUI running version: {%version_branch%}.{%version_major%}.{%version_minor%}"):template(luup))
+
+	local html_header = ([[
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml">
@@ -27,9 +37,9 @@
 		<meta http-equiv="pragma" content="nocache"/>
 		<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0;"/>
-		<script src="/port_3480/L_sPhoneUI_layout/js/mobile.js" language="javascript"></script>
-		<link rel="stylesheet" href="/port_3480/L_sPhoneUI_layout/css/iui.css" type="text/css" />
+		<script src="{%sPh_LAYOUT_PFX%}/js/mobile.js" language="javascript"></script>
+		<link rel="stylesheet" href="{%sPh_LAYOUT_PFX%}/css/iui.css" type="text/css" />
 	</head>
-	<body onLoad="js_prepare_urls();">
-]]
+	<body onLoad="js_prepare_urls();set_layout_prefix('{%sPh_LAYOUT_PFX%}');">
+]]):template ({})
 
 	local html_footer=[[
@@ -37,5 +47,5 @@
 </html>]]
 
-	function list_devices (lul_room, out)
+	function list_devices (lul_room, out, lul_js)
 	
 		local grouphead_inserted = false
@@ -48,5 +58,5 @@
 				end
 				
-				if( v.category_num==2 ) then -- DEVICE_CATEGORY_DIMMABLE_LIGHT
+				if( v.category_num==2 or v.category_num==8 ) then -- DEVICE_CATEGORY_DIMMABLE_LIGHT
 					table.insert (out, '<li class="bg">' .. lug_sPhoneRequest_light(k,v.description,lul_js) .. "</li>\n")
 				elseif( v.category_num==5 ) then -- DEVICE_CATEGORY_HVAC
@@ -58,4 +68,6 @@
 				elseif( v.category_num==17 ) then -- DEVICE_CATEGORY_TEMPERATURE
 					table.insert (out, '<li class="bg">' .. lug_sPhoneRequest_temp(k,v.description,lul_js) .. "</li>\n")
+				elseif( v.category_num==16 ) then -- DEVICE_CATEGORY_HUMIDITY
+					table.insert (out, '<li class="bg">' .. lug_sPhoneRequest_humid(k,v.description,lul_js) .. "</li>\n")
 				elseif( v.category_num==18 ) then -- DEVICE_CATEGORY_LIGHT
 					table.insert (out, '<li class="bg">' .. lug_sPhoneRequest_bright(k,v.description,lul_js) .. "</li>\n")
@@ -70,4 +82,10 @@
 
 	function lug_sPhoneRequest(lul_request,lul_parameters,lul_outputformat)
+		local lul_js = flag(lul_parameters.js)
+		g_is_remote = flag (lul_parameters.r)
+-- 		if( lul_js==nil or tonumber(lul_js)==0 ) then
+-- 			lul_js = 0
+-- 		end
+		luup.log("lul_js = " .. lul_js)
 		local out = {html_header, [[
 		<div id="toolbar" class="toolbar"><!--logout_btn--></div>
@@ -81,12 +99,12 @@
 				if not scene_grouphead_inserted then
 					table.insert (out, '<li class="group">Scenes</li>')
+					scene_grouphead_inserted = true
 				end
-				-- lul_html = lul_html .. '<li class="bg"><a href="data_request?id=lr_sPhone_action&remote=' .. v.remote .. '&page=' .. v.page .. '&room=' .. 0 .. '&device=0&service=urn:micasaverde-com:serviceId:HomeAutomationGateway1&action=RunScene&SceneNum=' .. tostring(k) .. '&time=' .. tostring(os.clock()) .. '"><img src="/port_3480/L_sPhoneUI_layout/buttons/go.gif" alt="" width="36" height="36" border="0" align="absmiddle" class="icon"/></a> ' .. v.description .. '</li>\n'
 				table.insert (out, ([[
 					<li class="bg">
-						<a href="data_request?id=lr_sPhone_action&remote=%{remote}%&page=%{page}%&room=%{room}%&device=0&service=urn:micasaverde-com:serviceId:HomeAutomationGateway1&action=RunScene&SceneNum=%{scene_num}%&time=%{time}%">
-							<img src="/port_3480/L_sPhoneUI_layout/buttons/go.gif" alt="" width="36" height="36" border="0" align="absmiddle" class="icon"/>
+						<a href="data_request?id=lr_sPhone_action&remote={%remote%}&page={%page%}&room={%room%}&device=0&service=urn:micasaverde-com:serviceId:HomeAutomationGateway1&action=RunScene&SceneNum={%scene_num%}&time={%time%}">
+							<img src="{%sPh_LAYOUT_PFX%}/buttons/go.gif" alt="" width="36" height="36" border="0" align="absmiddle" class="icon"/>
 						</a>
-						%{description}%
+						{%description%}
 					</li>
 				]]):template {
@@ -101,5 +119,4 @@
 		end
 
-		-- lul_html = lul_html .. '<li class="group">My Home</li>'
 		if next(luup.rooms) ~= nil then
 			table.insert (out, '<li class="group">My Home</li>')
@@ -107,8 +124,7 @@
 
 		for k,v in pairs(luup.rooms) do
-			-- lul_html = lul_html.. '<li><a class="pic" href="data_request?id=lr_sPhone_room&room=' .. tostring(k) .. '&time=' .. tostring(os.clock()) .. '">' .. v .. '</a></li>\r\n'
 			table.insert (out, ([[
-				<li><a class="pic" href="data_request?id=lr_sPhone_room&room=%{room}%&time=%{time}%">
-					%{room_name}%
+				<li><a class="pic" href="data_request?id=lr_sPhone_room&room={%room%}&time={%time%}">
+					{%room_name%}
 				</a></li>
 			]]):template {
@@ -119,11 +135,9 @@
 		end
 		
-		list_devices (0, out)
+		list_devices (0, out, lul_js)
 		
-		-- lul_html = lul_html .. '</ul>'
 		table.insert (out, '</ul>')
 		table.insert (out, html_footer)
 
-		-- lul_html = html_header .. lul_html .. html_footer
 		return table.concat (out),"text/html"
 	end
@@ -139,5 +153,5 @@
 
 		if( lul_remote~=nil and tonumber(lul_remote)>0 ) then
-			html_header_action = [[
+			html_header_action = ([[
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml">
@@ -146,10 +160,13 @@
 	<meta http-equiv="pragma" content="nocache"/>
 	<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0;"/>
-	<meta http-equiv="refresh" content="0;url=\/port_3480/luvd/PK_Remote_' .. lul_remote .. '_' .. lul_page .. '.html" />
-	<script src="/port_3480/L_sPhoneUI_layout/js/mobile.js" language="javascript"></script>
-	<link rel="stylesheet" href="/port_3480/L_sPhoneUI_layout/css/iui.css" type="text/css" />
+	<meta http-equiv="refresh" content="0;url="/port_3480/luvd/PK_Remote_{%lul_remote%}_{%lul_page%}.html" />
+	<script src="{%sPh_LAYOUT_PFX%}/js/mobile.js" language="javascript"></script>
+	<link rel="stylesheet" href="{%sPh_LAYOUT_PFX%}/css/iui.css" type="text/css" />
 </head>
 <body onLoad="js_prepare_urls();">
-]]
+			]]):template {
+				lul_remote = lul_remote,
+				lul_page,
+			}
 		else
 			html_header_action = html_header
@@ -161,5 +178,5 @@
 			return (html_header .. [[
 				<div>
-					<img src="/port_3480/L_sPhoneUI_layout/buttons/eror.gif" alt="" border="0" class="icon" align="absmiddle"/>
+					<img src="{%sPh_LAYOUT_PFX%}/buttons/eror.gif" alt="" border="0" class="icon" align="absmiddle"/>
 					Internal Error: Missing arguments
 				</div>
@@ -174,5 +191,5 @@
 			return (html_header .. [[
 				<div>
-					<img src="/port_3480/L_sPhoneUI_layout/buttons/eror.gif" alt="" border="0" class="icon" align="absmiddle"/>
+					<img src="{%sPh_LAYOUT_PFX%}/buttons/eror.gif" alt="" border="0" class="icon" align="absmiddle"/>
 					Internal Error: Invalid Device
 				</div>
@@ -196,5 +213,5 @@
 		local lul_resultcode,lul_resultstring,lul_job,lul_returnarguments = luup.call_action(lul_service,lul_action,lul_arguments,tonumber(lul_device))
 
-		luup.log (("lug_sPhoneRequest_action: device: %{device}% action: %{action}% service %{service}% returned: %{resultcode}% str %{resultstring}% job %{job}%"):template {
+		luup.log (("lug_sPhoneRequest_action: device: {%device%} action: {%action%} service {%service%} returned: {%resultcode%} str {%resultstring%} job {%job%}"):template {
 			device = lul_device,
 			action = lul_action,
@@ -207,14 +224,14 @@
 		if( lul_resultcode~=0 ) then
 			return ([[
-				%{html_header}%
+				{%html_header%}
 				<div>
-					<img src="/port_3480/L_sPhoneUI_layout/buttons/eror.gif" alt="" border="0" class="icon" align="absmiddle"/>
-					Error: %{lul_resultcode}%: %{lul_resultstring}%<br>
-					<a href="data_request?id=lr_sPhone_room&room=%{room_num}%&time=%{time}%">OK - back</a><br>
+					<img src="{%sPh_LAYOUT_PFX%}/buttons/eror.gif" alt="" border="0" class="icon" align="absmiddle"/>
+					Error: {%lul_resultcode%}: {%lul_resultstring%}<br>
+					<a href="data_request?id=lr_sPhone_room&room={%room_num%}&time={%time%}">OK - back</a><br>
 				</div>
-				%{html_footer}%
+				{%html_footer%}
 			]]):template {
-				html_header,
-				html_footer,
+				html_header = html_header,
+				html_footer = html_footer,
 				lul_resultcode = lul_resultcode,
 				lul_resultstring = lul_resultstring,
@@ -226,15 +243,15 @@
 		if ( lul_job==0 ) then
 			return ([[
-				%{html_header_action}%
+				{%html_header_action%}
 				<div id="toolbar" class="toolbar">
-					<a href="data_request?id=lr_sPhone_room&room=%{room}%&time=%{time}%">
-						<img src="/port_3480/L_sPhoneUI_layout/images/backButton.gif" border="0">
+					<a href="data_request?id=lr_sPhone_room&room={%room%}&time={%time%}">
+						<img src="{%sPh_LAYOUT_PFX%}/images/backButton.gif" border="0">
 					</a>
 				</div>
 				<div>
-					<img src="/port_3480/L_sPhoneUI_layout/buttons/ok.gif" alt="" border="0" class="icon" align="absmiddle"/>
+					<img src="{%sPh_LAYOUT_PFX%}/buttons/ok.gif" alt="" border="0" class="icon" align="absmiddle"/>
 					Command executed OK<br>
 				</div>
-				%{html_footer}%
+				{%html_footer%}
 			]]):template {
 				html_header_action = html_header_action,
@@ -246,18 +263,18 @@
 
 		return ([[
-			%{html_header_action}%
+			{%html_header_action%}
 			<div id="toolbar" class="toolbar">
-				<a href="data_request?id=lr_sPhone_room&room=%{room}%&time=%{time}%">
-					<img src="/port_3480/L_sPhoneUI_layout/images/backButton.gif" border="0">
+				<a href="data_request?id=lr_sPhone_room&room={%room%}&time={%time%}">
+					<img src="{%sPh_LAYOUT_PFX%}/images/backButton.gif" border="0">
 				</a>
 			</div>
 			<div>
-				<img src="/port_3480/L_sPhoneUI_layout/buttons/wait.gif" alt="" border="0" class="icon" align="absmiddle"/>
+				<img src="{%sPh_LAYOUT_PFX%}/buttons/wait.gif" alt="" border="0" class="icon" align="absmiddle"/>
 				Running command now...<br>
-				<a href="data_request?id=lr_sPhone_job&device=%{device}%&room=%{room}%&job=%{job}%&time=%{time}%">
+				<a href="data_request?id=lr_sPhone_job&device={%device%}&room={%room%}&job={%job%}&time={%time%}">
 					Check the status
 				</a>
 			</div>
-			%{html_footer}%
+			{%html_footer%}
 		]]):template {
 			html_header_action = html_header_action,
@@ -272,8 +289,8 @@
 	function lug_sPhoneRequest_camera(lul_device,lul_description,lul_js)
 		return ([[
-			<img src="/port_3480/L_sPhoneUI_layout/icons/camera.gif" alt="" width="44" height="43" align="absmiddle" class="icon"/>
-				%{description}% <br>
-			<a href="data_request?id=lr_sPhone_camimg&device=%{device}%&time=%{time}%&js=%{js}%">
-				<img src="/port_3480/L_sPhoneUI_layout/buttons/view.gif" alt="" border="0"/>
+			<img src="{%sPh_LAYOUT_PFX%}/icons/camera.gif" alt="" width="44" height="43" align="absmiddle" class="icon"/>
+				{%description%} <br>
+			<a href="data_request?id=lr_sPhone_camimg&device={%device%}&time={%time%}&js={%js%}&r={%g_is_remote%}">
+				<img src="{%sPh_LAYOUT_PFX%}/buttons/view.gif" alt="" border="0"/>
 			</a>
 		]]):template {
@@ -297,5 +314,5 @@
 		if( lul_job_status==nil ) then
 			lul_text = [[
-				<img src="/port_3480/L_sPhoneUI_layout/buttons/eror.gif" alt="" border="0" class="icon" align="absmiddle"/>
+				<img src="{%sPh_LAYOUT_PFX%}/buttons/eror.gif" alt="" border="0" class="icon" align="absmiddle"/>
 				No information on command.<br>
 				Command history is only kept for 30 seconds.
@@ -303,7 +320,7 @@
 		elseif( lul_job_status==0 or lul_job_status==1 or lul_job_status==5 ) then
 			lul_text = ([[
-				<img src="/port_3480/L_sPhoneUI_layout/buttons/wait.gif" alt="" border="0" class="icon" align="absmiddle"/>
+				<img src="{%sPh_LAYOUT_PFX%}/buttons/wait.gif" alt="" border="0" class="icon" align="absmiddle"/>
 				Command is still running...<br>
-				<a href="data_request?id=lr_sPhone_job&device=%{device}%&room=%{room}%&job=%{job}%&time=%{time}%">Refresh</a>'
+				<a href="data_request?id=lr_sPhone_job&device={%device%}&room={%room%}&job={%job%}&time={%time%}">Refresh</a>'
 			]]):template {
 				device = lul_device,
@@ -314,29 +331,29 @@
 		elseif( lul_job_status==2 or lul_job_status==3 ) then
 			lul_text = [[
-				<img src="/port_3480/L_sPhoneUI_layout/buttons/eror.gif" alt="" border="0" class="icon" align="absmiddle"/>
+				<img src="{%sPh_LAYOUT_PFX%}/buttons/eror.gif" alt="" border="0" class="icon" align="absmiddle"/>
 				Failed to run command
 			]]
 		elseif( lul_job_status==4 ) then
 			lul_text = [[
-				<img src="/port_3480/L_sPhoneUI_layout/buttons/ok.gif" alt="" border="0" class="icon" align="absmiddle"/>
+				<img src="{%sPh_LAYOUT_PFX%}/buttons/ok.gif" alt="" border="0" class="icon" align="absmiddle"/>
 				Command completed ok
 			]]
 		else
 			lul_text = [[
-				<img src="/port_3480/L_sPhoneUI_layout/buttons/eror.gif" alt="" border="0" class="icon" align="absmiddle"/>
+				<img src="{%sPh_LAYOUT_PFX%}/buttons/eror.gif" alt="" border="0" class="icon" align="absmiddle"/>
 				Unknown status:]] .. tostring(lul_job_status)
 		end
 
 		return ([[
-			%{html_header}%
+			{%html_header%}
 			<div id="toolbar" class="toolbar">
-				<a href="data_request?id=lr_sPhone_room&room=%{room}%&time=%{time}%">
-					<img src="/port_3480/L_sPhoneUI_layout/images/backButton.gif" border="0">
+				<a href="data_request?id=lr_sPhone_room&room={%room%}&time={%time%}">
+					<img src="{%sPh_LAYOUT_PFX%}/images/backButton.gif" border="0">
 				</a>
 			</div>
 			<div>
-				%{text}%
+				{%text%}
 			</div>
-			%{html_footer}%
+			{%html_footer%}
 		]]):template {
 			html_header = html_header,
@@ -370,21 +387,19 @@
 		if( lul_js=='1' ) then
 			return ([[
-				<img src="/port_3480/L_sPhoneUI_layout/icons/dimmable.gif" alt="" width="44" height="43" align="absmiddle" class="icon"/>%{description}%<br/>
-				<img src="/port_3480/L_sPhoneUI_layout/images/spacer.gif" border="0" width="20" height="20" id="action_icon_%{device}%">
-				<a href="javascript:void(0);" onClick="set_device_icon(%{device}%,1);send_command('data_request?id=lr_sPhone_action_js&room=%{room_num}%&device=%{device}%&service=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=0&time=%{time}%',%{device}%)"><img src="/port_3480/L_sPhoneUI_layout/buttons/off%{status_0}%.gif" alt="" border="0"/></a>
-				<a href="javascript:void(0);" onClick="set_device_icon(%{device}%,1);send_command('data_request?id=lr_sPhone_action_js&room=%{room_num}%&device=%{device}%&service=urn:upnp-org:serviceId:Dimming1&action=SetLoadLevelTarget&newLoadlevelTarget=25&time=%{time}%',%{device}%)"><img src="/port_3480/L_sPhoneUI_layout/buttons/25%{status_25}%.gif" alt="" border="0"/></a>
-				<a href="javascript:void(0);" onClick="set_device_icon(%{device}%,1);send_command('data_request?id=lr_sPhone_action_js&room=%{room_num}%&device=%{device}%&service=urn:upnp-org:serviceId:Dimming1&action=SetLoadLevelTarget&newLoadlevelTarget=50&time=%{time}%',%{device}%)"><img src="/port_3480/L_sPhoneUI_layout/buttons/50%{status_50}%.gif" alt="" border="0"/></a>
-				<a href="javascript:void(0);" onClick="set_device_icon(%{device}%,1);send_command('data_request?id=lr_sPhone_action_js&room=%{room_num}%&device=%{device}%&service=urn:upnp-org:serviceId:Dimming1&action=SetLoadLevelTarget&newLoadlevelTarget=75&time=%{time}%',%{device}%)"><img src="/port_3480/L_sPhoneUI_layout/buttons/75%{status_75}%.gif" alt="" border="0"/></a>
-				<a href="javascript:void(0);" onClick="set_device_icon(%{device}%,1);send_command('data_request?id=lr_sPhone_action_js&room=%{room_num}%&device=%{device}%&service=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=1&time=%{time}%',%{device}%)"><img src="/port_3480/L_sPhoneUI_layout/buttons/on%{status_100}%.gif" alt="" border="0"/></a> (%{level}%)
-			]]):template (tmpl_params)
-		else
-			return ([[
-				<img src="/port_3480/L_sPhoneUI_layout/icons/dimmable.gif" alt="" width="44" height="43" align="absmiddle" class="icon"/>%{description}%<br/>
-				<img src="/port_3480/L_sPhoneUI_layout/images/spacer.gif" border="0" width="20" height="20" id="action_icon_%{device}%">
-				<a href="javascript:void(0);" onClick="set_device_icon(%{device}%,1);send_command('data_request?id=lr_sPhone_action_js&room=%{room_num}%&device=%{device}%&service=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=0&time=%{time}%',%{device}%)"><img src="/port_3480/L_sPhoneUI_layout/buttons/off%{status_0}%.gif" alt="" border="0"/></a>
-				<a href="javascript:void(0);" onClick="set_device_icon(%{device}%,1);send_command('data_request?id=lr_sPhone_action_js&room=%{room_num}%&device=%{device}%&service=urn:upnp-org:serviceId:Dimming1&action=SetLoadLevelTarget&newLoadlevelTarget=25&time=%{time}%',%{device}%)"><img src="/port_3480/L_sPhoneUI_layout/buttons/25%{status_25}%.gif" alt="" border="0"/></a>
-				<a href="javascript:void(0);" onClick="set_device_icon(%{device}%,1);send_command('data_request?id=lr_sPhone_action_js&room=%{room_num}%&device=%{device}%&service=urn:upnp-org:serviceId:Dimming1&action=SetLoadLevelTarget&newLoadlevelTarget=50&time=%{time}%',%{device}%)"><img src="/port_3480/L_sPhoneUI_layout/buttons/50%{status_50}%.gif" alt="" border="0"/></a>
-				<a href="javascript:void(0);" onClick="set_device_icon(%{device}%,1);send_command('data_request?id=lr_sPhone_action_js&room=%{room_num}%&device=%{device}%&service=urn:upnp-org:serviceId:Dimming1&action=SetLoadLevelTarget&newLoadlevelTarget=75&time=%{time}%',%{device}%)"><img src="/port_3480/L_sPhoneUI_layout/buttons/75%{status_75}%.gif" alt="" border="0"/></a>
-				<a href="javascript:void(0);" onClick="set_device_icon(%{device}%,1);send_command('data_request?id=lr_sPhone_action_js&room=%{room_num}%&device=%{device}%&service=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=1&time=%{time}%',%{device}%)"><img src="/port_3480/L_sPhoneUI_layout/buttons/on%{status_100}%.gif" alt="" border="0"/></a> (%{level}%)
+				<img src="{%sPh_LAYOUT_PFX%}/icons/dimmable.gif" alt="" width="44" height="43" align="absmiddle" class="icon"/>{%description%}<br/>
+				<img src="{%sPh_LAYOUT_PFX%}/images/spacer.gif" border="0" width="20" height="20" id="action_icon_{%device%}">
+				<a href="javascript:void(0);" onClick="set_device_icon({%device%},1);send_command('data_request?id=lr_sPhone_action_js&room={%room%}&device={%device%}&service=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=0&time={%time%}',{%device%})"><img src="{%sPh_LAYOUT_PFX%}/buttons/off{%status_0%}.gif" alt="" border="0"/></a>
+				<a href="javascript:void(0);" onClick="set_device_icon({%device%},1);send_command('data_request?id=lr_sPhone_action_js&room={%room%}&device={%device%}&service=urn:upnp-org:serviceId:Dimming1&action=SetLoadLevelTarget&newLoadlevelTarget=25&time={%time%}',{%device%})"><img src="{%sPh_LAYOUT_PFX%}/buttons/25{%status_25%}.gif" alt="" border="0"/></a>
+				<a href="javascript:void(0);" onClick="set_device_icon({%device%},1);send_command('data_request?id=lr_sPhone_action_js&room={%room%}&device={%device%}&service=urn:upnp-org:serviceId:Dimming1&action=SetLoadLevelTarget&newLoadlevelTarget=50&time={%time%}',{%device%})"><img src="{%sPh_LAYOUT_PFX%}/buttons/50{%status_50%}.gif" alt="" border="0"/></a>
+				<a href="javascript:void(0);" onClick="set_device_icon({%device%},1);send_command('data_request?id=lr_sPhone_action_js&room={%room%}&device={%device%}&service=urn:upnp-org:serviceId:Dimming1&action=SetLoadLevelTarget&newLoadlevelTarget=75&time={%time%}',{%device%})"><img src="{%sPh_LAYOUT_PFX%}/buttons/75{%status_75%}.gif" alt="" border="0"/></a>
+				<a href="javascript:void(0);" onClick="set_device_icon({%device%},1);send_command('data_request?id=lr_sPhone_action_js&room={%room%}&device={%device%}&service=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=1&time={%time%}',{%device%})"><img src="{%sPh_LAYOUT_PFX%}/buttons/on{%status_100%}.gif" alt="" border="0"/></a> ({%level%})
+			]]):template (tmpl_params)
+		else
+			return ([[<img src="{%sPh_LAYOUT_PFX%}/icons/dimmable.gif" alt="" width="44" height="43" align="absmiddle" class="icon"/>{%description%}<br/>
+				<a href="data_request?id=lr_sPhone_action&room={%room%}&device={%device%}&service=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=0&time={%time%}"><img src="{%sPh_LAYOUT_PFX%}/buttons/off{%status_0%}.gif" alt="" border="0"/></a>
+				<a href="data_request?id=lr_sPhone_action&room={%room%}&device={%device%}&service=urn:upnp-org:serviceId:Dimming1&action=SetLoadLevelTarget&newLoadlevelTarget=25&time={%time%}"><img src="{%sPh_LAYOUT_PFX%}/buttons/25{%status_25%}.gif" alt="" border="0"/></a>
+				<a href="data_request?id=lr_sPhone_action&room={%room%}&device={%device%}&service=urn:upnp-org:serviceId:Dimming1&action=SetLoadLevelTarget&newLoadlevelTarget=50&time={%time%}"><img src="{%sPh_LAYOUT_PFX%}/buttons/50{%status_50%}.gif" alt="" border="0"/></a>
+				<a href="data_request?id=lr_sPhone_action&room={%room%}&device={%device%}&service=urn:upnp-org:serviceId:Dimming1&action=SetLoadLevelTarget&newLoadlevelTarget=75&time={%time%}"><img src="{%sPh_LAYOUT_PFX%}/buttons/75{%status_75%}.gif" alt="" border="0"/></a>
+				<a href="data_request?id=lr_sPhone_action&room={%room%}&device={%device%}&service=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=1&time={%time%}"><img src="{%sPh_LAYOUT_PFX%}/buttons/on{%status_100%}.gif" alt="" border="0"/></a>
 			]]):template (tmpl_params)
 		end
@@ -405,14 +420,14 @@
 		if( lul_js=='1' ) then
 			return ([[
-				<img src="/port_3480/L_sPhoneUI_layout/icons/switch.gif" alt="" width="44" height="43" align="absmiddle" class="icon" id="pic_device_%{device}%" />%{description}%<br>
-				<img src="/port_3480/L_sPhoneUI_layout/images/spacer.gif" border="0" width="20" height="20" id="action_icon_%{lul_device}%">
-				<a href="javascript:void(0);" onClick="set_device_icon(%{device}%,1);send_command('data_request?id=lr_sPhone_action_js&room=%{room}%&device=%{device}%&service=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=0&time=%{time}%',%{device}%)"><img src="/port_3480/L_sPhoneUI_layout/buttons/off%{status_0}%.gif" alt="" border="0"/></a>
-				<a href="javascript:void(0);" onClick="set_device_icon(%{device}%,1);send_command('data_request?id=lr_sPhone_action_js&room=%{room}%&device=%{device}%&service=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=1&time=%{time}%',%{device}%)"><img src="/port_3480/L_sPhoneUI_layout/buttons/on%{status_100}%.gif" alt="" border="0"/></a>
-			]]):template (tmpl_params)
-		else
-			return ([[
-				<img src="/port_3480/L_sPhoneUI_layout/icons/switch.gif" alt="" width="44" height="43" align="absmiddle" class="icon" />%{description}%<br>
-				<a href="data_request?id=lr_sPhone_action&room=%{room}%&device=%{device}%&service=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=0&time=%{time}%"><img src="/port_3480/L_sPhoneUI_layout/buttons/off%{status_0}%.gif" alt="" border="0"/></a>
-				<a href="data_request?id=lr_sPhone_action&room=%{room}%&device=%{device}%&service=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=1&time=%{time}%"><img src="/port_3480/L_sPhoneUI_layout/buttons/on%{status_100}%.gif" alt="" border="0"/></a>
+				<img src="{%sPh_LAYOUT_PFX%}/icons/switch.gif" alt="" width="44" height="43" align="absmiddle" class="icon" id="pic_device_{%device%}" />{%description%}<br>
+				<img src="{%sPh_LAYOUT_PFX%}/images/spacer.gif" border="0" width="20" height="20" id="action_icon_{%lul_device%}">
+				<a href="javascript:void(0);" onClick="set_device_icon({%device%},1);send_command('data_request?id=lr_sPhone_action_js&room={%room%}&device={%device%}&service=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=0&time={%time%}',{%device%})"><img src="{%sPh_LAYOUT_PFX%}/buttons/off{%status_0%}.gif" alt="" border="0"/></a>
+				<a href="javascript:void(0);" onClick="set_device_icon({%device%},1);send_command('data_request?id=lr_sPhone_action_js&room={%room%}&device={%device%}&service=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=1&time={%time%}',{%device%})"><img src="{%sPh_LAYOUT_PFX%}/buttons/on{%status_100%}.gif" alt="" border="0"/></a>
+			]]):template (tmpl_params)
+		else
+			return ([[
+				<img src="{%sPh_LAYOUT_PFX%}/icons/switch.gif" alt="" width="44" height="43" align="absmiddle" class="icon" />{%description%}<br>
+				<a href="data_request?id=lr_sPhone_action&room={%room%}&device={%device%}&service=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=0&time={%time%}"><img src="{%sPh_LAYOUT_PFX%}/buttons/off{%status_0%}.gif" alt="" border="0"/></a>
+				<a href="data_request?id=lr_sPhone_action&room={%room%}&device={%device%}&service=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=1&time={%time%}"><img src="{%sPh_LAYOUT_PFX%}/buttons/on{%status_100%}.gif" alt="" border="0"/></a>
 			]]):template (tmpl_params)
 		end
@@ -444,18 +459,18 @@
 		if( lul_js=='1' ) then
 			return ([[
-				<img src="/port_3480/L_sPhoneUI_layout/icons/security.gif" alt="" width="44" height="43" align="absmiddle" class="icon" id="pic_device_%{device}%" />%{description}%<br>
-				<img src="/port_3480/L_sPhoneUI_layout/images/spacer.gif" border="0" width="20" height="20" id="action_icon_%{lul_device}%">
-				<a href="javascript:void(0);" onClick="set_device_icon(%{device}%,1);send_command('data_request?id=lu_variableset&DeviceNum=%{device}%&serviceId=urn:micasaverde-com:serviceId:SecuritySensor1&Variable=Tripped&Value=1&time=%{time}%',%{device}%)"><img src="/port_3480/L_sPhoneUI_layout/images/%{status_tripped}%_circle.gif" alt="" border="0"/></a>
-				<a href="javascript:void(0);" onClick="set_device_icon(%{device}%,1);send_command('data_request?id=lu_variableset&DeviceNum=%{device}%&serviceId=urn:micasaverde-com:serviceId:SecuritySensor1&Variable=Armed&Value=1&time=%{time}%',%{device}%)"><img src="/port_3480/L_sPhoneUI_layout/buttons/arm%{status_arm}%.gif" alt="" border="0"/></a>
-				<a href="javascript:void(0);" onClick="set_device_icon(%{device}%,1);send_command('data_request?id=lu_variableset&DeviceNum=%{device}%&serviceId=urn:micasaverde-com:serviceId:SecuritySensor1&Variable=Armed&Value=0&time=%{time}%',%{device}%)"><img src="/port_3480/L_sPhoneUI_layout/buttons/bypass%{status_bypass}%.gif" alt="" border="0"/></a>
-				%{temp}%
-			]]):template (tmpl_params)
-		else
-			return ([[
-				<img src="/port_3480/L_sPhoneUI_layout/icons/security.gif" alt="" width="44" height="43" align="absmiddle" class="icon" />%{description}%<br>
-				<a href="data_request?id=lu_variableset&DeviceNum=%{device}%&serviceId=urn:micasaverde-com:serviceId:SecuritySensor1&Variable=Tripped&time=%{time}%"><img src="/port_3480/L_sPhoneUI_layout/images/%{status_tripped}%_circle.gif" alt="" border="0"/></a>
-				<a href="data_request?id=lu_variableset&DeviceNum=%{device}%&serviceId=urn:micasaverde-com:serviceId:SecuritySensor1&Variable=Armed&Value=1&time=%{time}%"><img src="/port_3480/L_sPhoneUI_layout/buttons/arm%{status_arm}%.gif" alt="" border="0"/></a>
-				<a href="data_request?id=lu_variableset&DeviceNum=%{device}%&serviceId=urn:micasaverde-com:serviceId:SecuritySensor1&Variable=Armed&Value=0&time=%{time}%"><img src="/port_3480/L_sPhoneUI_layout/buttons/bypass%{status_bypass}%.gif" alt="" border="0"/></a>
-				%{temp}%
+				<img src="{%sPh_LAYOUT_PFX%}/icons/security.gif" alt="" width="44" height="43" align="absmiddle" class="icon" id="pic_device_{%device%}" />{%description%}<br>
+				<img src="{%sPh_LAYOUT_PFX%}/images/spacer.gif" border="0" width="20" height="20" id="action_icon_{%lul_device%}">
+				<a href="javascript:void(0);" onClick="set_device_icon({%device%},1);send_command('data_request?id=lu_variableset&DeviceNum={%device%}&serviceId=urn:micasaverde-com:serviceId:SecuritySensor1&Variable=Tripped&Value=1&time={%time%}',{%device%})"><img src="{%sPh_LAYOUT_PFX%}/images/{%status_tripped%}_circle.gif" alt="" border="0"/></a>
+				<a href="javascript:void(0);" onClick="set_device_icon({%device%},1);send_command('data_request?id=lu_variableset&DeviceNum={%device%}&serviceId=urn:micasaverde-com:serviceId:SecuritySensor1&Variable=Armed&Value=1&time={%time%}',{%device%})"><img src="{%sPh_LAYOUT_PFX%}/buttons/arm{%status_arm%}.gif" alt="" border="0"/></a>
+				<a href="javascript:void(0);" onClick="set_device_icon({%device%},1);send_command('data_request?id=lu_variableset&DeviceNum={%device%}&serviceId=urn:micasaverde-com:serviceId:SecuritySensor1&Variable=Armed&Value=0&time={%time%}',{%device%})"><img src="{%sPh_LAYOUT_PFX%}/buttons/bypass{%status_bypass%}.gif" alt="" border="0"/></a>
+				{%temp%}
+			]]):template (tmpl_params)
+		else
+			return ([[
+				<img src="{%sPh_LAYOUT_PFX%}/icons/security.gif" alt="" width="44" height="43" align="absmiddle" class="icon" />{%description%}<br>
+				<a href="data_request?id=lu_variableset&DeviceNum={%device%}&serviceId=urn:micasaverde-com:serviceId:SecuritySensor1&Variable=Tripped&time={%time%}"><img src="{%sPh_LAYOUT_PFX%}/images/{%status_tripped%}_circle.gif" alt="" border="0"/></a>
+				<a href="data_request?id=lu_variableset&DeviceNum={%device%}&serviceId=urn:micasaverde-com:serviceId:SecuritySensor1&Variable=Armed&Value=1&time={%time%}"><img src="{%sPh_LAYOUT_PFX%}/buttons/arm{%status_arm%}.gif" alt="" border="0"/></a>
+				<a href="data_request?id=lu_variableset&DeviceNum={%device%}&serviceId=urn:micasaverde-com:serviceId:SecuritySensor1&Variable=Armed&Value=0&time={%time%}"><img src="{%sPh_LAYOUT_PFX%}/buttons/bypass{%status_bypass%}.gif" alt="" border="0"/></a>
+				{%temp%}
 			]]):template (tmpl_params)
 		end
@@ -472,12 +487,34 @@
 		if( lul_js=='1' ) then
 			return ([[
-				<img src="/port_3480/L_sPhoneUI_layout/icons/thermostat.gif" alt="" width="44" height="43" align="absmiddle" class="icon" id="pic_device_%{device}%" />%{description}%<br>
-				<img src="/port_3480/L_sPhoneUI_layout/images/spacer.gif" border="0" width="20" height="20" id="action_icon_%{device}%">
-				Temperature: %{temp}%&deg;<br/>
-			]]):template (tmpl_params)
-		else
-			return ([[
-				<img src="/port_3480/L_sPhoneUI_layout/icons/thermostat.gif" alt="" width="44" height="43" align="absmiddle" class="icon" />%{description}%<br>
-				Temperature: %{temp}%&deg;<br/>
+				<img src="{%sPh_LAYOUT_PFX%}/icons/thermostat.gif" alt="" width="44" height="43" align="absmiddle" class="icon" id="pic_device_{%device%}" />{%description%}<br>
+				<img src="{%sPh_LAYOUT_PFX%}/images/spacer.gif" border="0" width="20" height="20" id="action_icon_{%device%}">
+				Temperature: {%temp%}&deg;<br/>
+			]]):template (tmpl_params)
+		else
+			return ([[
+				<img src="{%sPh_LAYOUT_PFX%}/icons/thermostat.gif" alt="" width="44" height="43" align="absmiddle" class="icon" />{%description%}<br>
+				Temperature: {%temp%}&deg;<br/>
+			]]):template (tmpl_params)
+		end
+	end
+	
+	function lug_sPhoneRequest_humid(lul_device, lul_description, lul_js)
+		local lul_humid = luup.variable_get ('urn:micasaverde-com:serviceId:HumiditySensor1', 'CurrentLevel', lul_device)
+		local tmpl_params = {
+			device = lul_device,
+			description = lul_description,
+			humid = lul_humid or 'N/A',
+		}
+		
+		if (lul_js=='1') then
+			return ([[
+				<img src="{%sPh_LAYOUT_PFX%}/icons/thermostat.gif" alt="" width="44" height="43" align="absmiddle" class="icon" id="pic_device_{%device%}" />{%description%}<br>
+				<img src="{%sPh_LAYOUT_PFX%}/images/spacer.gif" border="0" width="20" height="20" id="action_icon_{%device%}">
+				Humidity: {%humid%}%<br/>
+			]]):template (tmpl_params)
+		else
+			return ([[
+				<img src="{%sPh_LAYOUT_PFX%}/icons/thermostat.gif" alt="" width="44" height="43" align="absmiddle" class="icon" />{%description%}<br>
+				Humidity: {%humid%}%<br/>
 			]]):template (tmpl_params)
 		end
@@ -494,12 +531,12 @@
 		if( lul_js=='1' ) then
 			return ([[
-				<img src="/port_3480/L_sPhoneUI_layout/icons/brightness.gif" alt="" width="44" height="43" align="absmiddle" class="icon" id="pic_device_%{device}%" />%{description}%<br>
-				<img src="/port_3480/L_sPhoneUI_layout/images/spacer.gif" border="0" width="20" height="20" id="action_icon_%{device}%">
-				Light level: %{level}%<br/>
+				<img src="{%sPh_LAYOUT_PFX%}/icons/brightness.gif" alt="" width="44" height="43" align="absmiddle" class="icon" id="pic_device_{%device%}" />{%description%}<br>
+				<img src="{%sPh_LAYOUT_PFX%}/images/spacer.gif" border="0" width="20" height="20" id="action_icon_{%device%}">
+				Light level: {%level%}%<br/>
 			]]):template(tmpl_params)
 		else
 			return ([[
-				<img src="/port_3480/L_sPhoneUI_layout/icons/brightness.gif" alt="" width="44" height="43" align="absmiddle" class="icon" />%{description}%<br>
-				Light level: %{lul_Level}%<br/>
+				<img src="{%sPh_LAYOUT_PFX%}/icons/brightness.gif" alt="" width="44" height="43" align="absmiddle" class="icon" />{%description%}<br>
+				Light level: {%level%}%<br/>
 			]]):template(tmpl_params)
 		end
@@ -529,70 +566,70 @@
 		if( lul_js=='1' ) then
 			return ([[
-				<img src="/port_3480/L_sPhoneUI_layout/icons/thermostat.gif" alt="" width="44" height="43" align="absmiddle" class="icon"/>%{description}%<br>
-				<img src="/port_3480/L_sPhoneUI_layout/images/spacer.gif" border="0" width="20" height="20" id="action_icon_%{device}%">
-				<a href="javascript:void(0);" onClick="set_device_icon(%{device}%,1);send_command('data_request?id=lr_sPhone_action_js&room=%{room}%&device=%{device}%&service=urn:upnp-org:serviceId:HVAC_UserOperatingMode1&action=SetModeTarget&NewModeTarget=Off&time=%{time}%',%{device}%)"><img src="/port_3480/L_sPhoneUI_layout/buttons/off%{status_off}%.gif" alt="" border="0"/></a>
-				<a href="javascript:void(0);" onClick="set_device_icon(%{device}%,1);send_command('data_request?id=lr_sPhone_action_js&room=%{room}%&device=%{device}%&service=urn:upnp-org:serviceId:HVAC_UserOperatingMode1&action=SetModeTarget&NewModeTarget=CoolOn&time=%{time}%',%{device}%)"><img src="/port_3480/L_sPhoneUI_layout/buttons/cool%{status_cool}%.gif" alt="" border="0"/></a>
-				<a href="javascript:void(0);" onClick="set_device_icon(%{device}%,1);send_command('data_request?id=lr_sPhone_action_js&room=%{room}%&device=%{device}%&service=urn:upnp-org:serviceId:HVAC_UserOperatingMode1&action=SetModeTarget&NewModeTarget=HeatOn&time=%{time}%',%{device}%)"><img src="/port_3480/L_sPhoneUI_layout/buttons/heat%{status_heat}%.gif" alt="" border="0"/></a>
-				<a href="javascript:void(0);" onClick="set_device_icon(%{device}%,1);send_command('data_request?id=lr_sPhone_action_js&room=%{room}%&device=%{device}%&service=urn:upnp-org:serviceId:HVAC_UserOperatingMode1&action=SetModeTarget&NewModeTarget=AutoChangeOver&time=%{time}%',%{device}%)"><img src="/port_3480/L_sPhoneUI_layout/buttons/auto%{status_auto}%.gif" alt="" border="0"/></a> <br/>
-				Fan: <a href="javascript:void(0);" onClick="set_device_icon('%{device}%,1);send_command('data_request?id=lr_sPhone_action_js&room=%{room}%&device=%{device}%&service=urn:upnp-org:serviceId:HVAC_FanOperatingMode1&action=SetMode&NewMode=Auto&time=%{time}%',%{device}%)"><img src="/port_3480/L_sPhoneUI_layout/buttons/auto%{status_fan_auto}%.gif" alt="" border="0"/></a>
-				<a href="javascript:void(0);" onClick="set_device_icon(%{device}%,1);send_command('data_request?id=lr_sPhone_action_js&room=%{room}%&device=%{device}%&service=urn:upnp-org:serviceId:HVAC_FanOperatingMode1&action=SetMode&NewMode=ContinuousOn&time=%{time}%',%{device}%)"><img src="/port_3480/L_sPhoneUI_layout/buttons/on%{status_fan_on}%.gif" alt="" border="0"/></a><br/>
+				<img src="{%sPh_LAYOUT_PFX%}/icons/thermostat.gif" alt="" width="44" height="43" align="absmiddle" class="icon"/>{%description%}<br>
+				<img src="{%sPh_LAYOUT_PFX%}/images/spacer.gif" border="0" width="20" height="20" id="action_icon_{%device%}">
+				<a href="javascript:void(0);" onClick="set_device_icon({%device%},1);send_command('data_request?id=lr_sPhone_action_js&room={%room%}&device={%device%}&service=urn:upnp-org:serviceId:HVAC_UserOperatingMode1&action=SetModeTarget&NewModeTarget=Off&time={%time%}',{%device%})"><img src="{%sPh_LAYOUT_PFX%}/buttons/off{%status_off%}.gif" alt="" border="0"/></a>
+				<a href="javascript:void(0);" onClick="set_device_icon({%device%},1);send_command('data_request?id=lr_sPhone_action_js&room={%room%}&device={%device%}&service=urn:upnp-org:serviceId:HVAC_UserOperatingMode1&action=SetModeTarget&NewModeTarget=CoolOn&time={%time%}',{%device%})"><img src="{%sPh_LAYOUT_PFX%}/buttons/cool{%status_cool%}.gif" alt="" border="0"/></a>
+				<a href="javascript:void(0);" onClick="set_device_icon({%device%},1);send_command('data_request?id=lr_sPhone_action_js&room={%room%}&device={%device%}&service=urn:upnp-org:serviceId:HVAC_UserOperatingMode1&action=SetModeTarget&NewModeTarget=HeatOn&time={%time%}',{%device%})"><img src="{%sPh_LAYOUT_PFX%}/buttons/heat{%status_heat%}.gif" alt="" border="0"/></a>
+				<a href="javascript:void(0);" onClick="set_device_icon({%device%},1);send_command('data_request?id=lr_sPhone_action_js&room={%room%}&device={%device%}&service=urn:upnp-org:serviceId:HVAC_UserOperatingMode1&action=SetModeTarget&NewModeTarget=AutoChangeOver&time={%time%}',{%device%})"><img src="{%sPh_LAYOUT_PFX%}/buttons/auto{%status_auto%}.gif" alt="" border="0"/></a> <br/>
+				Fan: <a href="javascript:void(0);" onClick="set_device_icon('{%device%},1);send_command('data_request?id=lr_sPhone_action_js&room={%room%}&device={%device%}&service=urn:upnp-org:serviceId:HVAC_FanOperatingMode1&action=SetMode&NewMode=Auto&time={%time%}',{%device%})"><img src="{%sPh_LAYOUT_PFX%}/buttons/auto{%status_fan_auto%}.gif" alt="" border="0"/></a>
+				<a href="javascript:void(0);" onClick="set_device_icon({%device%},1);send_command('data_request?id=lr_sPhone_action_js&room={%room%}&device={%device%}&service=urn:upnp-org:serviceId:HVAC_FanOperatingMode1&action=SetMode&NewMode=ContinuousOn&time={%time%}',{%device%})"><img src="{%sPh_LAYOUT_PFX%}/buttons/on{%status_fan_on%}.gif" alt="" border="0"/></a><br/>
 				<table cellpadding="2" cellspacing="0">
 					<tr>
 						<td>Heat: </td>
-						<td><input type="text" name="NewCurrentSetpoint" id="NewCurrentSetpoint_Heat_%{device}%" value="" size="3"></td>
-						<td><img src="/port_3480/L_sPhoneUI_layout/images/set_deasupra.gif" border="0" onClick="set_device_icon(%{device}%,1);send_command('data_request?id=lr_sPhone_action_js&room=%{room}%&device=%{device}%&service=urn:upnp-org:serviceId:TemperatureSetpoint1_Heat&action=SetCurrentSetpoint&NewCurrentSetpoint='+document.getElementById('NewCurrentSetpoint_Heat_%{device}%').value+'&time=%{time}%',%{device}%);" border="0"></td>
+						<td><input type="text" name="NewCurrentSetpoint" id="NewCurrentSetpoint_Heat_{%device%}" value="" size="3"></td>
+						<td><img src="{%sPh_LAYOUT_PFX%}/images/set_deasupra.gif" border="0" onClick="set_device_icon({%device%},1);send_command('data_request?id=lr_sPhone_action_js&room={%room%}&device={%device%}&service=urn:upnp-org:serviceId:TemperatureSetpoint1_Heat&action=SetCurrentSetpoint&NewCurrentSetpoint='+document.getElementById('NewCurrentSetpoint_Heat_{%device%}').value+'&time={%time%}',{%device%});" border="0"></td>
 					</tr>
 
 					<tr>
 						<td>Cool: </td>
-						<td><input type="text" name="NewCurrentSetpoint" id="NewCurrentSetpoint_Cool_%{device}%" value="" size="3"></td>
-						<td><img src="/port_3480/L_sPhoneUI_layout/images/set_deasupra.gif" border="0" onClick="set_device_icon(%{device}%,1);send_command('data_request?id=lr_sPhone_action_js&room=%{room}%&device=%{device}%&service=urn:upnp-org:serviceId:TemperatureSetpoint1_Cool&action=SetCurrentSetpoint&NewCurrentSetpoint='+document.getElementById('NewCurrentSetpoint_Cool_%{device}%').value+'&time=%{time}%',%{device}%);" border="0"></td>
+						<td><input type="text" name="NewCurrentSetpoint" id="NewCurrentSetpoint_Cool_{%device%}" value="" size="3"></td>
+						<td><img src="{%sPh_LAYOUT_PFX%}/images/set_deasupra.gif" border="0" onClick="set_device_icon({%device%},1);send_command('data_request?id=lr_sPhone_action_js&room={%room%}&device={%device%}&service=urn:upnp-org:serviceId:TemperatureSetpoint1_Cool&action=SetCurrentSetpoint&NewCurrentSetpoint='+document.getElementById('NewCurrentSetpoint_Cool_{%device%}').value+'&time={%time%}',{%device%});" border="0"></td>
 					</tr>
 				</table>
-				Current temperature: %{temp}%&deg;<br/>
-				Set point heat: %{setPointHeat}%&deg;<br/>
-				Set point cool: %{setPointCool}%&deg;
-			]]):template (tmpl_params)
-		else
-			return ([[
-				<img src="/port_3480/L_sPhoneUI_layout/icons/thermostat.gif" alt="" width="44" height="43" align="absmiddle" class="icon"/>%{description}%<br>
-				<a href="data_request?id=lr_sPhone_action&room=%{room}%&device=%{device}%&service=urn:upnp-org:serviceId:HVAC_UserOperatingMode1&action=SetModeTarget&NewModeTarget=Off&time=%{time}%"><img src="/port_3480/L_sPhoneUI_layout/buttons/off%{status_off}%.gif" alt="" border="0"/></a>
-				<a href="data_request?id=lr_sPhone_action&room=%{room}%&device=%{device}%&service=urn:upnp-org:serviceId:HVAC_UserOperatingMode1&action=SetModeTarget&NewModeTarget=CoolOn&time=%{time}%"><img src="/port_3480/L_sPhoneUI_layout/buttons/cool%{status_cool}%.gif" alt="" border="0"/></a>
-				<a href="data_request?id=lr_sPhone_action&room=%{room}%&device=%{device}%&service=urn:upnp-org:serviceId:HVAC_UserOperatingMode1&action=SetModeTarget&NewModeTarget=HeatOn&time=%{time}%"><img src="/port_3480/L_sPhoneUI_layout/buttons/heat%{status_heat}%.gif" alt="" border="0"/></a>
-				<a href="data_request?id=lr_sPhone_action&room=%{room}%&device=%{device}%&service=urn:upnp-org:serviceId:HVAC_UserOperatingMode1&action=SetModeTarget&NewModeTarget=AutoChangeOver&time=%{time}%"><img src="/port_3480/L_sPhoneUI_layout/buttons/auto%{status_auto}%.gif" alt="" border="0"/></a> <br/>
-				Fan: <a href="\data_request?id=lr_sPhone_action&room=%{room}%&device=%{device}%&service=urn:upnp-org:serviceId:HVAC_FanOperatingMode1&action=SetMode&NewMode=Auto&time=%{time}%"><img src="/port_3480/L_sPhoneUI_layout/buttons/auto%{status_fan_auto}%.gif" alt="" border="0"/></a>
-				<a href="\data_request?id=lr_sPhone_action&room=%{room}%&device=%{device}%&service=urn:upnp-org:serviceId:HVAC_FanOperatingMode1&action=SetMode&NewMode=ContinuousOn&time=%{time}%"><img src="/port_3480/L_sPhoneUI_layout/buttons/on%{status_fan_on}%.gif" alt="" border="0"/></a><br/>
+				Current temperature: {%temp%}&deg;<br/>
+				Set point heat: {%setPointHeat%}&deg;<br/>
+				Set point cool: {%setPointCool%}&deg;
+			]]):template (tmpl_params)
+		else
+			return ([[
+				<img src="{%sPh_LAYOUT_PFX%}/icons/thermostat.gif" alt="" width="44" height="43" align="absmiddle" class="icon"/>{%description%}<br>
+				<a href="data_request?id=lr_sPhone_action&room={%room%}&device={%device%}&service=urn:upnp-org:serviceId:HVAC_UserOperatingMode1&action=SetModeTarget&NewModeTarget=Off&time={%time%}"><img src="{%sPh_LAYOUT_PFX%}/buttons/off{%status_off%}.gif" alt="" border="0"/></a>
+				<a href="data_request?id=lr_sPhone_action&room={%room%}&device={%device%}&service=urn:upnp-org:serviceId:HVAC_UserOperatingMode1&action=SetModeTarget&NewModeTarget=CoolOn&time={%time%}"><img src="{%sPh_LAYOUT_PFX%}/buttons/cool{%status_cool%}.gif" alt="" border="0"/></a>
+				<a href="data_request?id=lr_sPhone_action&room={%room%}&device={%device%}&service=urn:upnp-org:serviceId:HVAC_UserOperatingMode1&action=SetModeTarget&NewModeTarget=HeatOn&time={%time%}"><img src="{%sPh_LAYOUT_PFX%}/buttons/heat{%status_heat%}.gif" alt="" border="0"/></a>
+				<a href="data_request?id=lr_sPhone_action&room={%room%}&device={%device%}&service=urn:upnp-org:serviceId:HVAC_UserOperatingMode1&action=SetModeTarget&NewModeTarget=AutoChangeOver&time={%time%}"><img src="{%sPh_LAYOUT_PFX%}/buttons/auto{%status_auto%}.gif" alt="" border="0"/></a> <br/>
+				Fan: <a href="\data_request?id=lr_sPhone_action&room={%room%}&device={%device%}&service=urn:upnp-org:serviceId:HVAC_FanOperatingMode1&action=SetMode&NewMode=Auto&time={%time%}"><img src="{%sPh_LAYOUT_PFX%}/buttons/auto{%status_fan_auto%}.gif" alt="" border="0"/></a>
+				<a href="\data_request?id=lr_sPhone_action&room={%room%}&device={%device%}&service=urn:upnp-org:serviceId:HVAC_FanOperatingMode1&action=SetMode&NewMode=ContinuousOn&time={%time%}"><img src="{%sPh_LAYOUT_PFX%}/buttons/on{%status_fan_on%}.gif" alt="" border="0"/></a><br/>
 				<table cellpadding="2" cellspacing="0">
 				<form action="\data_request" method="get">
 				<input type="hidden" name="id" value="lr_sPhone_action">
-				<input type="hidden" name="room" value="%{room}%">
-				<input type="hidden" name="device" value="%{device}%">
+				<input type="hidden" name="room" value="{%room%}">
+				<input type="hidden" name="device" value="{%device%}">
 				<input type="hidden" name="service" value="urn:upnp-org:serviceId:TemperatureSetpoint1_Heat">
 				<input type="hidden" name="action" value="SetCurrentSetpoint">
-				<input type="hidden" name="time" value="%{time}%">
+				<input type="hidden" name="time" value="{%time%}">
 					<tr>
 						<td>Heat: </td>
 						<td><input type="text" name="NewCurrentSetpoint" value="" size="3"></td>
-						<td><input type="image" src="/port_3480/L_sPhoneUI_layout/images/set_deasupra.gif" border="0"></td>
+						<td><input type="image" src="{%sPh_LAYOUT_PFX%}/images/set_deasupra.gif" border="0"></td>
 					</tr>
 				</form>
 				<form action="\data_request" method="get">
 				<input type="hidden" name="id" value="lr_sPhone_action">
-				<input type="hidden" name="room" value="%{room}%">
-				<input type="hidden" name="device" value="%{device}%">
+				<input type="hidden" name="room" value="{%room%}">
+				<input type="hidden" name="device" value="{%device%}">
 				<input type="hidden" name="service" value="urn:upnp-org:serviceId:TemperatureSetpoint1_Cool">
 				<input type="hidden" name="action" value="SetCurrentSetpoint">
-				<input type="hidden" name="time" value="%{time}%">
+				<input type="hidden" name="time" value="{%time%}">
 
 					<tr>
 						<td>Cool: </td>
 						<td><input type="text" name="NewCurrentSetpoint" value="" size="3"></td>
-						<td><input type="image" src="/port_3480/L_sPhoneUI_layout/images/set_deasupra.gif" border="0"></td>
+						<td><input type="image" src="{%sPh_LAYOUT_PFX%}/images/set_deasupra.gif" border="0"></td>
 					</tr>
 				</form>
 				</table>
-				Current temperature: %{temp}%&deg;<br/>
-				Set point heat: %{setPointHeat}%&deg;<br/>
-				Set point cool: %{setPointCool}%&deg;'
+				Current temperature: {%temp%}&deg;<br/>
+				Set point heat: {%setPointHeat%}&deg;<br/>
+				Set point cool: {%setPointCool%}&deg;'
 			]]):template (tmpl_params)
 		end
@@ -623,6 +660,6 @@
 					table.insert (o, ([[
 						<tr>
-							<td>%{part_5}%</td>
-							<td><a href="data_request?id=lr_sPhone_action&room=%{room}%&device=%{device}%&service=urn:micasaverde-com:serviceId:DoorLock1&action=ClearPin&UserCode=%{part_1}%&time=%{time}%"><img src="/port_3480/L_sPhoneUI_layout/images/remove_deasupra.gif" border="0"></a></td>
+							<td>{%part_5%}</td>
+							<td><a href="data_request?id=lr_sPhone_action&room={%room%}&device={%device%}&service=urn:micasaverde-com:serviceId:DoorLock1&action=ClearPin&UserCode={%part_1%}&time={%time%}"><img src="{%sPh_LAYOUT_PFX%}/images/remove_deasupra.gif" border="0"></a></td>
 						</tr>
 						]]):template (tmpl_params))
@@ -634,63 +671,62 @@
 
 
-		if( lul_js=='1' ) then
-			return ([[
-				%{description}%<br>
-				<img src="/port_3480/L_sPhoneUI_layout/images/spacer.gif" border="0" width="20" height="20" id="action_icon_%{device}%">
-				<a href="javascript:void(0);" onClick="set_device_icon(%{device}%,1);send_command('data_request?id=lr_sPhone_action_js&room=%{room}%&device=%{device}%&service=urn:micasaverde-com:serviceId:DoorLock1&action=SetTarget&newTargetValue=0&time=%{time}%',%{device}%)"><img src="/port_3480/L_sPhoneUI_layout/buttons/unlock%{status_unlock}%.gif" alt="" border="0"/></a>
-				<a href="javascript:void(0);" onClick="set_device_icon(%{device}%,1);send_command('data_request?id=lr_sPhone_action_js&room=%{room}%&device=%{device}%&service=urn:micasaverde-com:serviceId:DoorLock1&action=SetTarget&newTargetValue=1&time=%{time}%',%{device}%)"><img src="/port_3480/L_sPhoneUI_layout/buttons/lock%{status_lock}%.gif" alt="" border="0"/></a>
+		if( lul_js == '1') then
+			return ([[
+				{%description%}<br>
+				<img src="{%sPh_LAYOUT_PFX%}/images/spacer.gif" border="0" width="20" height="20" id="action_icon_{%device%}">
+				<a href="javascript:void(0);" onClick="set_device_icon({%device%},1);send_command('data_request?id=lr_sPhone_action_js&room={%room%}&device={%device%}&service=urn:micasaverde-com:serviceId:DoorLock1&action=SetTarget&newTargetValue=0&time={%time%}',{%device%})"><img src="{%sPh_LAYOUT_PFX%}/buttons/unlock{%status_unlock%}.gif" alt="" border="0"/></a>
+				<a href="javascript:void(0);" onClick="set_device_icon({%device%},1);send_command('data_request?id=lr_sPhone_action_js&room={%room%}&device={%device%}&service=urn:micasaverde-com:serviceId:DoorLock1&action=SetTarget&newTargetValue=1&time={%time%}',{%device%})"><img src="{%sPh_LAYOUT_PFX%}/buttons/lock{%status_lock%}.gif" alt="" border="0"/></a>
 				<form action="data_request" method="get">
 				<input type="hidden" name="id" value="lr_sPhone_action">
-				<input type="hidden" name="room" value="%{room}%">
-				<input type="hidden" name="device" value="%{device}%">
+				<input type="hidden" name="room" value="{%room%}">
+				<input type="hidden" name="device" value="{%device%}">
 				<input type="hidden" name="service" value="urn:micasaverde-com:serviceId:DoorLock1">
 				<input type="hidden" name="action" value="SetPin">
-				<input type="hidden" name="time" value="%{time}%">
+				<input type="hidden" name="time" value="{%time%}">
 				<table cellpadding="2" cellspacing="0">
 					<tr>
 						<td>New code:</td>
-						<td><input type="text" name="UserCodeName" id="UserCodeName_%{device}%" value="" size="8"></td>
+						<td><input type="text" name="UserCodeName" id="UserCodeName_{%device%}" value="" size="8"></td>
 					</tr>
 					<tr>
 						<td>PIN code:</td>
-						<td><input type="text" name="newPin" id="newPin_%{device}%" value="" size="8"></td>
+						<td><input type="text" name="newPin" id="newPin_{%device%}" value="" size="8"></td>
 					</tr>
 					<tr>
 						<td></td>
-						<td><img src="/port_3480/L_sPhoneUI_layout/images/set_deasupra.gif" border="0" onClick="set_device_icon(%{device}%,1);send_command('data_request?id=lr_sPhone_action_js&room=%{room}%&device=%{device}%&service=urn:micasaverde-com:serviceId:DoorLock1&action=SetPin&UserCodeName='+document.getElementById('UserCodeName_%{device}%').value+'&newPin='+document.getElementById('UserCodeName_%{device}%').value+'&time=%{time}%',%{device}%)"></td>
+						<td><img src="{%sPh_LAYOUT_PFX%}/images/set_deasupra.gif" border="0" onClick="set_device_icon({%device%},1);send_command('data_request?id=lr_sPhone_action_js&room={%room%}&device={%device%}&service=urn:micasaverde-com:serviceId:DoorLock1&action=SetPin&UserCodeName='+document.getElementById('UserCodeName_{%device%}').value+'&newPin='+document.getElementById('UserCodeName_{%device%}').value+'&time={%time%}',{%device%})"></td>
 					</tr>
 				</table>
 				</form>
-				%{existing_codes}%
-			]]):template (tmpl_params)
-		else
-			return ([[
-				%{description}%<br>
-				<img src="/port_3480/L_sPhoneUI_layout/images/spacer.gif" border="0" width="20" height="20" id="action_icon_%{device}%">
-				<a href="javascript:void(0);" onClick="set_device_icon(%{device}%,1);send_command('data_request?id=lr_sPhone_action_js&room=%{room}%&device=%{device}%&service=urn:micasaverde-com:serviceId:DoorLock1&action=SetTarget&newTargetValue=0&time=%{time}%',%{device}%)"><img src="/port_3480/L_sPhoneUI_layout/buttons/unlock%{status_unlock}%.gif" alt="" border="0"/></a>
-				<a href="javascript:void(0);" onClick="set_device_icon(%{device}%,1);send_command('data_request?id=lr_sPhone_action_js&room=%{room}%&device=%{device}%&service=urn:micasaverde-com:serviceId:DoorLock1&action=SetTarget&newTargetValue=1&time=%{time}%',%{device}%)"><img src="/port_3480/L_sPhoneUI_layout/buttons/lock%{status_lock}%.gif" alt="" border="0"/></a>
+				{%existing_codes%}
+			]]):template (tmpl_params)
+		else
+			return ([[
+				{%lul_description%}<br>
+				<a href="data_request?id=lr_sPhone_action&room={%room%}&device={%device%}&service=urn:micasaverde-com:serviceId:DoorLock1&action=SetTarget&newTargetValue=0&time={%time%}"><img src="{%sPh_LAYOUT_PFX%}/buttons/unlock{%status_unlock%}.gif" alt="" border="0"/></a>
+				<a href="data_request?id=lr_sPhone_action&room={%room%}&device={%device%}&service=urn:micasaverde-com:serviceId:DoorLock1&action=SetTarget&newTargetValue=1&time={%time%}"><img src="{%sPh_LAYOUT_PFX%}/buttons/lock{%status%}.gif" alt="" border="0"/></a>
 				<form action="data_request" method="get">
-				<input type="hidden" name="id" value="lr_sPhone_action">
-				<input type="hidden" name="room" value="%{room}%">
-				<input type="hidden" name="device" value="%{device}%">
-				<input type="hidden" name="service" value="urn:micasaverde-com:serviceId:DoorLock1">
-				<input type="hidden" name="action" value="SetPin">
-				<input type="hidden" name="time" value="%{time}%">
-				<table cellpadding="2" cellspacing="0">
-					<tr>
-						<td>New code:</td>
-						<td><input type="text" name="UserCodeName" id="UserCodeName_%{device}%" value="" size="8"></td>
-					</tr>
-					<tr>
-						<td>PIN code:</td>
-						<td><input type="text" name="newPin" id="newPin_%{device}%" value="" size="8"></td>
-					</tr>
-					<tr>
-						<td></td>
-						<td><img src="/port_3480/L_sPhoneUI_layout/images/set_deasupra.gif" border="0" onClick="set_device_icon(%{device}%,1);send_command('data_request?id=lr_sPhone_action_js&room=%{room}%&device=%{device}%&service=urn:micasaverde-com:serviceId:DoorLock1&action=SetPin&UserCodeName='+document.getElementById('UserCodeName_%{device}%').value+'&newPin='+document.getElementById('UserCodeName_%{device}%').value+'&time=%{time}%',%{device}%)"></td>
-					</tr>
-				</table>
+					<input type="hidden" name="id" value="lr_sPhone_action">
+					<input type="hidden" name="room" value="{%room%}">
+					<input type="hidden" name="device" value="{%device%}">
+					<input type="hidden" name="service" value="urn:micasaverde-com:serviceId:DoorLock1">
+					<input type="hidden" name="action" value="SetPin">
+					<input type="hidden" name="time" value="{%time%}">
+					<table cellpadding="2" cellspacing="0">
+						<tr>
+							<td>New code:</td>
+							<td><input type="text" name="UserCodeName" value="" size="4"></td>
+						</tr>
+						<tr>
+							<td>4 digit code:</td>
+							<td><input type="text" name="newPin" value="" size="4"></td>
+						</tr>
+						<tr>
+							<td></td>
+							<td><input type="image" src="{%sPh_LAYOUT_PFX%}/images/set_deasupra.gif" border="0"></td>
+						</tr>
+					</table>
 				</form>
-				%{existing_codes}%
+				{%existing_codes%}
 			]]):template (tmpl_params)
 		end
@@ -699,4 +735,5 @@
 	function lug_sPhoneRequest_camimg(lul_request,lul_parameters,lul_outputformat)
 		local lul_device = lul_parameters.device
+
 		local tmpl_params = {
 			header = html_header,
@@ -706,38 +743,43 @@
 			time = os.clock(),
 		}
-		local lul_js = lul_parameters.js
-		if( lul_js==nil or tonumber(lul_js)==0 ) then
-			lul_js = 0;
-		end
+		local lul_js = flag(lul_parameters.js)
 		tmpl_params.js = lul_js
+		g_is_remote = flag (lul_parameters.r)
+		
+		local streamingurl = luup.variable_get ('urn:micasaverde-com:serviceId:Camera1', 'DirectStreamingURL', lul_device)
+		if streamingurl and g_is_remote=='1' then
+			streamingurl = string.format('data_request?id=lu_camera_port&DeviceNum=%d', lul_device)
+		end
+		tmpl_params.url = streamingurl or ("data_request?id=cam_image&Device_Num={%device%}&room={%room%}&time={%time%}"):template(tmpl_params)
+		
 
 		if( lul_js=='1' ) then
 			return ([[
-				%{header}%
-				<div id="toolbar" class="toolbar"> <a href="data_request?id=lr_sPhone_room&room=%{room}%&time=%{time}%"><img src="/port_3480/L_sPhoneUI_layout/images/backButton.gif" border="0"></a> </div>
+				{%header%}
+				<div id="toolbar" class="toolbar"> <a href="data_request?id=lr_sPhone_room&room={%room%}&time={%time%}"><img src="{%sPh_LAYOUT_PFX%}/images/backButton.gif" border="0"></a> </div>
 				<div align="center">View camera <br/>
-				<img src="data_request?id=cam_image&Device_Num=%{device}%&room=%{room}%&time=%{time}%" id="view_%{device}%"><br>
-				<img src="/port_3480/L_sPhoneUI_layout/images/spacer.gif" border="0" width="20" height="20" id="action_icon_%{device}%"><br>
-				<a href="javascript:void(0)" onClick="sp_move_camera(%{device}%,'MoveUp');"><img src="/port_3480/L_sPhoneUI_layout/images/buupdeasupra.gif" border="0"></a>
-				<a href="javascript:void(0)" onClick="sp_move_camera(%{device}%,'MoveDown');"><img src="/port_3480/L_sPhoneUI_layout/images/budowndeasupra.gif" border="0"></a>
-				<a href="javascript:void(0)" onClick="sp_move_camera(%{device}%,'MoveLeft');"><img src="/port_3480/L_sPhoneUI_layout/images/buldeasupra.gif" border="0"></a>
-				<a href="javascript:void(0)" onClick="sp_move_camera(%{device}%,'MoveRight');"><img src="/port_3480/L_sPhoneUI_layout/images/burdeasupra.gif" border="0"></a>
-				<a href="javascript:void(0)" onClick="sp_move_camera(%{device}%,'ZoomIn');"><img src="/port_3480/L_sPhoneUI_layout/images/buplusdeasupra.gif" border="0"></a>
-				<a href="javascript:void(0)" onClick="sp_move_camera(%{device}%,'ZoomOut');"><img src="/port_3480/L_sPhoneUI_layout/images/buminusdeasupra.gif" border="0"></a>
-				<br><a href="data_request?id=lr_sPhone_camimg&device=%{device}%&js=%{js}%&time=%{time}%&js=%{js}%">Refresh</a>
-				%{footer}%
-			]]):template (tmpl_params)
-		else
-			return ([[
-				<div id="toolbar" class="toolbar"> <a href="data_request?id=lr_sPhone_room&room=%{room}%&time=%{time}%"><img src="/port_3480/L_sPhoneUI_layout/images/backButton.gif" border="0"></a> </div>
+				<img src="{%url%}" id="view_{%device%}"><br>
+				<img src="{%sPh_LAYOUT_PFX%}/images/spacer.gif" border="0" width="20" height="20" id="action_icon_{%device%}"><br>
+				<a href="javascript:void(0)" onClick="sp_move_camera({%device%},'MoveUp');"><img src="{%sPh_LAYOUT_PFX%}/images/buupdeasupra.gif" border="0"></a>
+				<a href="javascript:void(0)" onClick="sp_move_camera({%device%},'MoveDown');"><img src="{%sPh_LAYOUT_PFX%}/images/budowndeasupra.gif" border="0"></a>
+				<a href="javascript:void(0)" onClick="sp_move_camera({%device%},'MoveLeft');"><img src="{%sPh_LAYOUT_PFX%}/images/buldeasupra.gif" border="0"></a>
+				<a href="javascript:void(0)" onClick="sp_move_camera({%device%},'MoveRight');"><img src="{%sPh_LAYOUT_PFX%}/images/burdeasupra.gif" border="0"></a>
+				<a href="javascript:void(0)" onClick="sp_move_camera({%device%},'ZoomIn');"><img src="{%sPh_LAYOUT_PFX%}/images/buplusdeasupra.gif" border="0"></a>
+				<a href="javascript:void(0)" onClick="sp_move_camera({%device%},'ZoomOut');"><img src="{%sPh_LAYOUT_PFX%}/images/buminusdeasupra.gif" border="0"></a>
+				<br><a href="data_request?id=lr_sPhone_camimg&device={%device%}&js={%js%}&time={%time%}&r={%g_is_remote%}">Refresh</a>
+				{%footer%}
+			]]):template (tmpl_params)
+		else
+			return ([[
+				<div id="toolbar" class="toolbar"> <a href="data_request?id=lr_sPhone_room&room={%room%}&time={%time%}"><img src="{%sPh_LAYOUT_PFX%}/images/backButton.gif" border="0"></a> </div>
 				<div align="center">View camera <br/>
-				<img src="data_request?id=cam_image&Device_Num=%{device}%&room=%{room}%&time=%{time}%"><br>
-				<a href="data_request?id=lr_sPhone_action&room=%{room}%&device=%{device}%&service=urn:micasaverde-com:serviceId:PanTiltZoom1&action=MoveUp"><img src="/port_3480/L_sPhoneUI_layout/images/buupdeasupra.gif" border="0"></a>
-				<a href="data_request?id=lr_sPhone_action&room=%{room}%&device=%{device}%&service=urn:micasaverde-com:serviceId:PanTiltZoom1&action=MoveDown"><img src="/port_3480/L_sPhoneUI_layout/images/budowndeasupra.gif" border="0"></a>
-				<a href="data_request?id=lr_sPhone_action&room=%{room}%&device=%{device}%&service=urn:micasaverde-com:serviceId:PanTiltZoom1&action=MoveLeft"><img src="/port_3480/L_sPhoneUI_layout/images/buldeasupra.gif" border="0"></a>
-				<a href="data_request?id=lr_sPhone_action&room=%{room}%&device=%{device}%&service=urn:micasaverde-com:serviceId:PanTiltZoom1&action=MoveRight"><img src="/port_3480/L_sPhoneUI_layout/images/burdeasupra.gif" border="0"></a>
-				<a href="data_request?id=lr_sPhone_action&room=%{room}%&device=%{device}%&service=urn:micasaverde-com:serviceId:PanTiltZoom1&action=ZoomIn"><img src="/port_3480/L_sPhoneUI_layout/images/buplusdeasupra.gif" border="0"></a>
-				<a href="data_request?id=lr_sPhone_action&room=%{room}%&device=%{device}%&service=urn:micasaverde-com:serviceId:PanTiltZoom1&action=ZoomOut"><img src="/port_3480/L_sPhoneUI_layout/images/buminusdeasupra.gif" border="0"></a>
-				<br><a href="data_request?id=lr_sPhone_camimg&device=%{device}%&time=%{time}%&js=%{js}%">Refresh</a>
+				<img src="{%url%}"><br>
+				<a href="data_request?id=lr_sPhone_action&room={%room%}&device={%device%}&service=urn:micasaverde-com:serviceId:PanTiltZoom1&action=MoveUp"><img src="{%sPh_LAYOUT_PFX%}/images/buupdeasupra.gif" border="0"></a>
+				<a href="data_request?id=lr_sPhone_action&room={%room%}&device={%device%}&service=urn:micasaverde-com:serviceId:PanTiltZoom1&action=MoveDown"><img src="{%sPh_LAYOUT_PFX%}/images/budowndeasupra.gif" border="0"></a>
+				<a href="data_request?id=lr_sPhone_action&room={%room%}&device={%device%}&service=urn:micasaverde-com:serviceId:PanTiltZoom1&action=MoveLeft"><img src="{%sPh_LAYOUT_PFX%}/images/buldeasupra.gif" border="0"></a>
+				<a href="data_request?id=lr_sPhone_action&room={%room%}&device={%device%}&service=urn:micasaverde-com:serviceId:PanTiltZoom1&action=MoveRight"><img src="{%sPh_LAYOUT_PFX%}/images/burdeasupra.gif" border="0"></a>
+				<a href="data_request?id=lr_sPhone_action&room={%room%}&device={%device%}&service=urn:micasaverde-com:serviceId:PanTiltZoom1&action=ZoomIn"><img src="{%sPh_LAYOUT_PFX%}/images/buplusdeasupra.gif" border="0"></a>
+				<a href="data_request?id=lr_sPhone_action&room={%room%}&device={%device%}&service=urn:micasaverde-com:serviceId:PanTiltZoom1&action=ZoomOut"><img src="{%sPh_LAYOUT_PFX%}/images/buminusdeasupra.gif" border="0"></a>
+				<br><a href="data_request?id=lr_sPhone_camimg&device={%device%}&time={%time%}&js={%js%}&r={%g_is_remote%}">Refresh</a>
 			]]):template (tmpl_params)
 		end
@@ -747,10 +789,11 @@
 	function lug_sPhoneRequest_room(lul_request,lul_parameters,lul_outputformat)
 		local lul_room = lul_parameters.room
-		local lul_js = lul_parameters.js
-		if( lul_js==nil or tonumber(lul_js)==0 ) then
-			lul_js = 0;
-		end
-
-		luup.log("lul_js = " .. lul_js)
+		local lul_js = flag(lul_parameters.js)
+		g_is_remote = flag (lul_parameters.r)
+-- 		if( lul_js==nil or tonumber(lul_js)==0 ) then
+-- 			lul_js = 0;
+-- 		end
+
+		luup.log("lul_js = " .. tostring(lul_js))
 
 		if( lul_room==nil or tonumber(lul_room)==0 ) then -- Room 0 means the main menu
@@ -765,5 +808,5 @@
 
 		local lul_html = {html_header, ([[
-			<div id="toolbar" class="toolbar"> <div class="b_left"><a href="data_request?id=lr_sPhone"><img src="/port_3480/L_sPhoneUI_layout/images/backButton.gif" border="0"></a></div>  <div align="right" class="b_right"><a href="data_request?id=lr_sPhone_room&room=%{room}%&time=%{time}%&js=%{js}%"><img src="/port_3480/L_sPhoneUI_layout/images/refresh.gif" border="0"></a></div></div>
+			<div id="toolbar" class="toolbar"> <div class="b_left"><a href="data_request?id=lr_sPhone"><img src="{%sPh_LAYOUT_PFX%}/images/backButton.gif" border="0"></a></div>  <div align="right" class="b_right"><a href="data_request?id=lr_sPhone_room&room={%room%}&time={%time%}&js={%js%}&r={%g_is_remote%}"><img src="{%sPh_LAYOUT_PFX%}/images/refresh.gif" border="0"></a></div></div>
 			<ul title="Room" selected="true">
 		]]):template (tmpl_params)}
@@ -783,8 +826,8 @@
 					table.insert (lul_html, ([[
 						<li class="bg">
-							<a href="data_request?id=lr_sPhone_action&remote=%{remote}%&page=%{page}%&room=%{room}%&device=0&service=urn:micasaverde-com:serviceId:HomeAutomationGateway1&action=RunScene&SceneNum=%{scene}%&time=%{time}%">
-								<img src="/port_3480/L_sPhoneUI_layout/buttons/go.gif" alt="" width="36" height="36" border="0" align="absmiddle" class="icon"/>
+							<a href="data_request?id=lr_sPhone_action&remote={%remote%}&page={%page%}&room={%room%}&device=0&service=urn:micasaverde-com:serviceId:HomeAutomationGateway1&action=RunScene&SceneNum={%scene%}&time={%time%}">
+								<img src="{%sPh_LAYOUT_PFX%}/buttons/go.gif" alt="" width="36" height="36" border="0" align="absmiddle" class="icon"/>
 							</a>
-							%{description}%
+							{%description%}
 						</li>
 					]]):template (tmpl_params))
@@ -792,9 +835,9 @@
 					table.insert (lul_html, ([[
 						<li class="bg">
-							<img src="/port_3480/L_sPhoneUI_layout/images/spacer.gif" border="0" width="20" height="20" id="scene_action_icon_%{scene}%" style="vertical-align:middle">
-							<a href="javascript:void(0)" onClick="set_scene_icon(%{scene}%,1);sp_run_scene('data_request?id=lr_sPhone_action_js&remote=%{remote}%&page=%{page}%&room=%{room}%&device=0&service=urn:micasaverde-com:serviceId:HomeAutomationGateway1&action=RunScene&SceneNum=%{scene}%&time=%{time}%',%{scene}%);">
-								<img src="/port_3480/L_sPhoneUI_layout/buttons/go.gif" alt="" width="36" height="36" border="0" style="vertical-align:middle" class="icon"/>
+							<img src="{%sPh_LAYOUT_PFX%}/images/spacer.gif" border="0" width="20" height="20" id="scene_action_icon_{%scene%}" style="vertical-align:middle">
+							<a href="javascript:void(0)" onClick="set_scene_icon({%scene%},1);sp_run_scene('data_request?id=lr_sPhone_action_js&remote={%remote%}&page={%page%}&room={%room%}&device=0&service=urn:micasaverde-com:serviceId:HomeAutomationGateway1&action=RunScene&SceneNum={%scene%}&time={%time%}',{%scene%});">
+								<img src="{%sPh_LAYOUT_PFX%}/buttons/go.gif" alt="" width="36" height="36" border="0" style="vertical-align:middle" class="icon"/>
 							</a>
-							%{description}%
+							{%description%}
 						</li>
 					]]):template (tmpl_params))
@@ -804,5 +847,5 @@
 		end
 
-		list_devices (lul_room, lul_html)
+		list_devices (lul_room, lul_html, lul_js)
 
 		table.insert (lul_html, html_footer)
