Jump to content

Tasker talking to ISY via REST


MWareman

Recommended Posts

I have started a Wiki page on the subject. Feel free to make suggestions here and we can develop this further!

 

http://wiki.universal-devices.com/index.php?title=ISY-99i_Series_INSTEON:Networking:Tasker

 

Having ISY send device state back to Tasker is here: http://wiki.universal-devices.com/index.php?title=ISY-99i_Series_INSTEON:Networking:Mobile_Notification:Tasker (I plan on making this *much* better when we can include variables and device state in network resources as substitutions in  version 5)

 

By combining both together - you can create 'toggle' tasks (turn a device on if off, off if on etc) - or do 'Up' and 'Down' tasks for a Fanlinc. I have not written that up yet.

Link to comment

I do toggle tasks with tasker widgets, if that is what you seek. First, i create program (disabled) such as:

 

If

This program is false

Then

Turn light on

Else

Turn light off

 

I then create a tasker widget, through the mobilinc plug-in, that executes the program if path.

Link to comment

I do toggle tasks with tasker widgets, if that is what you seek. First, i create program (disabled) such as:

 

If

This program is false

Then

Turn light on

Else

Turn light off

 

I then create a tasker widget, through the mobilinc plug-in, that executes the program if path.

That's much simpler than what I've been doing for some scenarios!  However, if a device is 'On' and then turned 'Off' from a dimmer (or anywhere outside of the program) - how would the program state react?  I suspect the next toggle would do nothing - which I'm trying to avoid. Also - have you not had the issue of program IDs getting messed up in Mobilice on an ISY sync - causing you to have to re-setup your Tasker/Mobilinc tasks?

 

Instead - I have a program (triggered by a device turning on (then) or off (else) to send a '1' or '0' to Tasker (or '0', '1', '2' and '3' for fan states 'Off' 'Low' 'Medium' or 'high') (see http://wiki.universal-devices.com/index.php?title=ISY-99i_Series_INSTEON:Networking:Mobile_Notification:Tasker) and then implement my 'Up 'Down' and 'Toggle' processes as Tasker Tasks.

 

I wonder if (again - disabled):

 

If

  LightA is not On

Then

  Turn LightA On

Else

  Turn LightA Off

 

..would work? Tracking state directly from the device. Tasker would run the If - and the device toggles (whatever it's starting state)?

 

How would you do an 'up' 'down' program for a FanLinc?

 

Would this work?  (All disabled)

 

Program FanUP

If

  Fanlinc is Off

Then

  Turn FanLinc Low

Else

  Run Program FanUP2

 

Program FanUP2

If

  Fanlinc is Low

Then

  Turn FanLinc Medium

Else

  Run Program FanUP3

 

Program FanUP3

If

  Fanlinc is Medium

Then

  Turn FanLinc High

 

..and then repeat for the down series...  Running 'If' on FanUP would increment to the next speed up...  I think that would work - thoughts?

Link to comment

This should be good.  I have played around with tasker and isy a bit, but pretty much have just achieved proof of concept.  The wiki should help get things rolling.

I agree. The more I get into it - the more I like it.  I now have a 'scene' on Tasker with buttons that show the current lighting states - pushing one causes the associated light to change state. I have fan 'Up' and 'Down' buttons - and the whole thing is one tough accessible from the notification pull-down on my phone. Pretty sweet.

 

Right now - I'm about to start figuring out how to retrieve state from ISY into a variable - so I can poll on start instead of relying only on the push.

Link to comment

That's much simpler than what I've been doing for some scenarios!  However, if a device is 'On' and then turned 'Off' from a dimmer (or anywhere outside of the program) - how would the program state react?  I suspect the next toggle would do nothing - which I'm trying to avoid. Also - have you not had the issue of program IDs getting messed up in Mobilice on an ISY sync - causing you to have to re-setup your Tasker/Mobilinc tasks?

 

Instead - I have a program (triggered by a device turning on (then) or off (else) to send a '1' or '0' to Tasker (or '0', '1', '2' and '3' for fan states 'Off' 'Low' 'Medium' or 'high') (see http://wiki.universal-devices.com/index.php?title=ISY-99i_Series_INSTEON:Networking:Mobile_Notification:Tasker) and then implement my 'Up 'Down' and 'Toggle' processes as Tasker Tasks.

 

I wonder if (again - disabled):

 

If

  LightA is not On

Then

  Turn LightA On

Else

  Turn LightA Off

 

..would work? Tracking state directly from the device. Tasker would run the If - and the device toggles (whatever it's starting state)?

 

How would you do an 'up' 'down' program for a FanLinc?

 

Would this work?  (All disabled)

 

Program FanUP

If

  Fanlinc is Off

Then

  Turn FanLinc Low

Else

  Run Program FanUP2

 

Program FanUP2

If

  Fanlinc is Low

Then

  Turn FanLinc Medium

Else

  Run Program FanUP3

 

Program FanUP3

If

  Fanlinc is Medium

Then

  Turn FanLinc High

 

..and then repeat for the down series...  Running 'If' on FanUP would increment to the next speed up...  I think that would work - thoughts?

The program I posted i disabled to avoid having it otherwise react to changes in status. The only way it can activate is if called by mobilinc. I hav never noticed any problems with mobilinc sync operations.

 

Your proposed approach to the fan problem is near exactly how I would approach it. Like the first, I would expect these would need disabled.

Link to comment

Mwareman,

 

Thinking a little further about my approach and your comments, I believe you are correct about one problem with my approach. Unfortunately, I use these toggle widgets sparingly, and in situations where they are the only mechanism that can control the scene.

 

To avoid hav7ng the toggle widget get out of sync, I might choose instead to pick one de ice in a scene as an indicator for the scene state. Then I would use the indicator device as a condition in a program.

 

If

Status Indicator device is off

then

Turn scene on

Else

turn scene off

Link to comment

This is excellent!

 

but...

this would be much better in the Tasker Forum thread created for easier finding.

 

http://forum.universal-devices.com/forum/100-tasker/

This brings up a 404 for me.  

 

I've added device toggles to the wiki page (http://wiki.universal-devices.com/index.php?title=ISY-99i_Series_INSTEON:Networking:Tasker) using the method detailed here by @oberkc. The load device is used for status then the 'Then' or 'Else' turns the scene on or off. Program is disabled and then run using the 'RunIf' task. Location awareness takes care of ensuring Tasker uses the best available URL (HTTP on the same network - HTTPS when roaming). No MobiLinc required. (I have it - I've just been getting increasingly frustrated with it's extreme sluggishness on my Android devices)

Link to comment

Because of my problems revealed when I upgraded to android 5.0 (thread created in the mobilinc forum), I have suddenly become keenly aware of sluggishness when connected via https connections. In my case, I dont use my phone much around the house, and use other tablets connected solely via local http connection, which is quite fast.

 

With the phone (both cellular and wifi data) and mobilinc, I have yet to Establish a good understanding of how mobilinc transitions from cellular (https) data and wifi (http) data, but I can say that tablets are alway on http connections, and they are fast. Cell phones, when on https connection, have a response lag that can be near 30 seconds in my case. I also believe that if I am home, the phone on wifi, and I continue to see those delays,that mobilinc has not made the transition to http non-secure connection.

 

My point...if you are seeing delays when on wifi, consider the possibility that you are still on https secure connection and have not transitioned to http as your settings suggest should have happened.

Link to comment

Because of my problems revealed when I upgraded to android 5.0 (thread created in the mobilinc forum), I have suddenly become keenly aware of sluggishness when connected via https connections. In my case, I dont use my phone much around the house, and use other tablets connected solely via local http connection, which is quite fast.

 

With the phone (both cellular and wifi data) and mobilinc, I have yet to Establish a good understanding of how mobilinc transitions from cellular (https) data and wifi (http) data, but I can say that tablets are alway on http connections, and they are fast. Cell phones, when on https connection, have a response lag that can be near 30 seconds in my case. I also believe that if I am home, the phone on wifi, and I continue to see those delays,that mobilinc has not made the transition to http non-secure connection.

 

My point...if you are seeing delays when on wifi, consider the possibility that you are still on https secure connection and have not transitioned to http as your settings suggest should have happened.

I've confirmed that Mobilinc connects with HTTP on the local wifi (wireshark) - the sluggishness is due to the initial refresh that occurs when the app is started up. With Tasker - I'm working towards a zero latency solution. Even the initial SSL connection to ISY when roaming is orders of magnitude faster than what Mobilinc seems to be able to achieve. I don't really understand why yet. 

 

In my day job - I work with F5 units - and high end networking troubleshooting. This is why I'm able to dig into crypto, certificate and networking issues fairly readily and understand what's going on. Encrypted connections take an extended time to establish. The single biggest factor that helps is the math processing speed of the server you are connecting to. ISY does this math on it's main CPU - and given the complexity of > 1024 bit crypto math I'm amazed that connections times are as short as they are! Hopefully, UDI sees fit to include a chip like this (http://www.freescale.com/webapp/sps/site/taxonomy.jsp?code=C29X_FAMILY&cof=0&am=0) in the next hardware refresh of ISY to make strong TLS practical - even as an option that can be installed if a user desires. 

 

Me - for REST access to my ISY - I use one of these boards in my proxy server (http://soekris.com/products/vpn-1401.html) - and it works as an SSL offloader. Apache MOD_SSL seems to use it well. I have almost instantaneous connections using Tasker with SSL - but still high latency using Mobilinc due to it's initial refresh.

Link to comment

That is quite interesting. Most of the time, with my dedicated tablets that never leave the house, I dont percieve any latency beyond about a second. Perhaps mobilinc on these units dont go through an "initial refresh"?

 

Keep us informed what you come up with. What I would like, but have not yet figured out, is a widget that changes (dark and light, perhaps), depending on state of an insteon device or scene. In other words, I would like a widget that simulates a keypadlinc.

Link to comment
  • 6 months later...

I'm currently using the 'slow' method of driving MobiLinc from Tasker but I stumbled upon your tutorial and have been playing around with direct control.

 

However, I'm having an issue with (I think) the HTTP GET command.  When I fire off a task to turn a scene on, I get an error message:

 

"Input/Output error for http://xx.xx.xx.xx/rest/nodes/xxxx/cmd/DON:java.io.FileNotFoundException: http://xx.xx.xx.xx/rest/nodes/xxxx/cmd/DON "

 

If I type the same address into my browser, it works fine.  In googling around I thought I found something about a possible GET bug in Tasker, but can't find the information again.

 

Is there a setting I'm possibly overlooking somewhere?

 

Thanks!

Link to comment

In the wiki, I had documented  /rest/nodes/xxxx/DON for scene control, but I discovered this was in error (according to the REST interface doc - http://wiki.universal-devices.com/index.php?title=ISY_Developers:API:REST_Interface). I have fixed the page to include /cmd. Your post caused me to double check that...  Thanks!

 

As to your issue:

 

http://xxx.xxx.xxx.xxx may be working from your browser because you have already authenticated.

 

With tasker, you need http://user:password@xxx.xxx.xxx.xxx (where user and password are your ISY user and password).  Also - I assume the xxxx is the scene ID you are trying to control (usually either 4 or 5 numeric digits). 

 

Michael.

Link to comment

In the wiki, I had documented  /rest/nodes/xxxx/DON for scene control, but I discovered this was in error (according to the REST interface doc - http://wiki.universal-devices.com/index.php?title=ISY_Developers:API:REST_Interface). I have fixed the page to include /cmd. Your post caused me to double check that...  Thanks!

 

As to your issue:

 

http://xxx.xxx.xxx.xxx may be working from your browser because you have already authenticated.

 

With tasker, you need http://user:password@xxx.xxx.xxx.xxx (where user and password are your ISY user and password).  Also - I assume the xxxx is the scene ID you are trying to control (usually either 4 or 5 numeric digits). 

 

Michael.

 

Ah, apologies.. I am already including user:password in Tasker, I should have stated that.

 

Yes, scene ID is the number listed in the admin console for that particular scene.  I guess there's really no reason for me to not display it..

Link to comment

Odd - if the URL works in a browser it should in Tasker - especially if you are using http (as opposed to https). I have it running just fine on several Android devices that I use daily.

 

Can I confirm that in the Tasker HTTP Get action you have:

 

Server:Port    http://xxx.xxx.xxx.xxx

Path             /rest/nodes/xxxxx/cmd/DON

 

You need to split up the server:port from the path. Wanted to be sure you had done that.

 

If you are using SSL - you may want to consider checking 'Trust any Certificate' (be aware that if you access via a malicious method of access a fake certificate will be trusted) as a diagnostic step. If this allows SSL to work then the issue is you don't have a trusted (to Tasker) SSL cert on your ISY.

 

Finally - you can use the 'Run Log' in Tasker to better identify where the issue is. IF you are using variables to form the URL make sure that they are correctly set this way.

 

Michael.

Link to comment
  • 2 weeks later...

I'm having a problem with connecting to the ISY via REST as well.  I'm running Tasker with as exit task when I disconnect from my home wifi connection.  In this exit task is an HTTP GET.  Every time it runs automatically it seems to give me an error, unknown host.  What exactly does that mean?  When I run it manually afterwards it runs fine.  When I run it while I'm on my network it runs fine (using local IP address rather than dyndns.org address) Below is a portion of the TASKER log file showing unknown host error.  I've tried to have it run a second time in the exit task but it gives me an error again.  It runs the second time after a 30 second wait when the first response (%HTTPR) is not = 200 (e.g. is equal to -1).  The first run is after a 30 wait as well.  This is because I figured maybe the error was because it was running too soon after disconnecting from my home network.  I thought the 30 second wait would give enough time to properly connect to the cellular network.

 

I have a very similar exit task on my wife's phone and it seems to run ok each time.

 
Here's a short hand of the exit task:
wifi off
change a variable
wait 30 seconds
change another variable
clear a variable
Run HTTP GET
set variable %RESP to response from HTTP GET (%HTTPR)
wait 30 seconds if %RESP = -1
Run HTTP GET again if %RESP = -1
run some other non-related stuff, change more variables turn on bluetooth, etc.
 
Here's a portion of the run log (I've removed sensitive information below such as dyndns, port, username and password):
 
24-06-2015 E: 06.04.21#E: execute task: Insteon Away2
24-06-2015 E: 06.04.21#E: exe: Insteon Away2 / HTTP Get [ Server:Port:http://username:password@xxxxx.dyndns.org:port Path:/rest/programs/0023/run Attributes: Cookies: User Agent: Timeout:20 Mime Type: Output File: Trust Any Certificate:Off Continue Task After Error:On ]
24-06-2015 E: 06.04.21#E: prot: http:// serverport: xxxxx.dyndns.org:port contenttype: 
24-06-2015 E: 06.04.21#E: method: GET url: http://xxxxx.dyndns.org:port/rest/programs/0023/run timout: 20000 dataisfile false save null
24-06-2015 WakeLockManager: 06.04.21#WakeLockManager: setClearAlarm: not setting, last set 223 ago
24-06-2015 WakeLockManager: 06.04.21#WakeLockManager: setClearAlarm: not setting, last set 236 ago
24-06-2015 E: 06.04.21#E: body isfile: false cont: null
24-06-2015 Variables: 06.04.21#Variables: doreplresult: |%LOCK| -> |%LOCK|
24-06-2015 Variables: 06.04.21#Variables: doreplresult: |%EMERG| -> |%EMERG|
24-06-2015 Variables: 06.04.21#Variables: doreplresult: |%APPLOCK| -> |Yes|
24-06-2015 State: 06.04.21#State: checkMatch: code 165: false -> true
24-06-2015 M: 06.04.21#M: sig context change: checkMatchStates: pid: 95 cType: 5
24-06-2015 M: 06.04.21#M: sig context change pid: 95 cType: 5 enabled: true active: true
24-06-2015 Variables: 06.04.21#Variables: doreplresult: |%ATWORK| -> |No|
24-06-2015 Variables: 06.04.21#Variables: doreplresult: |%VIBRATE| -> |Off|
24-06-2015 M: 06.04.21#M: checkMatchStates: have change set size 1
24-06-2015 M: 06.04.21#M: handleProfileChanges
24-06-2015 E: 06.04.21#E: Unknown Host in http://xxxxx.dyndns.org:port/rest/programs/0023/run.
24-06-2015 E: 06.04.21#E: result: stop task (error)
24-06-2015 E: 06.04.21#E: action doesn't want stop on error
24-06-2015 E: 06.04.21#E: result: ok (ignore wait)
24-06-2015 M: 06.04.21#M: handle monitor changes
24-06-2015 M: 06.04.21#M: update flags (handleMonitorChanges)
24-06-2015 M: 06.04.21#M: clear flags (updateFlags

 

 

this is on my HTC One M8 running Lollipop 5.0.1

Tasker version 4.7u1m

Link to comment

'Unknown host' means whatever you have for xxxxx.dyndns.org is not resolving in DNS on the network you are connected to after your WiFi disconnects. So - this could mean android has disconnected from wiFi (triggering the rule) but the phone has not re-established to the cell network. You could try adding a delay before the attempt to see if this is the reason.

 

You should also ensure that your xxxxx.dyndns.org name is actually resolving to your external IP address.

 

Michael.

Link to comment

'Unknown host' means whatever you have for xxxxx.dyndns.org is not resolving in DNS on the network you are connected to after your WiFi disconnects. So - this could mean android has disconnected from wiFi (triggering the rule) but the phone has not re-established to the cell network. You could try adding a delay before the attempt to see if this is the reason.

 

You should also ensure that your xxxxx.dyndns.org name is actually resolving to your external IP address.

 

Michael.

 

Hmm, I already have a 30 second delay before triggering the HTTP GET command.  Then if it fails (returns -1) I wait another 30 seconds and try again.

 

I tried it today and it still didn't work.  When I run the task manually afterwards it seems to work.  Maybe I need to wait even longer than the initial 30 seconds and then another 30 seconds?  Although that seems like a long time (1 minute) for the phone to establish the cellular connection properly, doesn't it?

Link to comment

It does - yes. I have no delay in mine and the task runs perfectly every time. I have a Nexus 5 on AT&T if that makes any difference.

 

I have almost the same exit task on my wifes phone and on hers it only has a 10 second delay and hers runs fine every time.  I wonder if there is something with my HTC One M8 that makes a difference.  I'll have to keep  trying different delays to see if that makes a difference.  Thanks for the help.

Link to comment
  • 9 months later...

I have started a Wiki page on the subject. Feel free to make suggestions here and we can develop this further!

 

 

Just wanted to thank you for taking the time to do this write-up.  I had been using more primitive means (curl) via tasker and while it got the job done, your routines here prove to tickle my inner OCD.  It's also helped me to refine my routines for using my smartwatch to control my home, and receive status of modules as well so that I'm not just "toggling" in the dark.

 

Thanks again,

 

-N

Link to comment

Archived

This topic is now archived and is closed to further replies.


×
×
  • Create New...