Extension: URL Toggle Device

User avatar
Colorado4Wheeler
Posts: 2794
Joined: Mon Jul 20, 2009 10:48 am
Location: Colorado

Extension: URL Toggle Device

Post by Colorado4Wheeler »

Because I have no life (and my wife is out of town and I have nothing better to do without her) I just added a new extension to Device Extensions called a URL Toggle Device. This basically allows you to create an On/Off/Toggle device that simply executes a URL for you on each command.

It just so happened that last night I was checking my cameras and noticed that the I/R was on for one of my cameras and it was close enough to glass to make seeing the image impossible, so I decided I would write something to easily take care of that for me but generic enough I could use it on a number of my web-enabled devices around the house.

Screenshot & Details
New URL Toggle Device
New URL Toggle Device
Screen Shot 2016-06-10 at 5.57.27 PM.png (63.74 KiB) Viewed 6778 times
  • Turn on URL: The URL to execute when an On command is received
  • Turn off URL: The URL to execute when an Off command is received
  • Toggle URL: The URL to execute when a Toggle command is received. If this is left blank then the plugin will internally just execute whatever command is the opposite of the current device state (i.e., if it is currently in an On state it will send an Off command). Because these commands are sent in the blind with no feedback from the receiver, a toggle command might perform the opposite action than what you expect - if this happens there is an action to force it to an off state (without sending an Off command) so you can reset it
Full documentation, release notes and the download link can be found on the main Device Extensions topic

IndigoPluginDownload.png
IndigoPluginDownload.png (14.88 KiB) Viewed 6751 times
[/url]
My Modest Contributions to Indigo:

HomeKit Bridge | Device Extensions | Security Manager | LCD Creator | Room-O-Matic | Smart Dimmer | Scene Toggle | Powermiser | Homebridge Buddy

Check Them Out Here
User avatar
Different Computers
Posts: 2730
Joined: Sat Jan 02, 2016 10:07 am
Location: East Coast
Contact:

Re: New Extension: URL Toggle Device

Post by Different Computers »

oooh, baby, this is super useful when combined with the Maker channel of IFTTT! Saves the need to write a shell script to make something happen.
Sonoma on a Mac Mini M1 running Airfoil Pro, Bond Home, Camect, Roku Network Remote, Hue Lights, DomoPad, Adapters, Home Assistant Agent, HomeKitLinkSiri, EPS Smart Dimmer, Fantastic Weather, Nanoleaf, LED Simple Effects, Grafana, Yamaha RX Receiver.
User avatar
Colorado4Wheeler
Posts: 2794
Joined: Mon Jul 20, 2009 10:48 am
Location: Colorado

Re: New Extension: URL Toggle Device

Post by Colorado4Wheeler »

Sweet, glad you have a use for this thing that took me all of 5 minutes to add to Device Extensions :).

If people like this and want me to expand it I may port it out to a plugin of its own with more options. I'm already thinking of having some conditional statements for the data chunks returned from the call but that increases the time to develop exponentially. There are probably benefits to enabling other device actions like brightness, that could be tied to a number of other URLs for IFTTT or things like it.
My Modest Contributions to Indigo:

HomeKit Bridge | Device Extensions | Security Manager | LCD Creator | Room-O-Matic | Smart Dimmer | Scene Toggle | Powermiser | Homebridge Buddy

Check Them Out Here
User avatar
jay (support)
Site Admin
Posts: 19232
Joined: Wed Mar 19, 2008 11:52 am
Location: Austin, Texas
Contact:

Re: New Extension: URL Toggle Device

Post by jay (support) »

Different Computers wrote:Saves the need to write a shell script to make something happen.
Not that this device addition isn't useful (it is), but you don't need a shell script, just a simple 2 line Python script:

Code: Select all

import urllib
urllib.urlopen("http://host.com/path/to/whatever")
This is one of the major reasons we use Python as our primary scripting language (as opposed to AppleScript).
Jay (Indigo Support)
Twitter | Facebook | LinkedIn
User avatar
Different Computers
Posts: 2730
Joined: Sat Jan 02, 2016 10:07 am
Location: East Coast
Contact:

Re: New Extension: URL Toggle Device

Post by Different Computers »

Everything is simple once you know how to do it. :wink:

Thanks for the tip though.
Sonoma on a Mac Mini M1 running Airfoil Pro, Bond Home, Camect, Roku Network Remote, Hue Lights, DomoPad, Adapters, Home Assistant Agent, HomeKitLinkSiri, EPS Smart Dimmer, Fantastic Weather, Nanoleaf, LED Simple Effects, Grafana, Yamaha RX Receiver.
User avatar
Colorado4Wheeler
Posts: 2794
Joined: Mon Jul 20, 2009 10:48 am
Location: Colorado

Re: New Extension: URL Toggle Device

Post by Colorado4Wheeler »

And those are the exact two lines of code I use as well, the point of the program is to have it act as a toggle device for whatever your needs might be ;)
My Modest Contributions to Indigo:

HomeKit Bridge | Device Extensions | Security Manager | LCD Creator | Room-O-Matic | Smart Dimmer | Scene Toggle | Powermiser | Homebridge Buddy

Check Them Out Here
User avatar
jay (support)
Site Admin
Posts: 19232
Joined: Wed Mar 19, 2008 11:52 am
Location: Austin, Texas
Contact:

Re: New Extension: URL Toggle Device

Post by jay (support) »

Colorado4Wheeler wrote:And those are the exact two lines of code I use as well, the point of the program is to have it act as a toggle device for whatever your needs might be ;)
Exactly, which is why I said it was useful. Just couldn't resist the teachable moment... :)
Jay (Indigo Support)
Twitter | Facebook | LinkedIn
User avatar
Different Computers
Posts: 2730
Joined: Sat Jan 02, 2016 10:07 am
Location: East Coast
Contact:

Re: New Extension: URL Toggle Device

Post by Different Computers »

I do appreciate teachable moments.

I'm not entirely following on the toggle intent, but I thought I'd report after a lot of head scratching issues yesterday, today everything is working perfectly with sending URLs to the Maker channel that then make my ST hub turn on and off my zigbee lights. So I'm going to point at the eternal flakiness of the ST hub as the reason why it didn't work right immediately.

While the python code is great, and I may be able to use it going forward in future stuff, the ability to have my non-Hue zigbee lights appear as devices in Indigo is really great.

Now if there was just some way short of spinning up another Apache server to get the IFTTT Maker channel to talk straight to Indigo! That would let my remaining zigbee door sensors become useful. Also, I could use the generally reliable ST presence sensing for my wife and I.
Sonoma on a Mac Mini M1 running Airfoil Pro, Bond Home, Camect, Roku Network Remote, Hue Lights, DomoPad, Adapters, Home Assistant Agent, HomeKitLinkSiri, EPS Smart Dimmer, Fantastic Weather, Nanoleaf, LED Simple Effects, Grafana, Yamaha RX Receiver.
User avatar
Colorado4Wheeler
Posts: 2794
Joined: Mon Jul 20, 2009 10:48 am
Location: Colorado

Re: New Extension: URL Toggle Device

Post by Colorado4Wheeler »

Different Computers wrote:I'm not entirely following on the toggle intent
So you don't have to "turn on" or "turn off" only. For me my IR command button on my control pages is a single button, if I want to toggle IR on and off then I can use that. For schedules I have it set to "turn on" at dark and "turn off" at light. It just gives the same functionality to THIS device as other Indigo devices have.
My Modest Contributions to Indigo:

HomeKit Bridge | Device Extensions | Security Manager | LCD Creator | Room-O-Matic | Smart Dimmer | Scene Toggle | Powermiser | Homebridge Buddy

Check Them Out Here
User avatar
Different Computers
Posts: 2730
Joined: Sat Jan 02, 2016 10:07 am
Location: East Coast
Contact:

Re: New Extension: URL Toggle Device

Post by Different Computers »

Gotcha! I can see the need for that. It was my initial use of this to send a necessarily specific on OR off to Maker that had me not following.
Sonoma on a Mac Mini M1 running Airfoil Pro, Bond Home, Camect, Roku Network Remote, Hue Lights, DomoPad, Adapters, Home Assistant Agent, HomeKitLinkSiri, EPS Smart Dimmer, Fantastic Weather, Nanoleaf, LED Simple Effects, Grafana, Yamaha RX Receiver.
User avatar
Colorado4Wheeler
Posts: 2794
Joined: Mon Jul 20, 2009 10:48 am
Location: Colorado

Re: New Extension: URL Toggle Device

Post by Colorado4Wheeler »

Sometimes I get too bogged down in geek-speak and probably don't convey the meaning clearly, that's why my documentation on plugins tends to be so verbose :).
My Modest Contributions to Indigo:

HomeKit Bridge | Device Extensions | Security Manager | LCD Creator | Room-O-Matic | Smart Dimmer | Scene Toggle | Powermiser | Homebridge Buddy

Check Them Out Here
neilk
Posts: 729
Joined: Mon Jul 13, 2015 1:51 pm
Location: Reading, UK

Re: New Extension: URL Toggle Device

Post by neilk »

Hi,
Tried adding an URL extension today with the following URL (currently run in an external script)

https://192.168.1.20/cgi-bin/CGIProxy.f ... pwd=mypass

But get the following in the log file

EPS - Device Extensions Error Error in plugin execution ExecuteAction:

Traceback (most recent call last):
File "plugin.py", line 502, in actionControlDimmerRelay
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/urllib2.py", line 126, in urlopen
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/urllib2.py", line 391, in open
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/urllib2.py", line 409, in _open
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/urllib2.py", line 369, in _call_chain
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/urllib2.py", line 1189, in https_open
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/urllib2.py", line 1156, in do_open
URLError: <urlopen error [Errno 8] _ssl.c:493: EOF occurred in violation of protocol>

It is a foscam R2 Pan and tile camera

I found some old references to the same issue with older python versions, but https is a bit of a dark art for me.

Thanks,
Neil
User avatar
Colorado4Wheeler
Posts: 2794
Joined: Mon Jul 20, 2009 10:48 am
Location: Colorado

Re: New Extension: URL Toggle Device

Post by Colorado4Wheeler »

Are you able to access the camera via your browser without using SSL?
My Modest Contributions to Indigo:

HomeKit Bridge | Device Extensions | Security Manager | LCD Creator | Room-O-Matic | Smart Dimmer | Scene Toggle | Powermiser | Homebridge Buddy

Check Them Out Here
neilk
Posts: 729
Joined: Mon Jul 13, 2015 1:51 pm
Location: Reading, UK

Re: New Extension: URL Toggle Device

Post by neilk »

The documentation on the camera is more than a little sparse, no obvious settings on the camera to allow it. It is not really a big deal as it I have it working with external scripts and curl but I thought your device approach was much more elegant. I am also playing with the other extensions so many thanks for this.

I will keep digging, but good to know if anyone else has a similar issue.

Neil
PeteVis
Posts: 180
Joined: Fri Jun 19, 2015 3:28 am

Re: New Extension: URL Toggle Device

Post by PeteVis »

This would be a super useful plugin if you could make it a little more flexible...

i.e. I have a dLink camera that I can set IR commands, but the dlink requires authentication that is not passed via the url, so I need to use this script to make it work :

Code: Select all

import urllib2, base64

request = urllib2.Request("http://10.0.1.50/eng/admin/adv_audiovideo.cgi")

base64string = base64.encodestring('%s:%s' % ('username', 'password')).replace('\n', '')
request.add_header("Authorization", "Basic %s" % base64string)   
result = urllib2.urlopen(request,'irMode=3')
Post Reply

Return to “Device Extensions Plugin”