Notice: This forum has been recovered from an old backup, so some content, links, and dates may be outdated. The forum is currently read-only while we restore sign-in and registration functionality. Details

If you find this forum valuable and would like to help keep it online, donations to help cover hosting and domain costs are greatly appreciated, but never expected. You can support the forum through Buy Me a Coffee or Ko-fi. Thank you for helping preserve the EventGhost community.

http post to loxone miniserver

If you have a question or need help, this is the place to be.
User avatar
kgschlosser
Site Admin
Posts: 5190
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: http post to loxone miniserver

Post by kgschlosser »

i am thinking that it's because of the username being there with no password i have had that problem before and never really researched how to go about it

so you may want to add a password to the thing to see if it works
If you like the work I have been doing then feel free to Image
V_J
Experienced User
Posts: 165
Joined: Tue Mar 04, 2014 9:00 am

Re: http post to loxone miniserver

Post by V_J »

I tried without password as with password did not work. Next time, I'll try the piece of code I found on Stackoverflow, to see if that will allow me to connect to it.
(after that, I can continue with integrating xap: I need eventghost to translate the xap to http commands :-))

edit: thanks Pako for splitting the topic. And sorry for messing up with the other thread. :oops:
V_J
Experienced User
Posts: 165
Joined: Tue Mar 04, 2014 9:00 am

Re: http post to loxone miniserver

Post by V_J »

Ok, found something that works, code taken from my previous link to stackoverflow, corrected one mistake in variable name:

Code: Select all

import urllib2
password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
top_level_url = "http://example.com/foo/"
password_mgr.add_password(None, top_level_url, username, password)
handler = urllib2.HTTPBasicAuthHandler(password_mgr)
opener = urllib2.build_opener(handler)
opener.open(top_level_url)
urllib2.install_opener(opener)
I have not tried it on an account without password, but I actually prefer not to have such accounts. The code above works for sending to a Loxone Miniserver (version 7.4.4.14) using the http api. :)
User avatar
kgschlosser
Site Admin
Posts: 5190
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: http post to loxone miniserver

Post by kgschlosser »

well hell great you found a solution, that's awesome, i haven't dove into the urllib to much, i think i should to see what it can do.
If you like the work I have been doing then feel free to Image
V_J
Experienced User
Posts: 165
Joined: Tue Mar 04, 2014 9:00 am

Re: http post to loxone miniserver

Post by V_J »

Yes. Now I need to figure out how to get part of the url to be from the result or payload a different plugin (xap, Marantz, ...). I basically use the http post to set variables in the Loxone server, where I have variables for e.g. title of what is now playing or some status things. The url format is
http://..... /variablename/value
So the variablename is hardcoded, and the value has to be what I get. It might be that Pako's new version of the webserver would allow it, but I need to try that one still.
User avatar
kgschlosser
Site Admin
Posts: 5190
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: http post to loxone miniserver

Post by kgschlosser »

here is a much more simplified version of the password management, that is the loxone uses basic auth (which it probably does)

i don't know how the payload data is formatted that you are receiving or in what manner you are trying process the event/payload so without specifics this is as far as i can help..

i would need to see a copy of the actual event with the payload, and exactly what you are trying to accomplish with the loxone server the exact URL with the variable name you are trying to set.
i mean you can leave out the beginning bits but i need to know everything from the first / on

but this is a tester for ya if you want, in this you can put the variable name in the first slot of the eg.event.payload and the data you want written to that variable in the second.

Code: Select all

eg.event.payload = ['test', 'test.html']
URL = 'http://LOXONESERVER:PORT/'+'/'.join(eg.event.payload)
username = "LOXONEUSERNAME"
password = ""

import urllib2, base64

try:
	request = urllib2.Request(URL)
	base64string = base64.encodestring('%s:%s' % (username, password)).replace('\n', '')
	request.add_header("Authorization", "Basic %s" % base64string)   
except Exception as err:
	print 'urllib2 Header Error: ', err
else:
    try:
        print urllib2.urlopen(request).read()
    except urllib2.HTTPError as err:
    	print 'urllib2 Webpage Error: ', err
If you like the work I have been doing then feel free to Image
V_J
Experienced User
Posts: 165
Joined: Tue Mar 04, 2014 9:00 am

Re: http post to loxone miniserver

Post by V_J »

The variable name is just a name that I have to have declared in the Loxone; in EventGhost this can be hardcoded in the url. The data is just e.g. a title from the xap plugin, or a value/string received via another plugin.

It is basically option 3 from this page:
http://www.loxone.com/enen/service/docu ... al-io.html
This option is currently the only one in Loxone that allows you to send text to a variable. All other protocols are limited to single characters or numbers. The code I posted works for a hardcoded variable name and a hardcoded content.

I'll try your code, I suspect the join command is the key command to join the payload with the url. :)

Not sure when I'll have time though, next couple of days are hectic...
User avatar
kgschlosser
Site Admin
Posts: 5190
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: http post to loxone miniserver

Post by kgschlosser »

As far as the payload goes you would have to do this if you were going to use Xap

Code: Select all

URL += SOMEVARIABLENAME+"/"+eg.event.payload["Title"]
The join is only for joining a list of strings together

As such

var = ["Test1", "Test2"]

That is what a list of strings looks like

var = '/'.join(var)

That if you printed would show this

"Test1/Test2"

The payload in the xAP plugin is a dictionary not a list
If you like the work I have been doing then feel free to Image
V_J
Experienced User
Posts: 165
Joined: Tue Mar 04, 2014 9:00 am

Re: http post to loxone miniserver

Post by V_J »

Yeah... I know it is a dict, but it just abbreviated it a bit in my post. :) It did not work as I had a stupid syntax error. But now it all works. I had to encode the payload, as the string can contain spaces, but that was easy. So now it works!!

I managed to send all the data I need to the Loxone, now the matter is processing it there, mainly to show on the userinterface. :)
User avatar
kgschlosser
Site Admin
Posts: 5190
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: http post to loxone miniserver

Post by kgschlosser »

Well that's good ya got it working

Before ya know it you will be writing a plugin specifically to talk to the loxone server over http

That's what happened with me I have an audio video receiver and there was a plugin for it tho not really taking advantage of the AVR and it would also throw errors so I wanted it to do more things so I cut it all apart and thats pretty much where I started.

Between that and Google and a lot of missing hair on my head.

Its actually not all that hard once ya have the vocabulary and syntax down
If you like the work I have been doing then feel free to Image
V_J
Experienced User
Posts: 165
Joined: Tue Mar 04, 2014 9:00 am

Re: http post to loxone miniserver

Post by V_J »

kgschlosser wrote:Before ya know it you will be writing a plugin specifically to talk to the loxone server over http
Yeah... I know what you mean.

It happened to me with the Marantz Serial plugin, which I expanded with much more commands (named it Marantz RS232). I would have loved to make it fully bi-directional (now, EG has to send a command and get a reply; changes done on the amplifier are not sent to EG), but I did not manage. The data sent by the amplifier on the serial port when the feature is enabled and a setting is changed is quite extensive. I also figured I would not need to use it that often: amplifier is out of reach for normal use and if everything is set from EventGhost, then I should have no problems.
edit: but I should try again... it would seem so magical to press a button on the amplifier and see the change on e.g. the loxone interface... :) Perhaps I could try to modify from the point of view of the serial port plugin rather than from the Marantz Serial plugin... :)

It will not happen with the Loxone thing. For sure I could do things more elegantly, but I'll just do it with small Python scripts. For now, I just want something that works. I've been working on the whole thing for years now, and am fed up with it being still an a unusable state. I will use the Loxone miniserver to provide a user interface to control everything as it is faster than making a webinterface (less freedom, but it just works). My plan is:

1 control lights / temperature (done, temperature partly but enough)
2 control squeezebox (done)
3 get squeezebox info to loxone (done on eg side, not yet processed in loxone, using eventghost + xap)
4 control amplifier (concept works, using eventgost + webserver + marantz plugin; in progress)
5 get amplifier info bact to loxone (concept works, using eventghsot + python script + marantz plugin; in progress)
6 control mediacenter (still deciding: mediaportal/kodi, will be using eventghost + webserver)
7 get mediacenter info back to loxone (will be using eventghost + plugin for mediacenter + python script)

So still quite a list of things to do. However, once I have to full functionality for the squeezeboxes, I know the rest will be quite similar. I also had the plan of using the Squeezeboxes as ir receivers, but I have not many remotes that are compatible for that functionality. So most likely I will use my phone and possibly get a dirt-cheap tablet to use as a remote control for everything; a tablet as cheap as 20 euro suffices for that.
User avatar
kgschlosser
Site Admin
Posts: 5190
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: http post to loxone miniserver

Post by kgschlosser »

post the plugin and let me have a look at it so i can go through it and see what we might be able to do about it
If you like the work I have been doing then feel free to Image
User avatar
kgschlosser
Site Admin
Posts: 5190
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: http post to loxone miniserver

Post by kgschlosser »

no need to use the serial plugin, and you want to have it run in it's own thread anyways that way you can send commands to it while receiving them without any kind of processing delay and without other things happening in EG to pause what's happening with the amp
If you like the work I have been doing then feel free to Image
User avatar
kgschlosser
Site Admin
Posts: 5190
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: http post to loxone miniserver

Post by kgschlosser »

and deep six the kodi thing. too many problems with it and it has no native support for TV and won't ever have it unless the whole things gets re written.

i would just use mediaportal straight up, separate the client and server and install the server onto a machine with the speed and storage and ram for it with a raid array (get a good controller for this because otherwise it will take an eon if you have to rebuild)

and then get an HDHomeRun (like 60 bucks) for your cable TV and then you have the ability to install the client side on any windows based computer on your network and even off if you get a right proper VPN router like the linksys LRT224 (actually made by cisco), i put my cable modem into gateway mode shut off the built in wifi and put a separate router and a separate Access point and it runs so much better, i think i rebooted my router maybe 2 times in a year

if you really want to modify mediaportal you are going to have to get familiar with mysql. and i can't remember what the other database they use is but i know that they make a plugin for firefox to manage it and edit it

and the rest is mostly xml
plugins to get for mediaportal

AtmoLight (if you have the ambilight)
FanArt Handler
EventGhost Plus
Extensions
IMDB+
Logo Manager
Moving Pictures
MPSync (great for running a single source of data)
MP-TV Series
My Emulators 2 (if you do the video game thing)
Online Videos
Subtitle Downloader
Titanius
Titan Extended
Trailers
Trakt

Schedule Direct on the server side for the guide i think it's like maybe 10-20 beans a year
If you like the work I have been doing then feel free to Image
V_J
Experienced User
Posts: 165
Joined: Tue Mar 04, 2014 9:00 am

Re: http post to loxone miniserver

Post by V_J »

kgschlosser wrote:post the plugin and let me have a look at it so i can go through it and see what we might be able to do about it
Thanks for the offer!
I first want to focus on the other things, to finish them. Having the receiver send its changes when a button is pressed is cool, but not necessary as almost no changes will be made on the receiver. I'd rather have first that everything works nice together. Later, changing from one plugin to another is always possible. A change of work situation may put me abroad for a few years, so I'd rather finish it fast. :)
kgschlosser wrote:and deep six the kodi thing. too many problems with it and it has no native support for TV and won't ever have it unless the whole things gets re written.
i would just use mediaportal straight up, separate the client and server and install the server onto a machine with the speed and storage and ram for it with a raid array (get a good controller for this because otherwise it will take an eon if you have to rebuild)
(I had to google "deep six" :-))
The thing is: every now and then I try kodi, and I always come back disappointed. I'm currently using NextPVR for recording stuff from TV (DVB-T, DVB-S in planning), and MediaPlayerClassic HC for playing back recordings and videos. I just would like something that looks nicer than that combination.

I liked MediaBrowser when it still was a plugin into Windows Media Center and have used MediaPortal in the past. Now I feel like trying MediaPortal again, but I'm doubting between MediaPortal 1 and MediaPortal 2 (I tried MediaPortal 2 about a year ago, but had some issues... now there is a new version). Hardware-wise, I'm fully equipped, but just so little time for it all. This weekend I plan to disconnect and reconnect amplifier and computer, to hide cables nicely (following some renovations). After that I should have a bit of time to play with software again.
Post Reply