Amazon dash button: Things won't come online, INITIALIZING

After I upgraded to openHABian 1.3 and installed my amazon dash buttons, everything worked fine.
After a few days, the dash buttons went into “INITIALIZING” and won’t come back online.
If I restart the bundle in the oh2 console, it won’t change.

[12:41:21] openhabian@openHABianPi:/etc/openhab2$ sudo getcap `realpath /usr/bin/java`
/usr/lib/jvm/zulu-embedded-8-armhf/bin/java = cap_net_admin,cap_net_raw+eip cap_net_bind_service+ep

is there a test for checking libcap is working?

I have the same issue. Neither restarting openhab or rebooting the entire PI does solve the problem. The button is in “INITIALZING” mode for days now.

Anyone here who can help?

Thanks a lot!
Daniel

The only thing that helped me was to restart the the binding within Karaf:

#!/bin/bash
BUNDLE="org.openhab.binding.amazondashbutton"
if [ "$1" == "kodi" ]
then
	BUNDLE="org.openhab.binding.kodi"
fi
if [ "$1" == "knx" ]
then
	BUNDLE="org.openhab.binding.knx"
fi
if [ "$1" == "mqtt" ]
then
	BUNDLE="org.openhab.binding.mqtt"
fi
echo "Restarting bundle '$BUNDLE'"
/usr/bin/ssh -p 8101 -i /home/user/user.id_rsa uli@localhost "bundle:restart $BUNDLE" 

You could just open karaf and type the

bundle:restart org.openhab.binding.amazondashbutton

bit yourself. To automatize it I used the approach shown here

2 Likes

Same to me. Yesterday amazon dash button was online, but it didn´t work. After that i did a new install of libcap and made sudo getcap…

After that and a reboot amazondashbutton was online and working.

A few reboots later without changing something on amazondashbuttpn config - thing was “initializing” and never got back to online.

Now i made a binding-restart in karaf like you described in the last post and amazondashbutton immediately got back online.

Anybody knows why this always gets back to “initialising”?

Honestly I don’t - I finally gave up on the dashbutton binding, as there were always issues after a restart: 1 to 2 of my three dashbuttons not coming online.
I chose a different approach by giving up on the dashbutton-binding and using a python script to listen to the network and get the DHCP request of the button when being clicked. It’s about 1-2 seconds faster than the binding approach (YMMV):

Prerequisite: you need to install the python ‘scapy’ and ‘requests’ libraries to scan for the DHCP messages the dashbutton is broadcasting when pressed:

sudo apt-get install python-scapy
sudo apt-get install python-requests

(the alternative way with

python -m pip install scapy
python -m pip install requests

should work as well).

In addition you need to install the tcpdump package for scapy to work:

sudo apt-get install tcpdump

Then these files have to be created:

/etc/openhab2/scripts/dashbutton/dash.py

#!/usr/bin/python
# -*- coding: utf-8 -*-

from scapy.all import *
import sys, os
import requests, datetime
import syslog
import sys

def arp_display(pkt):
	if pkt.haslayer(DHCP):
		print (pkt[Ether].src)
		for index in range(len(dash_mac)):
			if pkt[Ether].src == dash_mac[index]: #die MAC Adresse des Button mit Kleinbuchstaben!
				print "Dash-Button %d detected" % (index +1)
				if (time.time() - dash_last[index]) > 5.0:
					dash_last[index] = time.time()
					url = ohabserver + dash_item[index] + "/state"
					s = "ON"
					print url +"=" + s
					try:
						myResponse = requests.put(url, s)
					except:
						syslog.syslog("Fehler beim Abruf von %(url)s : %(status)s" % {"url":url, "status":myResponse.status_code} ) 
				else:
					print "Aber doppelt, deswegen ignoriert..."


reload(sys)
sys.setdefaultencoding("utf-8")

# MODIFY THE FOLLOWING LINES ACCORDING TO YOUR NEEDS AND YOUR ENVIRONMENT
# The URL of your openhab-installation
ohabserver = "http://127.0.0.1:8080/rest/items/"
# The MAC addresses of the dashbuttons, please note the additional empty entry at the end of the real dashbuttons!!
dash_mac = ( "88:71:e5:5e:e0:d4", "fc:a6:67:48:09:15", "b4:7c:9c:e1:c0:d9", "")
# The item-names of the corresponding Dashboard entries in openhab (plus an empty one at the end)
dash_item = ("DashButton1", "DashButton2", "DashButton3", "")
# As many entries as there are dashbuttons plus 1
dash_last = [0.0, 0.0, 0.0, 0.0]

print sniff(prn=arp_display, store=0,count=0)

(please note that you have to amend the script in the last few lines according to your environment).

The corresponding service definition:

dash.service

[Unit]
Description=Amazon Dashbutton Reader

[Service]
Type=simple
User=root
Group=root
ExecStart=/usr/bin/python /etc/openhab2/scripts/dashbutton/dash.py
Restart=always

[Install]
WantedBy=multi-user.target
 

to be installed with

sudo cp dash.service /etc/systemd/system
sudo systemctl daemon-reload
sudo systemctl enable dash.service
sudo systemctl start dash.service
systemctl status dash.service

For every dashbutton you need a corresponding openhab-item:

Switch DashButton1 
[... more Dashbuttons...]

and a rule that gets fired when the python-Script sends a command to this button:

rule Dash1
	Item DashButton1 received update ON
then
	logInfo("dash.rules", "DashButton 1 was pressed")
// BEGIN OF ACTION
// e.g. otherButton.sendCommand(ON)
// END OF ACTION
// Reset the state of button, that it will see the next update...
	DashButton1.postUpdate(OFF)
end

Drawback: the python-script needs root privileges
Advantage: rock solid

6 Likes

Hello everybody!
I’m having exactly the same issues.
I’ve already figured out that the linux package triggerhappy was disturbuing the binding - uninstalled. Afterwards it worked at least sometimes.
But after restarting I have the same issue.
Also find it quite interesting, that “log:set debug org.openhab.binding.amazondashbutton” does not bring more debug outputs when I’m having the issue that the dashbutton is not coming online.
Could write now millions of combinations how I tried to make it work. If you have some questions, I’m intereseted to comment.
Kind Regards
Stefan

I had the same problem as others. I just uninstalled the binding and reinstalled everything again. All my items were in config files so it wasn’t any real hassle.

On the plus side while trying to troubleshoot I came across a tip about manually assigning the DNS for the items to shave a few seconds off how long they take.

From time to time I have the same issue, too.

I just simply delete the “INITIALIZING” thing

via PaperUI --> Configuration --> Things --> Dash Button [INITIALIZING].

Then I add it immediately again !

That’s all!

Can you tell more about this with the DNS?

Normally when you add a device to your network like a dash your router runs a Domain Name Service(DNS) which assigns an IP to a device.

I’m guessing the idea is that since the Dashes are off most of the time, when you push them, they will first ask the DNS provider what IP is. Then they can do their magic.
Now most/all routers have options to set devices to fixed ips. So if you give all your dashes fixed IPs, then in theory the time taken by the DNS to assign an IP should be less.
Once your router has seen the device and MAC it should be much easier to add them to the fixed assignment list. (ASUS had a drop down of hte device against thier mac and last/currentIP")

I;ve always found dash speed to be inconsistent in how long they take to activate but it might just be the placebo but they activate just a little bit faster.

And again my dash button stops working. It always stays in state “initializing”. I can´t work with this, so it´s completely unusable if i have to integrate the dashbutton again every few days.

Is there no other way to check the network for the registration process of the dash button?

Can you please tell me where the dash.service file has to be put in?

As outlined above in my post:

sudo cp dash.service /etc/systemd/system
sudo systemctl daemon-reload
sudo systemctl enable dash.service
sudo systemctl start dash.service
systemctl status dash.service

the service file has to go to

/etc/systemd

and the script to

/etc/openhab2/scripts/dashbutton/dash.py

And I can confirm this approach works flawlessly for two consequtive months and survived all restarts.

1 Like

Thank you very much! For your confirmation as well - very good to know that there is a working approach to fix the issue!

I tried to install this, but i get the following error, with the last command (status):

systemctl status dash.service
● dash.service - Amazon Dashbutton Reader
   Loaded: loaded (/etc/systemd/system/dash.service; enabled)
   Active: failed (Result: start-limit) since Mi 2018-01-24 13:40:01 CET; 5s ago
  Process: 22472 ExecStart=/usr/bin/python /etc/openhab2/scripts/dashbutton/dash.py (code=exited, status=1/FAILURE)
 Main PID: 22472 (code=exited, status=1/FAILURE)

owner of the dash.py-file in folder xxx/scripts/dashbutton is user “openhab”, group is “openhab”

rights are 766


Can i remove the pcap4j stuff along with the amazondashbutton-binding, when this python script is working?

Did you install scapy? What messages does the direct execution of the script provide?

scapy ??? There was no instruction to do that…

No, i didn´t install that. I only did what you described.

I made a new python-file into the scripts folder and the service-file.
After that i entered the commands for enabling the service in systemd.

debian@debian:/$ /usr/bin/python /etc/openhab2/scripts/dashbutton/dash.py
Traceback (most recent call last):
  File "/etc/openhab2/scripts/dashbutton/dash.py", line 4, in <module>
    from scapy.all import *
ImportError: No module named scapy.all
debian@debian:/$

Can you explain some more about scapy installation? I saw the instructions, but i´m a linux noob. In what directorys should i copy the github files???

Can you give me a full exaple where this files would be placed best?

git clone https://github.com/secdev/scapy
cd scapy
./run_scapy
>>>

I´m a windows user and linux is not my best friend… So please can someone tell me, where i should place this scapy files in a debian installation?

In windows it would be “c:/programm files”. But where should i place this scapy?

The error message clearly shows that the scapy library is missing.

My bad, I’ll update my post later - I just wanted to share which way I was going to solve the dashbutton odyssee once and for all.

Make your life simple by using:

sudo apt-get install python-scapy

that should do the magic for you…

Next error:

debian@debian:~$ /usr/bin/python /etc/openhab2/scripts/dashbutton/dash.py
WARNING: Failed to execute tcpdump. Check it is installed and in the PATH
WARNING: No route found for IPv6 destination :: (no default route?)
Traceback (most recent call last):
  File "/etc/openhab2/scripts/dashbutton/dash.py", line 6, in <module>
    import requests, datetime
ImportError: No module named requests