[SOLVED] Rules dont seem to be triggered

All,

i have been reading a lot on rules, but as much as i seem to be having things in place, the rule dont seem to be triggered and i cant seem to figure out why.

i am using the following files:

home.items

//teksten voor meldingen van schakelaars
String VERLICHTING_KEUKEN_SCHAKELAAR_STRING "Melding schakelaar keuken [%s]"
    { mqtt="<[broker:verlichting/keuken_schakelaar/cmnd/POWER:state:default]" }

String VERLICHTING_KEUKEN_SCHAKELAAR_STRING2 "retour Melding script keuken [%s]"
//    { mqtt="<[broker:verlichting/keuken_schakelaar_retour/cmnd/POWER:state:de$

home.sitemap

            Text item=VERLICHTING_KEUKEN_SCHAKELAAR_STRING
            Text item=VERLICHTING_KEUKEN_SCHAKELAAR_STRING2

home.rules

//schakelen verlichting keuken met dummy signaal schakelaar.
rule "verlichting_keuken"
when
    Item VERLICHTING_KEUKEN_SCHAKELAAR_STRING received command

then
    logInfo("Keuken verlicthing rule")
    logInfo("Waarde keuken: " + VERL_KEUKEN.state)

        VERLICHTING_KEUKEN_SCHAKELAAR_STRING2.sendCommand("oops")
    if (VERL_KEUKEN.state == ON) {
        VERLICHTING_KEUKEN_SCHAKELAAR_STRING2.sendCommand("Uit gedaan")
     }
    else {
        VERLICHTING_KEUKEN_SCHAKELAAR_STRING2.sendCommand("Aan gedaan")
    }
end

What does and what does not happen.
when the mqtt message comes in, i can see that VERLICHTING_KEUKEN_SCHAKELAAR_STRING recieves the value from mqtt. but VERLICHTING_KEUKEN_SCHAKELAAR_STRING2 does not update.

when i check the logging i can see the updates to VERLICHTING_KEUKEN_SCHAKELAAR_STRING, but there is no meantion that any rules was triggerd nor any errors.

so at the moment i am kind of clueless where i am going wrong.

I think that the problem is that the string doesnā€™t receive a command, but an update from the MQTT broker.
So if you change the when part from received command to received update, it should work.

3 Likes

This is the MQTTv1 binding.
Your item syntax is correct and you say that the item value is updated. Binding works, confirmed.
As @ljsquare mentionned, the binding UPDATES the item value.

Change the rule trigger to received update and it should work as you expect.

To simplify, an item receives a command when:

  • explicitely done in the rule
  • a widget on an UI
  • in some binding (specific configuration to pass an update as a command)

And an item receives an update:

  • explicitely in the rules
  • through the binding (a sensor value has changedā€¦)

To simplifiy even more:
command are used to send an instruction OUT to a deviceā€¦
updates are generated by a device sending infomation IN

Hope this helps

3 Likes

Thanks for the replies. The explinations makes sense.
i changed the code now to ā€˜received updateā€™, however i still dont see a result.

just to be sure, when i save the rules file, i dont need to trigger anything else right? meaning the changes are imidiately taken into effect?

i checked the logging and i can see the switches, but no feedback from the rule.

2019-09-02 19:52:41.202 [ome.event.ItemCommandEvent] - Item
'VERL_KEUKEN_SCHAKELAAR' received command ON
2019-09-02 19:52:41.230 [vent.ItemStateChangedEvent] -
VERL_KEUKEN_SCHAKELAAR changed from OFF to ON
2019-09-02 19:52:41.241 [vent.ItemStateChangedEvent] -
VERLICHTING_KEUKEN_SCHAKELAAR_STRING changed from OFF to ON
2019-09-02 19:52:41.954 [ome.event.ItemCommandEvent] - Item
'VERL_KEUKEN_SCHAKELAAR' received command OFF
2019-09-02 19:52:41.979 [vent.ItemStateChangedEvent] -
VERL_KEUKEN_SCHAKELAAR changed from ON to OFF
2019-09-02 19:52:41.982 [vent.ItemStateChangedEvent] -
VERLICHTING_KEUKEN_SCHAKELAAR_STRING changed from ON to OFF
2019-09-02 19:52:42.688 [ome.event.ItemCommandEvent] - Item
'VERL_KEUKEN_SCHAKELAAR' received command ON
2019-09-02 19:52:42.730 [vent.ItemStateChangedEvent] -
VERL_KEUKEN_SCHAKELAAR changed from OFF to ON
2019-09-02 19:52:42.734 [vent.ItemStateChangedEvent] -
VERLICHTING_KEUKEN_SCHAKELAAR_STRING changed from OFF to ON
2019-09-02 19:52:43.847 [ome.event.ItemCommandEvent] - Item
'VERL_KEUKEN_SCHAKELAAR' received command OFF
2019-09-02 19:52:43.871 [vent.ItemStateChangedEvent] -
VERL_KEUKEN_SCHAKELAAR changed from ON to OFF
2019-09-02 19:52:43.883 [vent.ItemStateChangedEvent] -
VERLICHTING_KEUKEN_SCHAKELAAR_STRING changed from ON to OFF
2019-09-02 19:52:44.743 [ome.event.ItemCommandEvent] - Item
'VERL_KEUKEN_SCHAKELAAR' received command ON
2019-09-02 19:52:44.763 [vent.ItemStateChangedEvent] -
VERL_KEUKEN_SCHAKELAAR changed from OFF to ON
2019-09-02 19:52:44.767 [vent.ItemStateChangedEvent] -
VERLICHTING_KEUKEN_SCHAKELAAR_STRING changed from OFF to ON
2019-09-02 19:52:45.317 [ome.event.ItemCommandEvent] - Item
'VERL_KEUKEN_SCHAKELAAR' received command OFF
2019-09-02 19:52:45.326 [vent.ItemStateChangedEvent] -
VERL_KEUKEN_SCHAKELAAR changed from ON to OFF
2019-09-02 19:52:45.340 [vent.ItemStateChangedEvent] -
VERLICHTING_KEUKEN_SCHAKELAAR_STRING changed from ON to OFF

The code now looks like this:

//schakelen verlichting keuken met dummy signaal schakelaar.
rule "verlichting_keuken"
when
    Item VERLICHTING_KEUKEN_SCHAKELAAR_STRING received update
then
    logInfo("Keuken verlicthing rule")
    logInfo("Waarde keuken: " + VERL_KEUKEN.state)

        VERLICHTING_KEUKEN_SCHAKELAAR_STRING2.sendCommand("oops")


    if (VERL_KEUKEN.state == ON) {
        VERLICHTING_KEUKEN_SCHAKELAAR_STRING2.sendCommand("Uit gedaan")
     }
    else {
        VERLICHTING_KEUKEN_SCHAKELAAR_STRING2.sendCommand("Aan gedaan")
    }
end

correct

1 Like

It doesnā€™t work because the item according to the log receives a command. Not an update.
What sends that command?

1 Like

You can be sure and look in openhab.log for a ā€œxxx.rules file loadedā€ message (and any syntax complaints).

This is a syntax error. logInfo requires two string parameters
logInfo("myRule", "Keuken verlicthing rule")

1 Like

ow shoot, now i seeā€¦ i overlooked a couple of things.

  • i was checking the wrong loggingā€¦ meaning i did not see the errors from the compiling.
  • i was using the wrong syntax of loginfo
  • i was checking in my if statement for a command while a string has a string value in itā€¦ (duh).

but thanks to all the help i managed to fix the code.
the final (and working) code looks like this

//schakelen verlichting keuken met dummy signaal schakelaar.
rule "verlichting_keuken"
when
    Item VERLICHTING_KEUKEN_SCHAKELAAR_STRING received update

then
    logInfo("home.rules","Keuken verlicthing rule")
    logInfo("home.rules","Waarde keuken: " + VERL_KEUKEN.state)
    logInfo("home.rules","Waarde keuken string 1: " + VERLICHTING_KEUKEN_SCHAKELAAR_STRING.state)

    if (VERLICHTING_KEUKEN_SCHAKELAAR_STRING.state == "OFF") {
        VERLICHTING_KEUKEN_SCHAKELAAR_STRING2.sendCommand("Uit gedaan")
     }
    else {
        VERLICHTING_KEUKEN_SCHAKELAAR_STRING2.sendCommand("Aan gedaan")
    }
end

3 Likes

Great job!
Change your thread title to start with [SOLVED] and be sure to check the little box in the post that helped you solve your issue

2 Likes