Rules don't work

Hi,
my setting is a raspi1 with openhabian2.

My first rules where made by the “experimental rule engine” (PaperUI -> AddOns -> Misc ->
Rule Engine (Experimental)) … and they work fine as far. But now i like to enhance the logics a bit.

Unfortunaly my rule do not work - maybe someone can help to find my mistake:

i’ve place a rule named “DashButtonGilette.rules” in the folder “./etc/openhab2/rules/”. The rule is a simple build like this:

rule "DashButton pressed"
   when
       Channel "amazondashbutton:dashbutton:xx-xx-xx-xx-ed-1c:press" triggered
   then
       Hue_lightstrip.sendCommand(ON)
end

“Hue_lightstrip” is the exact name of the thing; the Channel is straight from the channel below the thing “DashButtonGillette” (just anonymous here).

…what mistake has happened to me?

regards
Tom

PS:little addition: i’ve noticed that there is another rules folder: ./srv/openhab2-conf/rules/ … here i’ve found my rule too (mirrored?) … i don’t think this is a important information … just for completion.

Which version do you use?
openhabian is v1.3 currently, but it provides both stable (openHAB2.1) and unstable (openHAB2.2) version.

In case of openHAB2.1 I’m pretty sure that the file-based rules engine does not provide channel triggers yet, you have to use items as triggers instead, so just create an item and link it to the dash button channel, then use this item to trigger the rule.
my.items:

Switch MyDashButton {channel="amazondashbutton:dashbutton:xx-xx-xx-xx-ed-1c:press"}

my.rules:

rule "DashButton pressed"
when
    Item MyDashButton received command
then
    Hue_lightstrip.sendCommand(ON)
end

In question of the correct folder: /etc/openhab2/rules/ is the correct one.

You are probably not going to be happy with this setup. A Pi 1 is really underpowered and has too little RAM to comfortably run OH. People do it so if you don’t give OH too much to do or expect too quick of a response you might be OK.

Do you really mean /etc/openab2/rules or is etc under some other folder as implied by the .?

You need to reference an Item linked to a Channel on a Thing. Not a Thing directly.

I’m not sure either but I think Dash has been around since before 2.1 Release and it has always used Channel triggers like this. It is, to my knowledge the very first binding to use Thing triggers, beating Astro by several months.

openHAB2.2 is installed on my System. And im quite sure that like Rich Koshak said it should work - because of this manual: http://onesmarthome.de/smart-home-openhab-2-dash-button/ chapter “openHAB 2 Dash Button – Software – Paper UI Dash Button Binding” (german only)

Yes, in case of OH2.2 there is a good chance that channel trigger should work.

Did you link the correct channel to the item Hue_lightstrip? You can’t send commands to things, only to items.

1 Like

Yes, i think there is the problem - Just now i’ve checked the doc http://docs.openhab.org/configuration/items.html / Chapter “Paper UI Linking”. First step there descripe to create an Item under “configuration” -> “items”. … but under configuration there is no such “chapter”. Under Configuration ist only …

  • System
  • Bindings
  • Services
  • Things

where can i link channels to items (by paper ui if possible).

You must create the Items in PaperUI. Then you can link the Items to a Channel by browsing to the Thing, click on the up/down arrows to the right of the desired channel, and click the + next to Linked Items.

If there is no Items chapter, your openHAB system is configured to Simple mode Item linking (See Configuration->System->Item Linking->Simple Mode)
openHAB will automatically create one Item for each channel of each thing, but the name of this item will be … complex. Each item name will contain a uuid. Just take a look at Configuration->Things->Your thing->Channel->Linked Items (the arrows at the very right column)

uhm, where are the arrows at the very right column?:thinking:

Ooops…
openHAB doesn’t show these arrows when in simple mode… sorry.

Please switch simple mode off:

Configuration->System->Item Linking->Simple Mode->OFF

Yeeesss … it worked! At least the first step “switch ON Hue with dash Button”.
unfortunaley the second step “switch on AND OFF Hue with dash Button” failed. Maybe i should go to bed and think about it tomorrow… but here’s (not working) coding for the on/off-switch:

rule "Dash button pressed"
when
    Channel "amazondashbutton:dashbutton:xx-xx-xx-xx-xx-xx:press" triggered
then
    if ( hue_0210_XXXXXXXXXX_4_color.state.toString == "ON") {
        hue_0210_XXXXXXXXXX_4_color.sendCommand(OFF)
        } else {
        hue_0210_XXXXXXXXXX_4_color.sendCommand(ON)
        } end
1 Like

Well, I guess, the state of your hue…color is never “ON”. You can check the states of your items through events.log.

oh, the log-files are no friend of mine. theevents.log in folder /var/log/openhab2 is empty (checked by cat events.log).

And -acutally- i don’t think "color is never “ON” is responsible for this problem:

  • … because i can switch the HUE-bulbs “ON”
    *… and i’ve the coding from hier http://onesmarthome.de/smart-home-openhab-2-dash-button/ … search for “Hier mein Beispiel:”
  • only the “item” ist named “…xxx_4_color”. I think this preconfigured name point out, that i use the mulitcolor bulbs (not the “hue white”-bulbs).

mmmh, i think the “check the log-files” is the next step … Udo (or anyone else): any idea why my events.log is empty? is there an events.log in a other folder or do i have to activate the logging? i’ve checked this: http://docs.openhab.org/administration/logging.html … but with no result - have i failed to see something relevant?

Thanks in advance.
Tom

If you are using the openhabian distro, the you can use the frontail viewer, which is an indispensable tool for development - you may call it in a web browser via:

http://<ip-of-your-installation>:9001/

Since openhabian 1.3 that should be a default component, otherwise you might have to install it via

sudo openhabian-config

Commands and states can be different. Consider sending a Dimmer an ON commannd, this is valid - but the Dimmer’s state goes to 100%.

Please see the table at the top of the Items doc. While an Item can receive a command from any of the Types listed in the right hand column, it internally stores its state only as one of them. In the case of Color it stores its state as an HSBType. An HSBType will never == ON.

This is further explained at the end of the doc here.

See the Conversions section of the Rules Doc for more details on how to convert from various types to other types in Rules.

Finally, there is a little known feature of Items that I fairly recently discovered that lets you get the state of a type as another compatible type. For your HSBType example you can use:

if(hue_0210_XXXXXXXXXX_4_color.getStateAs(OnOffType) == ON)

You can get the state of an Item as any type that you can sendCommand to the Item so to get the brightness of a ColorItem you can use

myColorItem.getStateAs(PercentType)

But you will get a runtime error if you try to get the state as an incompatible type:

myColorItem.getStateAs(DateTimeType)

Puuh, i think i’m not clever enough to understand in detail - so i’ve justed replaced my

with

… but still the same - lights on; but no “off”.

for german language speakers - this was my instructable: http://onesmarthome.de/smart-home-openhab-2-dash-button/

Add some logging. Maybe it thinks the light is ON when you think it should be OFF…

Put the following line before your if statement. Then check openhab.log for what it printed after the rule triggers.

logInfo("lighting", "Hue Light State = " + hue_0210_XXXXXXXXXX_4_color.state.toString + " ON status is " + hue_0210_XXXXXXXXXX_4_color.getStateAs(OnOffType))

Is this the right syntax:

rule "Dash button pressed"
when
    Channel "amazondashbutton:dashbutton:xx-xx-xx-xx-xx-1c:press" triggered
then
    logInfo("lighting", "Hue Light State = "
       + hue_0210_XXXXXXXXXX_4_color.state.toString + " ON status is " + 
       hue_0210_XXXXXXXXXX_4_color.getStateAs(OnOffType))
    if (hue_0210_XXXXXXXXXX_4_color.getStateAs(OnOffType) == "ON") {
        hue_0210_XXXXXXXXXX_4_color.sendCommand(OFF)
        } else {
        hue_0210_XXXXXXXXXX_4_color.sendCommand(ON)
        }
end

… then there ist no loggin information in /var/log/openhab2 (I’ve checked the Files “Openhab.log” and “events.log” by…

cat openhab.log"

respectively

cat events.log

Then either you have an error and your .rules file is not being correctly loaded (should see an error in openhab.log when you save the file) or your rule is not triggering.