How can I open an external webpage from a script
Moderator: leecollings
-
- Posts: 230
- Joined: Friday 03 April 2015 20:44
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Germany (near dutch border)
- Contact:
How can I open an external webpage from a script
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
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
-
- Posts: 543
- Joined: Saturday 02 July 2016 5:17
- Target OS: Linux
- Domoticz version: Beta
- Contact:
Re: How can I open an external webpage from a script
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
Unless otherwise stated, all my code is released under GPL 3 license: https://www.gnu.org/licenses/gpl-3.0.en.html
-
- Posts: 230
- Joined: Friday 03 April 2015 20:44
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Germany (near dutch border)
- Contact:
Re: How can I open an external webpage from a script
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
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
- philchillbill
- Posts: 399
- Joined: Monday 12 September 2016 13:47
- Target OS: Linux
- Domoticz version: beta
- Location: Eindhoven. NL
- Contact:
Re: How can I open an external webpage from a script
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
Sent from my iPhone using Tapatalk
Alexa skills author: EvoControl, Statereport, MediaServer, LMS-lite
-
- Posts: 230
- Joined: Friday 03 April 2015 20:44
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Germany (near dutch border)
- Contact:
Re: How can I open an external webpage from a script
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
Yes i figured it all out and it works like a charm.. i will put the code here once I am home..
Regards,Hans
- philchillbill
- Posts: 399
- Joined: Monday 12 September 2016 13:47
- Target OS: Linux
- Domoticz version: beta
- Location: Eindhoven. NL
- Contact:
Re: How can I open an external webpage from a script

Sent from my iPhone using Tapatalk
Alexa skills author: EvoControl, Statereport, MediaServer, LMS-lite
-
- Posts: 230
- Joined: Friday 03 April 2015 20:44
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Germany (near dutch border)
- Contact:
Re: How can I open an external webpage from a script
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:
One minute later I change all the Selectorswitchs (populate)
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
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
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
- philchillbill
- Posts: 399
- Joined: Monday 12 September 2016 13:47
- Target OS: Linux
- Domoticz version: beta
- Location: Eindhoven. NL
- Contact:
Re: How can I open an external webpage from a script
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?
Code: Select all
firefox "www.bmw.nl"
Alexa skills author: EvoControl, Statereport, MediaServer, LMS-lite
-
- Posts: 230
- Joined: Friday 03 April 2015 20:44
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Germany (near dutch border)
- Contact:
Re: How can I open an external webpage from a script
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
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
-
- Posts: 230
- Joined: Friday 03 April 2015 20:44
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Germany (near dutch border)
- Contact:
Re: How can I open an external webpage from a script
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
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
-
- Posts: 272
- Joined: Sunday 11 May 2014 11:09
- Target OS: Windows
- Domoticz version: 2023.1+
- Location: NL
- Contact:
Re: How can I open an external webpage from a script
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
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
Rpi & Win x64. Using : cam's,RFXCom, LaCrosse, RFY, HuE, google, standard Lua, Tasker, Waze traveltime, NLAlert&grip2+,curtains, vacuum, audioreceiver, smart-heating&cooling + many more (= automate all repetitive simple tasks)
-
- Posts: 230
- Joined: Friday 03 April 2015 20:44
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Germany (near dutch border)
- Contact:
Re: How can I open an external webpage from a script
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
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
-
- Posts: 272
- Joined: Sunday 11 May 2014 11:09
- Target OS: Windows
- Domoticz version: 2023.1+
- Location: NL
- Contact:
Re: How can I open an external webpage from a script
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.
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

Rpi & Win x64. Using : cam's,RFXCom, LaCrosse, RFY, HuE, google, standard Lua, Tasker, Waze traveltime, NLAlert&grip2+,curtains, vacuum, audioreceiver, smart-heating&cooling + many more (= automate all repetitive simple tasks)
-
- Posts: 230
- Joined: Friday 03 April 2015 20:44
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Germany (near dutch border)
- Contact:
Re: How can I open an external webpage from a script
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
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
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
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
Who is online
Users browsing this forum: No registered users and 1 guest