Amazon Dash Button as openHAB Trigger

I recommend looking at the Items and Rules documentation.
http://docs.openhab.org/features/items.html
http://docs.openhab.org/features/automation/ruledsl.html

You do not say what happens when you press the RunCode1 element on the Sitemap. Does it trigger the rule or not? If not this isn’t a Dash binding problem but a fundamental problem with the Item’s configuration.

Can you trigger the rule if you define a separate Item to put on your sitemap from the one that is supposed to respond to the Dash button?

Do you see RunCode1 being updated in events.log when you press either the Dash or the sitemap element?

Try giving the full path the php in your command line. OH is running as a separate and non-privileged user and it is safest to assume its path is severely limited. It is unlikely that php is in its path so it can’t find it to run it.

Thankyou for a prompt reply, sorry for not being clear.

Pressing RunCode1 element (button) on the sitemap works fine - the rule is triggered, executeCommandLine is run and the script runs.
I get this in the logfile for GUI button press: 16:14:01.290 [INFO ] [smarthome.event.ItemCommandEvent ] - Item ‘RunCode1’ received command ON
16:14:01.312 [INFO ] [lipse.smarthome.io.net.exec.ExecUtil] - executed commandLine ‘php /opt/openhab2/scripts/myscripts.php’

If I press the Dash Button, I get this in the log:
16:10:54.022 [INFO ] [marthome.event.ChannelTriggeredEvent] - amazondashbutton:dashbutton:ac-63-be-xx-xx-xx:press triggered
…and nothing else.

It is probably my lack of understanding in how to process .event.ChannelTriggeredEvent (as triggered by the Dash Button) as opposed to .event.ItemCommandEvent (as triggered by the GUI button).

Perhaps I have not set up the Item correctly - the Dash Button emits “:press” rather than “Command ON”, so I can see my rule failing. Do I need a way of mapping the Dash button “Press:” to an “ON/OFF” command suitable for a Switch?

I will re-read those links on rules and Items you have sent.

Thankyou for your patience.

Properly configured there is no difference as far as the Rules are concerned.

You say “the log file”, are you referring to the event.log?

If you do not see an entry in the event.log when you press the Dash button it means there is something wrong between the binding and your Item. This helps narrow down where to look.

You have proven that the Rule itself is fine because it executes when you press the button on the sitemap.

@oliver, what types of Items(s) are valid for the press channel? Is Switch supported or should it be Contact or something else? If there are restrictions on the type of Item the channel supports it should be in the readme.

The “log file” I refer to above is the Openhab Karaf output from “log:tail” when I press the Dash button/Sitemap button

The /opt/openhab2/userdata/logs/events.log shows the following for a Dash button press
2016-10-31 16:52:44.118 [ChannelTriggeredEvent ] - amazondashbutton:dashbutton:ac-63-be-xx-xx-xx:press triggered

The Sitemap Switch button when pressed shows the following in the events.log
2016-10-31 16:54:36.501 [ItemCommandEvent ] - Item ‘RunCode1’ received command ON
2016-10-31 16:54:36.504 [ItemStateChangedEvent ] - RunCode1 changed from NULL to ON

I guess my condensed question would therefore be how I trigger a rule for the ChannelTriggeredEvent produced by the Dash button; whether my attempt to link it to a Sitemap GUI button is just a red herring. My goal is I hope pretty straightforward - press the Dash Button, execute Code.

You don’t. Only Time or Item events can trigger a Rule. That is the whole point of Items, to provide a common layer of abstraction between the dozens of different technologies and the rest of your HA system.

The problem is the channel event is not sending the command to the Switch. The problem is either in the binding config, the channel string, or in how the Item is bound to the channel.

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

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?

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
1 Like

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

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.

It’s an Eclipse Smarthome concept: smarthome/docs/documentation/development/bindings/thing-definition.md at master · eclipse-archived/smarthome · GitHub (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.

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.

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.

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

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

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.

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.

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!

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

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