Amazon Dash Component? #484

Closed
avaidyam opened this Issue Oct 6, 2015 · 26 comments

Projects

None yet

8 participants

@avaidyam
avaidyam commented Oct 6, 2015

Using scapy and a quick ARP-hunting python script:

def arp_display(pkt):
  if pkt[ARP].op == 1: #who-has (request)
    if pkt[ARP].psrc == '0.0.0.0': # ARP Probe
      if pkt[ARP].hwsrc == 'xx:xx:xx:xx': # MAC Address here
        # BUTTON PRESSED --> EVENT
      else:
        print "ARP Probe from unknown device: " + pkt[ARP].hwsrc
print sniff(prn=arp_display, filter="arp", store=0)

it's possible to use an Amazon Dash button as a trigger. This would be super helpful, since now you have a cheap 5$ button that can toggle any lighting setup you want, for starters.

Is anyone already implementing such a feature?

@maddox
Collaborator
maddox commented Oct 6, 2015

since now you have a cheap 5$ button that can toggle any lighting setup you want

At least for 5-10 minutes.

The Dash button is exciting to me, but the fact that you can only use it ONCE over a period of time really takes the wind out of my sails. It's great if you want to use it as some sort of incrementer, but as a "switch" it sort of falls flat.

How long does it actually take to fall back asleep so that you can use it again?

@CCOSTAN
Contributor
CCOSTAN commented Oct 6, 2015

I have a dash and it looks like it takes a few seconds to jump on the wireless, send it's payload, and then drops right off. it all happens within a 12 second period since I can almost NEVER catch it with the NMAP scanning (which runs every 12 seconds).

I think the DASH buttons make EXCELLENT smart buttons for non time sensitive things like Good Morning, & Good Night scenes.

@maddox
Collaborator
maddox commented Oct 6, 2015

@CCOSTAN wow! I figured it took minutes at a time to time out.

Ok, used for the right thing, then it sounds like it'll totally work. Awesome.

@avaidyam
avaidyam commented Oct 6, 2015

Yup! Should be within 10 seconds, and if you resort to DNS hackery you can even redirect the address and run your own script. If you return 200 OK it'll blink to confirm. That takes more effort though, so it might be optional.

@balloob
Member
balloob commented Oct 6, 2015

Don't you need to run as root to listen for arp packets?

On Tue, Oct 6, 2015, 08:08 Aditya Vaidyam notifications@github.com wrote:

Yup! Should be within 10 seconds, and if you resort to DNS hackery you can
even redirect the address and run your own script. If you return 200 OK
it'll blink to confirm. That takes more effort though, so it might be
optional.

โ€”
Reply to this email directly or view it on GitHub
#484 (comment)
.

@CCOSTAN
Contributor
CCOSTAN commented Oct 6, 2015

If we can somehow think of a workable solution for the Dash buttons, I think that would be awesome. (Front Page Reddit stuff!) :) 5 dollar buttons just in time for Christmas lighting!

@maddox
Collaborator
maddox commented Oct 6, 2015

I think the only real solution would be to run a process next to HA that POSTs to it. Running HA as root isn't really a good idea or even acceptable, especially JUST for these buttons.

@avaidyam
avaidyam commented Oct 6, 2015

The root requirement arises from the use of raw sockets; if we can find a way around that, perhaps using BSD sockets as a layer, it might work. It needs to be evaluated for compatibility though.

To clarify, layer 2 (ethernet, wireless) and layer 3 (raw sockets) require root, while layer 4 (tcp/udp) doesn't. I'm not sure if ARP sniffing would work at layer 4 either.

@CCOSTAN
Contributor
CCOSTAN commented Oct 6, 2015

If HA did end up using a separate process running alongside, We could ALSO use the ARP detection for additional presence detection of Phones (people).

@maddox
Collaborator
maddox commented Oct 6, 2015

@CCOSTAN that's a good point. It might not hurt having general ARP detection available. ๐Ÿ‘ Though I don't know what it looks like to bring up 2 processes in the current stack.

@avaidyam
avaidyam commented Oct 6, 2015

I suppose it could be the main HA process, and an "escalator" process. If the user allows a component to access the "escalator" process, Python IPC could facilitate multiple components communicating to a counterpart in that process. It's a little convoluted, but VERY powerful, and depending on implementation details, should be secure.

@avaidyam
avaidyam commented Oct 6, 2015

I've found a version that doesn't use scapy below:

# Written by Bob Steinbeiser (https://medium.com/@xtalker)

rawSocket = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.htons(0x0003))
while True:
    packet = rawSocket.recvfrom(2048)
    ethernet_header = packet[0][0:14]
    ethernet_detailed = struct.unpack('!6s6s2s', ethernet_header)
    arp_header = packet[0][14:42]
    arp_detailed = struct.unpack('2s2s1s1s2s6s4s6s4s', arp_header)

    # skip non-ARP packets
    ethertype = ethernet_detailed[2]
    if ethertype != '\x08\x06':
        continue

    source_mac = binascii.hexlify(arp_detailed[5])
    dest_ip = socket.inet_ntoa(arp_detailed[8])
    if source_mac == MAC:
        # BUTTON 1 PRESSED
    else if source_mac == OTHER_MAC:
        # BUTTON 2 PRESSED
    # and on and on, for as many buttons you need
@sfam
Contributor
sfam commented Oct 6, 2015

Just use an ESP8266 and to make a Dash-like-button and have it trigger something in HA directely through REST API...

@avaidyam
avaidyam commented Oct 6, 2015

Easy to say, but the Dash is an easy to purchase button that literally does just that. It would be a bigger "attraction" to the HA platform if you told a person they could buy smart bulbs and a button to trigger things manually with it, along with the automation.

Essentially, a non-programmer/hardware person isn't going to want to fiddle with an ESP8266. It would be more beneficial if we could reroute the Dash itself to a REST API or something similar.

@CCOSTAN
Contributor
CCOSTAN commented Oct 6, 2015

@sfam I agree with @avaidyam. Even with great instructions like this, http://deqingsun.github.io/ESP8266-Dash-Button/ , I'm still intimidated!

Or this one: https://www.hackster.io/noelportugal/ifttt-smart-button

@sfam
Contributor
sfam commented Oct 6, 2015

of course an user-friendly solution would be ideal, but just wanted to show an alternative for those with courage to start hacking with esp8266... :D

@avaidyam

I've just picked up a Dash button myself, and will now be able to take a look at the implementation details.

@CCOSTAN
Contributor
CCOSTAN commented Oct 14, 2015

This would be the BEST ANSWER. Amazon may eventually sell hackable buttons that use the lambda service. That would solve everything.

http://hackaday.com/2015/10/11/amazon-giving-out-sort-of-hackable-amazon-dash-button/

@avaidyam

Unfortunately, it doesn't seem like those are going to be available anytime soon. I'm looking into DNSMasq and router-level fencing to interface with the Dash. It may not really be worth it...

@maddox
Collaborator
maddox commented Oct 14, 2015

I wrote a service last week that lets you register your Dash button and map URLs to process whenever they've been pressed. It's pretty simple. The config looks like this:

{"buttons":[
  {
    "name": "Party Time",
    "address": "a0:02:dc:d9:63:49",
    "url": "http://media.local:8123/api/services/scene/turn_on",
    "method": "POST",
    "headers": {"x-ha-access": "XXX"},
    "json": true,
    "body": {"entity_id": "scene.party_time"}
  },
  {
    "name": "Music",
    "address": "74:75:48:36:45:29",
    "url": "http://media.local:8123/api/services/media_player/media_play",
    "method": "POST",
    "headers": {"x-ha-access": "XXX"},
    "json": true,
    "body": {"entity_id": "media_player.itunes"}
  }
]}

You would need to run this separately, but you can run just this as root. I'll post it up sometime soon.

I can't speak much to it's reliability as I haven't even figured out a good reason to use the buttons ๐Ÿ˜€ so I haven't really used this outside of just getting it to work, heh.

@maddox
Collaborator
maddox commented Oct 14, 2015
@CCOSTAN
Contributor
CCOSTAN commented Oct 14, 2015

@maddox This is great. I think I am going to use it to post events to HA and then from HA, use the event to trigger and then based on conditions, execute various things. (Turn on things in the morning, turn off things at night kinda things)

@avaidyam

@maddox Any thoughts on a python port, so HA can assimilate it?

@avaidyam
avaidyam commented Nov 1, 2015

Closing issue, seeing as root requirement for HA is a bad idea; use @maddox's tool instead.

@avaidyam avaidyam closed this Nov 1, 2015
@w1ll1am23
Collaborator

According to @soggypretzels this is what comes up in google if you search for amazon dash and Home-Assistant. Some people seem to have problems with the dasher package. Just in case you can't get dasher to work, I have a python version that does the same thing. https://github.com/w1ll1am23/pydasher however, you should try to get Maddox's dasher working first I use it, and it works great.

@clach04
Contributor
clach04 commented Jul 25, 2016

I have some notes on this at http://somnambulistic-monkey.blogspot.com/2016/07/home-assistant-custom-events-and-amazon.html - I'm using an HA event/trigger where the name includes the Dash MAC address.

I used DNSmasq on my router to detect the Dash and then send the event via HA's REST api.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment