Amazon Dash Button as openHAB Trigger


(SteveW) #47

I see - that makes more sense. Thankyou for your replies Rich. I know now where to experiment.


(SteveW) #48

I tried defining the Item as a Contact:
Contact DashContact "Dash button as contact" { channel = "amazondashbutton:dashbutton:ac-63-be-xx-xx-x:press" }

and as a String
String DashString "Dash button as string" { channel = "amazondashbutton:dashbutton:ac-63-be-xx-xx-xx:press" }

and define a rule on each:
rule "RunCode 1 string changed"
when
Item DashString received update
then
executeCommandLine("php /opt/openhab2/scripts/myscript.php")

end
rule "RunCode 1 contact changed"
when
Item DashContact received update
then
executeCommandLine("php /opt/openhab2/scripts/myscript.php")
end

The rules are still not triggered. I still only receive the one line in the log:tail ChannelTriggeredEvent.
Perhaps I am defining the Item's channel incorrectly...

I wonder if @oliver can educate me please?


(Oliver Libutzki) #49

Hi @steve098 ,

you're close!

The binding uses a trigger channel which doesn't have to be linked to an item. You can easily use it in your rules like this:

rule "Dash button pressed"
    when
        Channel "amazondashbutton:dashbutton:ac-63-be-xx-xx-xx:press" triggered
    then
        println("The Dash button has been pressed")
end

(SteveW) #50

Huraah! It's alive! Thankyou Oliver! Would you consider updating the readme with this simple example to save the sanity of others!
Many thanks for your work.
Steve


(Rich Koshak) #51

I had no idea that was even possible. I'm not sure what I think about that. It seems to violate the standard OH architecture. But if OH allows it I guess it is kosher.

But, is there any way to bind an Item to the channel? If not that really does seem to violate the way bindings are supposed to work.


(Oliver Libutzki) #52

It's an Eclipse Smarthome concept: https://github.com/eclipse/smarthome/blob/master/docs/documentation/development/bindings/thing-definition.md#channels (see trigger channel section)

Unlike other channel which can be bound to an item, trigger channels do not have a state. There is just an event (button pressed). If you have a channel which is bound to a Switch you have an On/Off-State whch is just artifical as the button is not on or off at all.

Moreover, using a Switch would mean that it's possible to change the state of the item, but for a simple button you just cannot set/change any state.


(SteveW) #53

I (think) I've updated the docs.openhab.org readme for the Amazon Dash addon with the above example code, via a pull request. All new to me though so may be the wrong way of going about it.


(Rich Koshak) #54

Clearly it doesn't but this is a concept that is completely new in OH. There is no documentation for it in the docs yet. And while I admit to not reading each and every posting on this forum, I believe this is the first mention of a Channel trigger for Rules anywhere on the OH side of the ESH/OH 2 divide.

In this case the documentation for Rules needs to be updated as there is no mention of "Channel" as a valid Rule trigger.

Is this the new concept we have heard about that is intended to replace the old capability of the 1.9 Astro binding where it generates an event on a Switch at sunrise/sunset, etc?

Is one able to persist when these channels are triggered without creating a new Item (not bound to the channel since it isn't allow) and Rules to update that Item? I'm thinking of a use case where in a Rule where I may care if that Channel was triggered say five minutes ago. It feels like a lot of extra work for the users that didn't have to be done previously.

People have been using Switches for simple buttons in OH 1.x since the beginning. But your comment implies that we will be able to put a Triggering channel on our Sitemaps. Is there a new Trigger element in work or do we still have to use a Switch to simulate a Trigger?

And if we are concerned about the user changing the state a Contact can be used which has an implied "read only".

At a high level, I understand philosophically why a Trigger like this wouldn't be assignable to an Item, but I can think of several use cases off the top of my head where this makes things that used to be simple and straightforward in OH 1.x impossible or challenging in OH 2.

This is probably a larger discussion but since this Binding is the first to use such triggers this is the first time its come up.


(Oliver Libutzki) #55

I think we should not use this thread for the discussion. This is the corresponding pull request: https://github.com/eclipse/smarthome/pull/1936


(Oliver Libutzki) #56

Thanks a lot! In general the openHAB / Eclipse Smarthome Documentation seems to lack this feature,


(Rich Koshak) #57

Well, given that it was only merged and approved a month ago and no one outside of the developers seems to have been informed that is not surprising. I believe yours is the first binding to implement this feature.


Rule triggers options
(SteveW) #58

For a newbie like myself, having just got my head around linking Things to Items via channels, the description in http://docs.openhab.org/addons/bindings/amazondashbutton/readme.html is misleading:

In openHAB it can be used as a simple switch

You will forgive us therefore when we try and create a Switch Item and bind it with the Dash channel, as per the documentation http://docs.openhab.org/concepts/things.html where:

Channels are linked to items, where such links are the glue between the virtual and the physical layer

I hope you can appreciate the leap in faith needed to create an Item-less Thing for a beginner or even seasoned OpenHAB user.

I would offer to amend the readme for the Dashbutton further, as I feel it needs this crucial difference from a stereotypical Thing:Item relationship emphasising, but my understanding and experience is too limited to apply the correct terminology.

I think as a concept, channel triggers make sense and I can see it making for more flexibility in home automation, perhaps at the expense of pleasing the existing 1.x cohort.


(Oliver Libutzki) #59

You are right. The documentation is just wrong. In the first version of the binding a "normal" channel bound to a Switch item has been used.

While reviewing @Kai mentioned that the trigger channel would fit better. Unfortunately I did not update the docs accordingly. Will do so soon!


(Oliver Libutzki) #60

I updated the documentation: https://github.com/openhab/openhab2-addons/pull/1380


(SteveW) #61

Thanks Oliver for the updated docs and for a great plugin.


(Stefan Endrullis) #62

@oliver
Thanks for this plugin, Oliver! It works really good. The only difficulty for me was to figure out how the trigger event is used in the rules. So I made the same mistake as Steve when the documentation was not yet updated. With the new example it's much clearer now.

The only thing that remains a bit unclear to me is the ability that I can bind an item to this channel. Does this have any effect or it it ignored completely?
If it's ignored, is it possible to prevent the linking ability so that users do not get confused by that?

Moreover since this plugin uses an undocumented OH feature (channel event), I assume that every user needs to read the binding documentation in order to get it work. What about placing a link to the binding documentation in the thing or binding description shown in the paperui? Actually, I wish this would be a default for all OH plugins. :wink:

Anyway, thanks a lot for your work on this plugin!


(Oliver Libutzki) #63

http://docs.openhab.org/addons/bindings/amazondashbutton/readme.html is updates now.


(Artyom Syomushkin) #64

Hi. Did anyone experienced with Amazon IoT Button https://www.amazon.com/dp/B01C7WE5WM ?
It should have same hardware as Dash button, but from description it should talk MQTT, and all you need is to make it somehow publish topics on your MQTT broker instead of AWS. But basically for original use as remote controller it should be fine to use AWS - AWS is acting like fast MQTT broker, to which OpenHab could be connected as well.
Worth to try?


(Rich Koshak) #65

I looked at them when they first came out but they sold out too fast. It would be nice to have one that talks to MQTT directly (eliminates the lag with the Dash button right now).

At $20 I personally would only consider it if it had a relatively easy user replaceable battery. $20 is too much for something disposable. However, with the new Amazon Dash Binding it is possible to get something that works well for $5.


(Super Ook) #66

Hi Oliver,

thanks for your binding. Looks promising. However, I think I have problems getting it to work properly as I don't get any things in the inbox when I press the dash button.
The situation looks quite well

  • OH2 running on raspbian, Raspberry Pi 2
  • amazondash binding installed and runs properly; I see the binding in the paper UI
  • libpcap-dev is installed in raspbian
  • setcap is set as you described: sudo setcap cap_net_raw,cap_net_admin=eip realpath /usr/bin/java
  • dash button is configured in the network
  • I see the arp requests on my PC with wireshark
  • I see the arp requests on the raspi with tcpdump

sudo tcpdump -i eth0 arp and ether host XX:XX:XX:XX:XX:XX -l
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 262144 bytes
21:15:02.608080 ARP, Request who-has fritz.box tell dash-ariel.fritz.box, length 46
21:15:16.103170 ARP, Request who-has fritz.box tell dash-ariel.fritz.box, length 46
  • I don't see any messages in the log from your binding though
  • no new things in the inbox
    Any hints what could be wrong? How can I make sure the binding can correctly use the libpcap?

Cheers,
Hauke