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

One additional note:

If you use the python-way to control the dashbutton, you can uninstall the dasbutton binding and the things-definition.

Your rule with “amazondashbutton… gets triggered” uses still the binding, not the python script.

Okay, thank you very much!

I did not know that. I guess this detail (the items definition) is missing in the posting above. Maybe this could be added.

Done :wink:

Here I never got it working reliably - every time I rebooted there were different dash buttons that weren’t working, and after some uptime often others would fail, too. I’ve now given up on this junk and recycled the dash buttons, this way at least I got a working AAA-battery out of each.

I can’t get the dashbutton to work. So I want to test if the script is working. I tried to change and restart the script to see if I could monitor the messages of the script. But there are no messages.
Is my (your) script correct like this?


#!/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!
                                syslog.syslog("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:
                                        syslog.syslog("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://192.168.178.68:8080/rest/items/"
# The MAC addresses of the dashbuttons
dash_mac = ("00:fc:8b:9e:03:b6")
# The item-names of the corresponding Dashboard entries in openhab
dash_item = ("africola")

Have a look at the posting above.
If you want to debug the stuff, i’d replace all

syslog.syslog("Dash-Button %d detected" % (index +1))

by plain

print "Dash-Button %d detected" % (index +1)

Then you could call the script directly with

sudo dash.py

and watch what messages it provides…

Is there a way to send this log-entrys into the openhab.log, too? Instead of printing on the shell.

See here - the overhead to do so was too big for my taste - so unless you do it yourself: sorry, no.

Oh I see. I misunderstood your post above. I changed it from syslog.syslog back to print and called the script. But it will only provide the mac-adress of my dash-button.

That’s a good sign. Now add these addresses at the bottom of the script. Have you created the corresponding items and rules in openhab? (Please refer to my initial post above).

As you can see above, the adress is already added at the bottom.
I hav an item and a rule, but it wont work. That’s why I tried to see if the script itself is working to make sure the rule is triggered.

Can you see the event been trigger in the Events-log (tail -f /var/log/openhab2/events.log or better use frontail in the browser (http://youropenhab:9001) ? It should show something like:

==> /var/log/openhab2/events.log <==

2018-02-07 11:14:37.354 [vent.ItemStateChangedEvent] - DashButton3 changed from NULL to ON

2018-02-07 11:14:37.367 [ome.event.ItemCommandEvent] - Item 'V_DG_PY_Buben_Jens' received command ON

2018-02-07 11:14:37.376 [vent.ItemStateChangedEvent] - DashButton3 changed from ON to OFF

The last two statements are coming from the rule, but the first one is issued due to the rest-call in the python script.

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.