Scripting and rules

Hi there, I’ve been playing with A Rasp PI and a Tasmota flashed chinese GarageDoor opener and as a beginner am struggling with rules etc.
I’m running 2.4 image as everytime I deployed 2.5 it completed the install but had no Paper UI or Basic UI, but that’s not my man query;
I have successfully got the opener working via MQTT 2.4 (which also deletes the binding everytime you restart OpenHab and needs to be added again.) but I’m struggling to make the switch operate as momentary, manual switching works fine.
I’ve created a rule as below but it doesn’t seem to trigger, this rule is in rules directory and I see it successfully load in the logs

when
Item Garage_Door_Status changed from OFF to ON
then
// createTimer(now.plusSeconds(2))
Garage_Door.sendCommand(OFF)
end

==> /var/log/openhab2/openhab.log <==

2020-04-09 01:30:13.408 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model ‘garage.rules’

==> /var/log/openhab2/events.log <==

2020-04-09 01:30:14.693 [ome.event.ItemCommandEvent] - Item ‘mqtt_topic_c80ac941_GarageDoor’ received command OFF

2020-04-09 01:30:14.707 [nt.ItemStatePredictedEvent] - mqtt_topic_c80ac941_GarageDoor predicted to become OFF

2020-04-09 01:30:14.738 [vent.ItemStateChangedEvent] - mqtt_topic_c80ac941_GarageDoor changed from ON to OFF

2020-04-09 01:30:14.862 [vent.ItemStateChangedEvent] - mqtt_topic_c80ac941_Garage_Door_Switch_Status changed from ON to OFF

2020-04-09 01:30:18.879 [ome.event.ItemCommandEvent] - Item ‘mqtt_topic_c80ac941_GarageDoor’ received command ON

2020-04-09 01:30:18.887 [nt.ItemStatePredictedEvent] - mqtt_topic_c80ac941_GarageDoor predicted to become ON

2020-04-09 01:30:18.904 [vent.ItemStateChangedEvent] - mqtt_topic_c80ac941_GarageDoor changed from OFF to ON

Question is the something I need to do to have rules active?

If I understand your logs the item in rules you are trying to trigger on is no the same as showing in the logs.

Item name needs to match.

Thanks heaps, this just got my head in the right space, have now got a nice little script working with a 2 sec delay. For others looking, here’s my code in my .rules file. :

var Timer timer = null

rule “GarageTimer2s”

when
Item mqtt_topic_c80ac941_GarageDoor changed from OFF to ON
then
if (timer === null) {
timer = createTimer(now.plusSeconds(2)) [|
sendCommand(mqtt_topic_c80ac941_GarageDoor, OFF)
]
} else {
timer.reschedule(now.plusSeconds(2))
}
end

Thanks again!!

1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.