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

The only thin showing up there is the last time I turne on or off my light manually.

Ouch, I just realized my script works great with two or more dashbuttons but fails if you have only one… :hushed:
So if you have only one dashbutton, then modify the last lines to:

dash_mac = ( "88:71:e5:5e:e0:d4", "")
dash_item = ("DashButton1", "")
dash_last = [0.0, 0.0]

Then it should work. I have amended the script above as well…

FWIW, I noticed that the “stuck on Initializing” issue occurs in Linux but not on Windows. My dash buttons were 100% stable in Windows and then I moved my openhab to Ubuntu 16.04 and started having the issue.

I gave up and went with this instead:

1 Like

This sounds good and complete.
How do you get this into openhab?
Could share some more details?

Is this way as fast as the way of @Jens_Pirnay ?

The way you hook up amazon-dash to openhab is similar to what @Jens_Pirnay posted in this thread on Dec 7, 2017. It’s the same idea but instead of using his python script to listen for button events I use amazon-dash (I already had it configured and working so I just updated the config file).

Here is an outline of what to do:

  1. Install amazon-dash as per instructions.
  2. Create virtual switches in openhab for your buttons. e.g. add something like this to your items file
Switch DashButton1
  1. Configure amazon-dash to turn ON the appropriate DashButtonX openhab virtual switch (from step2). This can be done with MQTT or HTTP. I have a bash script that does a CURL HTTP POST request (make sure you replace the IP address with your own IP of your openhab install):
#!/bin/bash

#Call like this:
#       ./update_openhab_item.sh DashButton1 ON

item=$1
value=$2

curl -X POST --header "Content-Type: text/plain" --header "Accept: application/json" -d "$2" "http://192.168.1.15:8080/rest/items/$1"
  1. I call the above script like this from the amazon-dah.yml
# amazon-dash.yml
# ---------------
settings:
  delay: 10
devices:
  WW:XX:YY:ZZ:AA:BB:
    name: DashButton1
    user: user1
    cmd: /home/user1/update_openhab_item.sh DashButton1 ON

  1. Add rules like this for each of your buttons:
rule DashButton1_Rule
when Item DashButton1 received update ON
then
   //SOME ACTION GOES HERE
    DashButton1.postUpdate(OFF)
end

The amazon-dash solution supports direct HTTP Post calls in the amazon-dash.yml directly so you may not even need the bash script, but I haven’t tried it.

1 Like

I have not tried @Jens_Pirnay’s solution so I don’t know. Amazon-dash is something I was using already and was working well for me so I figured I’d share in case anyone wanted to explore another option.

I did not benchmark it, but I had a look at amazon-dash, it’s using the scapy libray as well but listens to some udp packages the buttons are sending. This should normally come after the dhcp request, so slightly slower. But this package is way nicer programmed and more flexible for other uses than the couple of lines I threw together just to interact with openhab…

But hey, both methods work - great - another solution found. As usual, use the one that suits you best.

@kociubin Thanks a lot for your detailed instructions.
Today I got the chance to test it.

It works great!

Typo: you missed an " at the end of line: curl -X POST …

Remark: for diagnostics you can run at the command line:
sudo amazon-dash
It shows you possible errors in the config file.

Hello everyone! I am the developer of the Amazon-dash project. I have added native support for OpenHAB. I hope it can be useful!

# amazon-dash.yml
# ---------------
settings:
  delay: 10
devices:
  18:74:2E:87:01:F2:
    name: Doritos
    openhab: 192.168.1.140
    item: open_door
    state: ON

Docs:
http://docs.nekmo.org/amazon-dash/config_file.html#openhab-event

I have not been able to personally test it but I have used the @kociubin code (thank you!) and I think it should work. If you can prove it, I would appreciate it.

To use native support for OpenHAB it is necessary to update to version 1.0.0

1 Like

@Nekmo: Thanks for including openhab support.
I’ll test it as soon as possible.
It makes the integration smarter for me.

I have installed the way of @Jens_Pirnay, now i want to change to the way of @Nekmo.

Can i simply remove all the installed files/programms/modules with apt-get remove “name”? All what was explained in the instruction, only with “remove” instead of install?

Or should i keep all the modules/files and only install the new application?

I did the complete fresh installation according to @Nekmo and @kociubin

But I have not tested the new OpenHab support which seems easier/smarter.
https://github.com/Nekmo/amazon-dash

I think yes.

@Nekmo I tried your latest release with openhab support. Unfortunately, it’s not working for me. Two issues:

  1. I get the following error after I press the button (I have “state: ON” in configuration file) :
Listening for events. Amazon-dash will execute the events associated with the registered buttons.
2018-03-14 22:04:32,259 - amazon-dash - DEBUG   - dash_On device executed (mac 74:75:48:e0:8e:dd)
Traceback (most recent call last):
  File "/usr/local/bin/amazon-dash", line 6, in <module>
    catch(cli)()
  File "/usr/local/lib/python3.5/dist-packages/amazon_dash/exceptions.py", line 91, in wrap
    return fn(*args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.5/dist-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/amazon_dash/management.py", line 100, in run
    Listener(config).run(root_allowed=root_allowed)
  File "/usr/local/lib/python3.5/dist-packages/amazon_dash/listener.py", line 154, in run
    scan_devices(self.on_push, lambda d: d.src.lower() in self.devices)
  File "/usr/local/lib/python3.5/dist-packages/amazon_dash/scan.py", line 24, in scan_devices
    sniff(prn=fn, store=0, filter="udp", lfilter=lfilter)
  File "/usr/local/lib/python3.5/dist-packages/scapy/sendrecv.py", line 603, in sniff
    r = prn(p)
  File "/usr/local/lib/python3.5/dist-packages/amazon_dash/listener.py", line 135, in on_push
    self.execute(device)
  File "/usr/local/lib/python3.5/dist-packages/amazon_dash/listener.py", line 145, in execute
    device.execute(root_allowed=self.root_allowed)
  File "/usr/local/lib/python3.5/dist-packages/amazon_dash/listener.py", line 82, in execute
    result = self.execute_instance.execute(root_allowed)
  File "/usr/local/lib/python3.5/dist-packages/amazon_dash/execute.py", line 180, in execute
    resp = request(self.data.get('method', 'get').lower(), self.data['url'], **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/requests/api.py", line 58, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/requests/sessions.py", line 508, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python3.5/dist-packages/requests/sessions.py", line 618, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/requests/adapters.py", line 460, in send
    for i in request.body:
TypeError: 'bool' object is not iterable



"

  1. If I try “state: TOGGLE” I get a different output. Are you sure TOGGLE is supported?
Welcome to Amazon-dash v1.0.0 using Python 3.5.2
Listening for events. Amazon-dash will execute the events associated with the registered buttons.
2018-03-14 22:06:22,976 - amazon-dash - DEBUG   - dash_On device executed (mac 74:75:48:e0:8e:dd)
[Error] Amazon Dash Exception (ExecuteError):
"http://192.168.1.15:8080/rest/items/FamilyRmTVviewingScene" return code 400.

1 Like

Hello, can you try please to change ON on the config file to “ON” (between quotes)? Thanks for your time :slight_smile:

I’m not 100% sure that TOGGLE works. If it does not exist, I will have to eliminate that option until I find a solution. Thank you again

Hi Nekmo,
I had the same Exception ("‘bool’ object is not iterable". Putting ON between quotes solved the problem. Now the buttons work like a charm in openhab. Thanks a lot !

My config in /etc/amazon-dash.yml now looks like
[…]
fd:a8:67:3a:a1:8e:
name: MyButton1
openhab: 192.168.2.100
item: DASH1
state: “ON”

In openhab’s item file “default.items” it looks like

Switch DASH1 “DASH-1-MyFirstDash”

And the corresponding rule in “default.rules”

rule “Rule for Dash-Button 1”
when
Item DASH1 received update
then
[…]

And for the ones using OpenHabian 1.4 there seems to be a configuration error (?) in the python config. Just in case you get the following error

[07:09:38] openhabian@openHABianPi:~$ sudo amazon-dash run
Welcome to Amazon-dash v1.0.0 using Python 2.7.13
Listening for events. Amazon-dash will execute the events associated with the registered buttons.
Traceback (most recent call last):
_ File “/usr/local/bin/amazon-dash”, line 6, in _
_ catch(cli)()_
_ File “/usr/local/lib/python2.7/dist-packages/amazon_dash/exceptions.py”, line 91, in wrap_
_ return fn(*args, **kwargs)_
_ File “/usr/local/lib/python2.7/dist-packages/click/core.py”, line 722, in call_
_ return self.main(*args, **kwargs)_
_ File “/usr/local/lib/python2.7/dist-packages/click/core.py”, line 697, in main_
_ rv = self.invoke(ctx)_
_ File “/usr/local/lib/python2.7/dist-packages/click/core.py”, line 1066, in invoke_
_ return process_result(sub_ctx.command.invoke(sub_ctx))
_ File “/usr/local/lib/python2.7/dist-packages/click/core.py”, line 895, in invoke_
_ return ctx.invoke(self.callback, **ctx.params)_
_ File “/usr/local/lib/python2.7/dist-packages/click/core.py”, line 535, in invoke_
_ return callback(*args, **kwargs)_
_ File “/usr/local/lib/python2.7/dist-packages/amazon_dash/management.py”, line 99, in run_
_ from amazon_dash.listener import Listener_
_ File “/usr/local/lib/python2.7/dist-packages/amazon_dash/listener.py”, line 9, in _
_ from amazon_dash.scan import scan_devices_
_ File “/usr/local/lib/python2.7/dist-packages/amazon_dash/scan.py”, line 6, in _
_ from scapy.all import *_
_ File “/usr/local/lib/python2.7/dist-packages/scapy/all.py”, line 10, in _
_ from .config import *_
_ File “/usr/local/lib/python2.7/dist-packages/scapy/config.py”, line 11, in _
_ from .data import *_
_ File “/usr/local/lib/python2.7/dist-packages/scapy/data.py”, line 184, in _
_ TCP_SERVICES,UDP_SERVICES=load_services("/etc/services")_
_ File “/usr/local/lib/python2.7/dist-packages/scapy/data.py”, line 109, in load_services_
_ f=open(filename, errors=‘ignore’)_
TypeError: ‘errors’ is an invalid keyword argument for this function

You probably have the wrong scapy version. Please check with

pip freeze

The output could look like this (note “scapy-python3” although I am using python 2.7):

amazon-dash==1.0.0
certifi==2018.1.18
chardet==3.0.4
click==6.7
click-default-group==1.2
cryptography==1.7.1
dnspython==1.15.0
enum34==1.1.6
functools32==3.2.3.post2
idna==2.6
ipaddress==1.0.17
jsonschema==2.6.0
keyring==10.1
keyrings.alt==1.3
pyasn1==0.1.9
PyBluez==0.18
pycrypto==2.6.1
pygobject==3.22.0
pyxdg==0.25
PyYAML==3.12
requests==2.18.4
RPi.GPIO==0.6.3
scapy-python3==0.23
SecretStorage==2.3.1
six==1.10.0
subprocess32==3.2.7
tzupdate==1.2.0
urllib3==1.22

The solution: Uninstall scapy-python3

sudo pip uninstall scapy-python3

The output looks like this:

Uninstalling scapy-python3-0.23:

[…] long list of files […]

Proceed (y/n)? y
_ Successfully uninstalled scapy-python3-0.23_

And then reinstall the correct scapy version:

sudo pip install scapy

The output looks like this:

Collecting scapy
_ Downloading scapy-2.3.3.tgz (1.4MB)_
_ 100% |████████████████████████████████| 1.4MB 75kB/s_
Building wheels for collected packages: scapy
_ Running setup.py bdist_wheel for scapy … done_
_ Stored in directory: /root/.cache/pip/wheels/bd/cf/05/d5abc9b4434f39ffe231517dfb8dab96241fef6a99459051f9_
Successfully built scapy
Installing collected packages: scapy
Successfully installed scapy-2.3.3

Now you are ready to go :slight_smile:

Thank you @MahatmaX :slight_smile: It is very important for me to have feedback from users.

I dont know where i go wrong.

I had this script running but after the last update it won’t start after i reboot my Pi.

I get this error

    systemctl status dash.service
dash.service - Amazon Dashbutton Reader
Loaded: loaded (/etc/systemd/system/dash.service; enabled)
Active: failed (Result: start-limit) since Mon 2018-08-06 10:43:59 CEST; 12min ago
Process: 1344 ExecStart=/usr/bin/python /etc/openhab2/scripts/dashbutton/dash.py (code=exited, 
status=1/FAILURE)
Main PID: 1344 (code=exited, status=1/FAILURE)

The rights of my servicefile looks like this:
-rwxr-xr-x 1 root root 208 Mar 6 11:09 dash.service

And this rights of my dash.py looks like this:
-rwxrw-rw- 1 openhabian openhabian 1445 Aug 2 10:25 /etc/openhab2/scripts/dashbutton/dash.py

When i start it manually with sudo systemctl start dash.service the service runs well until i reboot my Pi.

Where is the error?

EDIT (07.08.18): It seems like the service crashes when i press the DashButton too. Yesterday evening i try to press the button and the service status says that the service faild at that time (17:14). Mayby that is a hint for the solution.

After upgrading to a new raspberry image with openhab 2.3 I am getting similar errors like @NilsAcht.
I tried to start the diagnostics:

 sudo amazon-dash run --config /etc/amazon-dash.yml

I am getting:

Welcome to Amazon-dash v1.1.1 using Python 2.7.13
Listening for events. Amazon-dash will execute the events associated with the registered buttons.
Traceback (most recent call last):
  File "/usr/local/bin/amazon-dash", line 6, in <module>
    catch(cli)()
  File "/usr/local/lib/python2.7/dist-packages/amazon_dash/exceptions.py", line 91, in wrap
    return fn(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/amazon_dash/management.py", line 99, in run
    from amazon_dash.listener import Listener
  File "/usr/local/lib/python2.7/dist-packages/amazon_dash/listener.py", line 6, in <module>
    from amazon_dash.confirmations import get_confirmation
  File "/usr/local/lib/python2.7/dist-packages/amazon_dash/confirmations.py", line 5, in <module>
    from amazon_dash._compat import JSONDecodeError
  File "/usr/local/lib/python2.7/dist-packages/amazon_dash/_compat.py", line 18, in <module>
    import subprocess32 as subprocess
ImportError: No module named subprocess32

@Nekmo: May be it’s together with the python version?