Page 28 of 37

Re: terRemote - Android remote app for EventGhost

Posted: Wed Dec 25, 2013 11:06 am
by terRemote
@thealbiglou: This is a nice idea. I will try that. This might then even come as a feature in terRemote or at least I'll write a tutorial on the homepage how to do it.

@mpg732: I am currently writing some tutorials on these things. I also did one for displaying text, thanks to your question. You can find it under http://www.terremote.com/tutorials/disp ... iable_text. Let me know if there are still any issues.

Chris

Re: terRemote - Android remote app for EventGhost

Posted: Wed Dec 25, 2013 7:22 pm
by mpg732
Thanks, got it to work.

Any one good with Python scripts. I want to send out this out n a Python Script to my direcTV box and have the return data inserted into a variable so I can send it up to terRemote. I want to do this all in EG Python script if possible.

import urllib
urllib.urlopen('http://192.168.0.116:8080/tv/getTuned')

I need some thing here so I can finish with the sample below... "I just don't know how to deal with returned data from the DirecTV box."

eg.plugins.NetworkSender2.plugin.Send("Dir.Channel", ["Variable"])




The IP command will return some thing like this when done in a web brouser.

{
"callsign": "FXHD",
"date": "2008",
"duration": 7200,
"isOffAir": false,
"isPclocked": 3,
"isPpv": false,
"isRecording": false,
"isVod": false,
"major": 248,
"minor": 65535,
"offset": 2105,
"programId": "7495528",
"rating": "TV-G",
"startTime": 1387994400,
"stationId": 3900906,
"status": {
"code": 200,
"commandResult": 0,
"msg": "OK.",
"query": "/tv/getTuned"
},
"title": "Madagascar: Escape 2 Africa"
}
I think once I figure out how to deal with the returned data, I should be able to just grab the parts I need and break them out into different Variables.

Re: terRemote - Android remote app for EventGhost

Posted: Wed Dec 25, 2013 7:55 pm
by terRemote
try something like

Code: Select all

import json
data = json.decode(eg.result)
duration = data["duration"]

Re: terRemote - Android remote app for EventGhost

Posted: Wed Dec 25, 2013 8:37 pm
by mpg732
So is this what you were thinking of?

import urllib
import json
urllib.urlopen('http://192.168.0.116:8080/tv/getTuned')

data = json.decode(eg.result)
duration = data["duration"]


eg.plugins.NetworkSender2.plugin.Send("Dir.Channel", [duration])


If so when I run the script I get errors

Traceback (most recent call last):
Python script "231", line 5, in <module>
data = json.decode(eg.result)
AttributeError: 'module' object has no attribute 'decode'

Re: terRemote - Android remote app for EventGhost

Posted: Wed Dec 25, 2013 11:16 pm
by terRemote
sry, wrong function. Try

Code: Select all

data = json.loads(eg.result)
You find the documentation here:
http://docs.python.org/2/library/json.html

Re: terRemote - Android remote app for EventGhost

Posted: Thu Dec 26, 2013 1:22 am
by mpg732
Still not working.

import urllib
import json
urllib.urlopen('http://192.168.0.116:8080/tv/getTuned')

data = json.loads(eg.result)
duration = data["duration"]


eg.plugins.NetworkSender2.plugin.Send("Dir.Channel", [duration])

I get a bunch of errors,

Traceback (most recent call last):
Python script "245", line 5, in <module>
data = json.loads(eg.result)
File "json\__init__.pyc", line 307, in loads
File "json\decoder.pyc", line 319, in decode
TypeError: expected string or buffer

Re: terRemote - Android remote app for EventGhost

Posted: Thu Dec 26, 2013 1:37 am
by Javier
Do you use Tasker?
If you do it may be easier to set up a Tasker Task using the "Http Get" Action and then the "variable split" Action (which will splitup the recieved data) then the terRemote Plugin to send the data (variables) you want to terRemote.
I will be happy to help you with any Tasker question.

Javier

Re: terRemote - Android remote app for EventGhost

Posted: Thu Dec 26, 2013 1:45 am
by mpg732
The only problem that I can see with using tasker would be the time conversions. Never used Tasker so can you write java or json or php scripts in Tasker? Plus I have multiple hand sets, do I have to run Tasker on each, or just one and have it send the data to both?

Re: terRemote - Android remote app for EventGhost

Posted: Thu Dec 26, 2013 2:02 am
by Javier
You can write Java (and python using SL4a). However I have never written anything in java and I am only a copy and paste python programer. I do use python in eventghost but no longer use it in tasker as there are plugins for eveything I used to connect with using python through SL4A. As for multiple device this may be an issue as each device would have to update independently, but you can export your tasker profile just as you export your terremot profile so you would not have to do anything twice. I use multiple devices and I do not have a problem as I can only use one device at a time and I do not have my PC as a middleman between my phone and the device from which I am requesting the data. I use tasker to update terremote seekbars for home lighting and webviews containing temperature from my home thermostate and it works very quickly, but if you are a programer you may be able to knock of a few miliseconds. Anyway, if you decide to go the tasker route I will always be willing to share my setups or help.

Javier

Re: terRemote - Android remote app for EventGhost

Posted: Thu Dec 26, 2013 8:39 am
by terRemote
In my code I assumed that the returned string was in eg.result. I think in your case this translates to

Code: Select all

import urllib
import json
f = urllib.urlopen('http://192.168.0.116:8080/tv/getTuned')
result = f.read()

data = json.loads(result)
duration = data["duration"]

eg.plugins.NetworkSender2.plugin.Send("Dir.Channel", [duration])
Does this work?

Re: terRemote - Android remote app for EventGhost

Posted: Fri Dec 27, 2013 4:32 pm
by mpg732
Getting closer, now all I get an "NetworkSender failed" error. Does not like

eg.plugins.NetworkSender2.plugin.Send("Dir.Channel", [duration])

I wonder if I have to convert the incoming data into an integer?

PS.

I have NetworkSender2 working already working with other comands

Re: terRemote - Android remote app for EventGhost

Posted: Fri Dec 27, 2013 4:38 pm
by terRemote
Ah, yes, duration is an integer variable.
Try

Code: Select all

eg.plugins.NetworkSender2.plugin.Send("Dir.Channel", [unicode(duration)])
to ensure that it is converted into a unicode string.

Re: terRemote - Android remote app for EventGhost

Posted: Fri Dec 27, 2013 5:10 pm
by mpg732
DING DING DING, that was it, thanks so much. Now all I need to work out is the time conversion and progress slider.

Re: terRemote - Android remote app for EventGhost

Posted: Sat Dec 28, 2013 1:00 am
by mpg732
What do you guys recommend, I want to run that script every 5 to 10 seconds. What do you think is the best way to do that, with out tieing up EG or terRemote. Would Tasker be a good way to do that?

Or I am thinking of doing a loop in the Python script and then Enabling and Disabling the macro/event when I enter and leave my DirecTV pages in terRemote.

Re: terRemote - Android remote app for EventGhost

Posted: Sat Dec 28, 2013 4:09 pm
by Javier
I'm sorry I did not understand what you were trying to do in your original post, but I think I understand now.

There may be a few ways to do this in tasker however there are a few limitations I can see (Please correct me if I am wrong) and data results that may require additonal work arounds.

In terRemote you can not update the max/min values of seekbars so everything would have to be in a percentage of total-time/time-elapsed. Second terRemote does not show events in the log when (1)the screen turns off with app running, (2) the screen turns on and app is running, (3)you leave the app, or (4)you re-enter the app without automaticly changing the current layout by going to the default home layout, So some of the tasks may continue to run until they are stopped by the feedback from the direct TV values, you change layouts, or they hit a maximum value defined to stop a loop.

The specs of the android device used may affect the results.

I do not have a Direct TV box to test so there may be things that I can not forsee which will require a little more work depending on returned values . An example would be (1) what is the "Offset" (time elapsed in seconds) value when the program starts, finishes, or there is no value. I have also encountered devices in the past which would start to lag if there where too many looping requests.

In tasker you can use loops in tasks which will end when the value of a variable hits a defined value/variable e.g. task continues to run as long as the variable is < 100(%) (I believe you can also do this in python so maybe someone else can give you information on how to do this in the script you already have). Then you can have tasks to stop the looping task for any other reason.
I just tested a looping Tasker task which was linked to a terRemote seekbar. The seek bar had values 0 thru 100. The Tasker task had the following actions (1) wait one second (2) add 1 to the current value of the variable (3) Send terremote event which sends the value of the variable as a payload (4) Goto action "(1)" if the value of the variable is less than 100. In terRemote a Macro which updated the seekbar with the payload sent from tasker and a Macro to start the task when the layout was opened..There was also another task to restart the loop if the seekbar was updated manually...Everything worked fine and still alowed me to run other tasker tasks and terremote actions while the seekbar was moving every second.

So I believe you should be able to do this by either updating the variable from the Direct TV continually in a tasker loop or updating the variable periodicly and having tasker update the variable/seekbar by counting/waiting.