Page 2 of 2

Re: RE: Re: New kind of Amazon Dash button to start tasks

Posted: Sunday 04 December 2016 19:55
by jake
Madgeni wrote:async callbacks via the API call
Meaning...?

Re: New kind of Amazon Dash button to start tasks

Posted: Sunday 04 December 2016 20:17
by Madgeni
probably in the context of making one device call, not much. but node is built for asynchronicity, so good practice to not let your code block

Re: New kind of Amazon Dash button to start tasks

Posted: Monday 05 December 2016 22:40
by thebeetleuk
thanks!!

Re: New kind of Amazon Dash button to start tasks

Posted: Monday 05 December 2016 22:43
by thebeetleuk
ok so next question.. I have set this up and is working... How do I get the program to launch on boot of the Pi?

Code: Select all

pi@raspberrypi:~/node_modules/node-dash-button $ sudo node node-dash.js
I'm a bit of a noob when it comes to the pi :)

I have checked rc.local but I cant see where Domoticz is stating on boot to I assume this is the wrong place.

Re: New kind of Amazon Dash button to start tasks

Posted: Monday 05 December 2016 23:01
by thebeetleuk
go it...

in the /etc/rc.local file I added the line. seems to have done the trick.

Code: Select all

sudo node /home/pi/node_modules/node-dash-button/node-dash.js &
I did notice this created 2 processes:

Code: Select all

root       444     1  0 21:55 ?        00:00:00 sudo node /home/pi/node_modules/node-dash-button/node-dash.js
root       465   444  3 21:55 ?        00:00:04 node /home/pi/node_modules/node-dash-button/node-dash.js
Is this normal? do I need the sudo?

Re: New kind of Amazon Dash button to start tasks

Posted: Tuesday 06 December 2016 0:16
by MikeF
I'm experiencing the same thing, i.e., 2 processes get created, one with sudo, one without:

Code: Select all

root     27739  0.0  0.3   6184  3092 pts/0    T    23:02   0:00 sudo node node-dash.js
root     27743  3.7  3.9 110804 37352 pts/0    Tl   23:02   0:02 node node-dash.js
I'm using @pdjm43's code (with my MAC addresses):

Code: Select all

#!/usr/bin/env node
var dash_button = require('node-dash-button');
var dash = dash_button(["50:f5:da:38:e1:f0","ac:63:be:17:2f:4a"], null, null, 'arp');  //mac address from node-dash-button$
var requestify = require('requestify');
dash.on("detected", function (dash_id){
    if (dash_id === "50:f5:da:38:e1:f0"){
       console.log("Dash1");
       requestify.get('http://127.0.0.1:8080/json.htm?type=command&param=switchlight&idx=118&switchcmd=Toggle');
    } else if (dash_id === "ac:63:be:17:2f:4a"){
       console.log("Dash2");
       requestify.get('http://127.0.0.1:8080/json.htm?type=command&param=switchlight&idx=221&switchcmd=Toggle');
    }
});

If I run this as

Code: Select all

nohup sudo node node-dash.js &
then the second process reverses the effect of the first, i.e., toggles the light back again!

Re: New kind of Amazon Dash button to start tasks

Posted: Tuesday 06 December 2016 15:13
by thebeetleuk
Mike,

I'll post my script later but I was thinking as an improvement to the script I am thinking about creating a dummy button for each dash button. so then when I have set it up initially I don't need to edit the file. From that I can just use the json queries in the on and off actions on that dummy button to kick off the relevant activity.

So this way you can then use the Domoticz GUI to edit everything.

I suppose you could go one step further and read an array of values from the Domoticz variables and then the script would be independent from the mac addresses and the IDX values.

Thoughts?

Re: New kind of Amazon Dash button to start tasks

Posted: Tuesday 06 December 2016 17:28
by MikeF
Yes, I can see that this would be useful, although it's no great hardship to edit the script and add the MAC addresses and IDX's - this is only a one-time activity.

BTW, I was initially concerned about these becoming useless once the battery dies (I bought 2 used on eBay), but I have managed to carefully score around the join, and there is a Duracell AAA battery inside (and I've put it back together again!).

Image

Re: New kind of Amazon Dash button to start tasks

Posted: Wednesday 07 December 2016 3:03
by alexsh1
MikeF wrote:BTW, I was initially concerned about these becoming useless once the battery dies (I bought 2 used on eBay)
They are £5 each at Amazon (or free if you make one order) so in my view no need to be concerned. In theory one can change them every year.
Thought your investigation comes very useful. Thank you.

Re: New kind of Amazon Dash button to start tasks

Posted: Wednesday 07 December 2016 22:31
by thebeetleuk
Nice one on the battery. I wouldn't have thought it was a AAA inside even though I did think the device was a bit large. It will be interesting to see how long these last. I suspect this will very much depend on usage :)

Re: New kind of Amazon Dash button to start tasks

Posted: Wednesday 07 December 2016 22:33
by thebeetleuk
My code calling a bunch of dummy switches which in turn run a json command to perform the aciton I want. this way I know when its a dash button thats turned something on as it will show in the dummy switch log :)

I used a case statement instead of a if else :)
Spoiler: show
var dash_button = require('node-dash-button');

var dash = dash_button(["AC:63:BE:8B:6D:8C","AC:63:BE:49:56:84","ac:63:be:25:27:f6","44:65:0d:8b:96:a7","50:f5:da:ad:81:5f","ac:63:be:2a:b5:da","50:f5:da:60:e1:20","50:f5:da:58:70:39","44:65:0d:08:fd:d$
null, null, 'arp'); //mac address from node-dash-button setup scan

var requestify = require('requestify');

console.log("Waiting for you to push a DASH Button");

dash.on("detected", function (dash_id){

switch(dash_id){
case "AC:63:BE:8B:6D:8C":
console.log("Dash Button Pressed - OLAY");
requestify.get('http://192.168.0.101:8080/json.htm?type ... cmd=Toggle');
break;
case "AC:63:BE:49:56:84":
console.log("Dash Button Pressed - Play-Doh");
requestify.get('http://192.168.0.101:8080/json.htm?type ... cmd=Toggle');
break;
case "ac:63:be:25:27:f6":
console.log("Dash Button Pressed - Neutorgena");
requestify.get('http://192.168.0.101:8080/json.htm?type ... cmd=Toggle');
break;
case "44:65:0d:8b:96:a7":
console.log("Dash Button Pressed - On");
requestify.get('http://192.168.0.101:8080/json.htm?type ... cmd=Toggle');
break;
case "50:f5:da:ad:81:5f":
console.log("Dash Button Pressed - Philips");
requestify.get('http://192.168.0.101:8080/json.htm?type ... cmd=Toggle');
break;
case "ac:63:be:2a:b5:da":
console.log("Dash Button Pressed - Ariel");
requestify.get('http://192.168.0.101:8080/json.htm?type ... cmd=Toggle');
break;
case "50:f5:da:60:e1:20":
console.log("Dash Button Pressed - Finish");
requestify.get('http://192.168.0.101:8080/json.htm?type ... cmd=Toggle');
break;
case "50:f5:da:58:70:39":
console.log("Dash Button Pressed - Kleenex");
requestify.get('http://192.168.0.101:8080/json.htm?type ... cmd=Toggle');
break;
case "44:65:0d:08:fd:d0":
console.log("Dash Button Pressed - Dolce");
requestify.get('http://192.168.0.101:8080/json.htm?type ... cmd=Toggle');
break;
case "ac:63:be:02:6a:77":
console.log("Dash Button Pressed - Gillette");
requestify.get('http://192.168.0.101:8080/json.htm?type ... cmd=Toggle');
break;
}
});

Re: New kind of Amazon Dash button to start tasks

Posted: Saturday 10 December 2016 17:44
by MikeF
Just bought two more of these on eBay - Andrex and Rimmel. Both registered OK with Amazon, but when I run findbutton and press the Rimmel button, I get

Code: Select all

Possible dash hardware address detected: 34:d2:70:29:a3:2a Manufacturer: unknown Protocol: udp
Possible dash hardware address detected: 34:d2:70:29:a3:2a Manufacturer: unknown Protocol: arp
- also, the light glows yellow twice before the usual 5 sequences of red flashes. Is this a 'rogue' button, or do the yellow flashes mean low battery? (this is not mentioned on the Amazon help page: About the Indicator Light on Dash Button)

Separately, I've created a python routine using scapy, which seems to be simpler than the node.js version:

Code: Select all

from scapy.all import *
import os
import requests

def arp_display(pkt):
	if pkt[ARP].op == 1: #who-has (request)
		if pkt[ARP].hwsrc == '50:f5:da:38:e1:f0': # ARP Probe
			print "ARP Probe from: Dash 1 " + pkt[ARP].psrc
			url = 'http://127.0.0.1:8080/json.htm?type=command&param=switchlight&idx=136&switchcmd=Toggle'
			r = requests.get(url)
			
		if pkt[ARP].hwsrc == 'ac:63:be:17:2f:4a': # ARP Probe
			print "ARP Probe from: Dash 2 " + pkt[ARP].psrc
			os.system("bash /Users/mjf2708/HA/hive_boost.sh")
			
		if pkt[ARP].hwsrc == 'ac:63:be:c8:84:93': # ARP Probe
			print "ARP Probe from: Dash 3 " + pkt[ARP].psrc
			# not yet allocated
			
		if pkt[ARP].hwsrc == '34:d2:70:29:a3:2a': # ARP Probe
			print "ARP Probe from: Dash 4 " + pkt[ARP].psrc
			# not yet allocated
			

print sniff(prn=arp_display, filter="arp", store=0, count=0)
(Dash 2 runs a bash script which triggers a heating boost through my Hive Home Heating system.)

Re: New kind of Amazon Dash button to start tasks

Posted: Tuesday 13 December 2016 13:40
by thebeetleuk
all you really care about is the MAC address so should work fine even if its a rogue button :)

Re: New kind of Amazon Dash button to start tasks

Posted: Tuesday 13 December 2016 14:26
by MikeF
Agreed. I just wondered if anyone knew the significance of the LED flashing yellow?

Re: New kind of Amazon Dash button to start tasks

Posted: Monday 13 November 2017 17:45
by stress1ner
Hello guys. I am trying to set this up as a doorbell can anyone guide me with that process or share their method.
I see that most implementations in this thread focus on switch items on and off, so was wondering how to get it to lay a sound or tts when pushed.