Page 1 of 1
How can I open an external webpage from a script
Posted: Monday 03 September 2018 17:47
by DutchHans
Hi all...
I want to open (really open; not reading) from a lua script.
How can I do that... I have tried os.execute(start...etc) and os.execute(open etc)...but no luck
Anyone who can put me in the right direction?
Thanks in advance,
Hans
Re: How can I open an external webpage from a script
Posted: Monday 03 September 2018 18:42
by ben53252642
Lua example that will work on Linux / Raspberry Pi, make sure curl is installed: apt-get install curl
Code: Select all
commandArray = {}
if (devicechanged["Bedlamp Switch"] == "Off") then
os.execute ('curl -s "http://192.168.0.5/pauseall"')
end
return commandArray
Re: How can I open an external webpage from a script
Posted: Tuesday 04 September 2018 17:44
by DutchHans
Good evening...
I have tried the code but nothing happens... maybe I wasn't clear...
Here is what I want to achieve.. I read Titel, startingtime, channel etc from an XML file and create selectorswitches out of them with "Watch", "Record", "Info" and "delete"
If I click on "Info" I would like to open a webpage with Info about that movie.. in a new window on top of the GUI of Domoticz.
I have no clue if it is possible...
Any help is appreciated,
Hans
Re: How can I open an external webpage from a script
Posted: Wednesday 05 September 2018 8:47
by philchillbill
So does this mean you got the json for auto-populating the selector switch figured out? You posted about that a while back but never commented on my answer telling you how to do it.
Sent from my iPhone using Tapatalk
Re: How can I open an external webpage from a script
Posted: Wednesday 05 September 2018 19:33
by DutchHans
I am sorry,
Yes i figured it all out and it works like a charm.. i will put the code here once I am home..
Regards,Hans
Re: How can I open an external webpage from a script
Posted: Wednesday 05 September 2018 23:33
by philchillbill
Sent from my iPhone using Tapatalk
Re: How can I open an external webpage from a script
Posted: Thursday 06 September 2018 20:13
by DutchHans
Ok, hereby the code:
Please keep in mind that I am not a programmer but this code works for me.
First I read the XML and distilled my info out of it:
I have a dummyswitch with a timer at 00:01 every day
This creates the Selectorswitches for the films:
Code: Select all
local b='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
-- encoding
function enc(data)
return ((data:gsub('.', function(x)
local r,b='',x:byte()
for i=8,1,-1 do r=r..(b%2^i-b%2^(i-1)>0 and '1' or '0') end
return r;
end)..'0000'):gsub('%d%d%d?%d?%d?%d?', function(x)
if (#x < 6) then return '' end
local c=0
for i=1,6 do c=c+(x:sub(i,i)=='1' and 2^(6-i) or 0) end
return b:sub(c+1,c+1)
end)..({ '', '==', '=' })[#data%3+1])
end
-- decoding
function dec(data)
data = string.gsub(data, '[^'..b..'=]', '')
return (data:gsub('.', function(x)
if (x == '=') then return '' end
local r,f='',(b:find(x)-1)
for i=6,1,-1 do r=r..(f%2^i-f%2^(i-1)>0 and '1' or '0') end
return r;
end):gsub('%d%d%d?%d?%d?%d?%d?%d?', function(x)
if (#x ~= 8) then return '' end
local c=0
for i=1,8 do c=c+(x:sub(i,i)=='1' and 2^(8-i) or 0) end
return string.char(c)
end))
end
commandArray = {}
if devicechanged['CreateSwitch'] == 'On' then
local file = io.open(ResultFilmInfo, "rb") -- Open file for reading (binary data)
for instance in file:read("*a"):gmatch("<film>(.-)</film>") do
Titel = instance:match("^.+<titel>(.+)</titel>.+$")
Jaar = instance:match("^.+<jaar>(.+)</jaar>.+$")
Zender = instance:match("^.+<zender>(.+)</zender>.+$")
Synopsis = instance:match("^.+<synopsis>(.+)</synopsis>.+$")
Link = instance:match("^.+<ft_link>(.+)</ft_link>.+$")
Starttijd_Epoch = instance:match("^.+<starttijd>(.+)</starttijd>.+$")
--Starttijd = os.date('%Y-%m-%d %H:%M:%S', Starttijd_Epoch)
Starttijd = os.date('%H:%M', Starttijd_Epoch)
Eindtijd_Epoch = instance:match("^.+<eindtijd>(.+)</eindtijd>.+$")
Eindtijd = os.date('%Y-%m-%d %H:%M:%S', Eindtijd_Epoch)
commandArray[#commandArray+1] = {['OpenURL'] ="http://xx.xx.xx.xx:8081/json.htm?type=createdevice&idx=4&sensorname="..encodeString(Titel).."%20-%20"..Starttijd.."&sensormappedtype=0xF43E"}
end
commandArray['CreateSwitch'] = 'Off'
end
One minute later I change all the Selectorswitchs (populate)
Code: Select all
local b='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
-- encoding
function enc(data)
return ((data:gsub('.', function(x)
local r,b='',x:byte()
for i=8,1,-1 do r=r..(b%2^i-b%2^(i-1)>0 and '1' or '0') end
return r;
end)..'0000'):gsub('%d%d%d?%d?%d?%d?', function(x)
if (#x < 6) then return '' end
local c=0
for i=1,6 do c=c+(x:sub(i,i)=='1' and 2^(6-i) or 0) end
return b:sub(c+1,c+1)
end)..({ '', '==', '=' })[#data%3+1])
end
-- decoding
function dec(data)
data = string.gsub(data, '[^'..b..'=]', '')
return (data:gsub('.', function(x)
if (x == '=') then return '' end
local r,f='',(b:find(x)-1)
for i=6,1,-1 do r=r..(f%2^i-f%2^(i-1)>0 and '1' or '0') end
return r;
end):gsub('%d%d%d?%d?%d?%d?%d?%d?', function(x)
if (#x ~= 8) then return '' end
local c=0
for i=1,8 do c=c+(x:sub(i,i)=='1' and 2^(8-i) or 0) end
return string.char(c)
end))
end
commandArray = {}
if devicechanged['ChangeSwitch'] == 'On' then
local file = io.open(ResultFilmInfo, "rb") -- Open file for reading (binary data)
for changeButName in file:read("*a"):gmatch("<film>(.-)</film>") do
Titel = changeButName:match("^.+<titel>(.+)</titel>.+$")
Jaar = changeButName:match("^.+<jaar>(.+)</jaar>.+$")
Zender = changeButName:match("^.+<zender>(.+)</zender>.+$")
Synopsis = changeButName:match("^.+<synopsis>(.+)</synopsis>.+$")
Starttijd_Epoch = changeButName:match("^.+<starttijd>(.+)</starttijd>.+$")
--Starttijd = os.date('%Y-%m-%d %H:%M:%S', Starttijd_Epoch)
Starttijd = os.date('%H:%M', Starttijd_Epoch)
Eindtijd_Epoch = changeButName:match("^.+<eindtijd>(.+)</eindtijd>.+$")
Eindtijd = os.date('%Y-%m-%d %H:%M:%S', Eindtijd_Epoch)
TitelTemp = Titel.." - "..Starttijd
local titelIDX = otherdevices_idx[TitelTemp]
print(titelIDX)
if titelIDX ~= nil then
commandArray[#commandArray+1] = {['OpenURL'] ="http://xx.xx.xx.xx:8081/json.htm?type=setused&idx="..titelIDX.."&name="..encodeString(Titel).."%20-%20"..Starttijd.."&description=&strparam1=&strparam2=&protected=false&switchtype=18&customimage=0&used=true&addjvalue=0&addjvalue2=0&options="..enc("LevelNames%3AOff%7CRecord%7CWatch%7CDelete%3BLevelActions%3A%7C%7C%7C%3BSelectorStyle%3A0%3BLevelOffHidden%3Atrue%3B")..""}
end
end
commandArray['ChangeSwitch'] = 'Off'
end
return commandArray
Et Voila populated selectorswitches with Record, Watch or delete.
In another script I check the switches witch either programms the Recorder or sets an Timer so that everything is prepared to watch the movie, Reciever, sound, blinds and lights. Then a notify on my Phone or deletes the switch.
Maybe this can be of any help for somone.. Success
Regards, Hans
Re: How can I open an external webpage from a script
Posted: Saturday 08 September 2018 13:33
by philchillbill
To answer the original question, under Ubuntu (so likely also under Raspbian) I can type the following in the command line
and it launches firefox with that website loading. Maybe you can use that syntax in your os.execute instead of using curl?
Re: How can I open an external webpage from a script
Posted: Saturday 08 September 2018 15:47
by DutchHans
I will investigate...
When i click a dummy button in the GUI i want to open an external page.. eg.
www.google.com in a new window on top of the GUI from Domoticz... (As a hyperlink in html)...
Regards,
Hans
Re: How can I open an external webpage from a script
Posted: Saturday 08 September 2018 21:02
by DutchHans
I am stuck...is there anybody who can tell me if it is possible?.. i want to open a page eg.
Http://www.google.com when a Switch changes from off to on
I want this page on top of the GUI of Domotics.. as if clicked on a hyperlink which opens a page in a new window.
Any help is appreciated
Hans
Re: How can I open an external webpage from a script
Posted: Sunday 30 September 2018 12:41
by zicht
On what platform (win/osx/android ?
On windows you can execute a powershell command to have things happening (whatever you want including opening a page in a browser)
This of course happens on the "running host" not on the client that is viewed on another medium !!
What you can do is not exactly what you want but put a link inside a text sensor, so the user can choose to click it.
As domoticz client is running a HTML page, you can invoke a popup on clicking, but i do not see a posibility how to do this without user intervention.
Mayby with changing a html code inside a text sensor that is displayed , but then that screen has to be upfront
When you alter the main HTML codes there will be more possible, but that will be overwritten by every update of domoticz !
Or you could make a hidden HTML element that get's unhidden by another running code or calling some of the existing code
Conclusion there is no out of the box solution for this, but i can see some use for this as wel
Re: How can I open an external webpage from a script
Posted: Friday 15 February 2019 9:45
by DutchHans
Here's the idea again.
I have, for example, a selectorswitch... when I press a selection it should work like a hyperlink in a webpage: <a href='
www.google.com target='_blank''> which results in a new window on top showing the google webpage.
Is there a way of doing it?
regards, Hans
Re: How can I open an external webpage from a script
Posted: Wednesday 06 March 2019 6:54
by zicht
maybe you can call a script and from the script use the liua command Os.execute or similar to open the browser. In theory you could pass a parameter containing the website to open. All depends on the browser you use.
This would only work on the equipment running domoticz, not on other clients.
BUT there is a hudge risk of making domoticz hang or slow this way.. depending on your platform there are ways to avoid this, but i have no experience with this. (Lua keeps waiting until it all has finished !)
---
If you want to do it on clients you need to alter HTML code, insert a hidden popup (CSS.Javascript), make a depended call from HTML/Javascript to make this popup visible on a trigger on the server. You need a creative mind to get it working

Again, i have no experience and am not a fan of altering HTML, my trials on this part ended always in broken things or security risks.
Re: How can I open an external webpage from a script
Posted: Wednesday 06 March 2019 7:04
by DutchHans
Thank you for your answer.. I have figured out that it is possible as a link in the title of a device.ie. <a href="
http://www.google.com" target=_blank>Title of a device</a>
It shows the title and makes it interactive. No matter on what browser you view the page.
But I want to do the same with a button from a selectorswitch.
Regards, Hans
Re: How can I open an external webpage from a script
Posted: Thursday 02 April 2020 16:32
by Roma111
Hi Hans
I integrated your hyperlink idea in my Dasboard and it works great. Thanks.
After the upgrade to the new version 2020.1 the hyperlink is cut as soon as I update the name field of the switch.
For example:
Before:<a href="
http://www.google.com" target_blank<Title of device</a>
After upfdating the field: Title of device</a>
So the hyperlink "<a href....." is cut.
Any idea for another solution?
Regards
Roman