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.
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.
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
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