openhab-scripters / openhab-helper-libraries

Scripts and modules for use with openHAB
Eclipse Public License 1.0
88 stars 70 forks source link

OPEN/CLOSED Types doesn't work? #78

Closed NicoFilips closed 5 years ago

NicoFilips commented 5 years ago

So I'm currently rewriting the Xioami smarthome .rules pattern into Jython: https://www.openhab.org/addons/bindings/mihome/ Cubes, Motion Sensor etc are working great so far and I will contribute it to the .README if every rules working out. But I've noticed that the Contact items are not supported or am I wrong? Code:

#Door Sensor #1 Heizungskeller
@rule("Xiaomi Door/Window Sensor Heizungskeller")
@when("Item Door_Openstatus1 received command OPEN")
@when("Item Door_lastopened1 changed")
@when("Item Door_Openstatus1 changed from CLOSED to OPEN")
def heizungskellerLicht(event):
    x = int(items["gMotionOffset"])
    logXC.info("Licht im Heizungskeller: angeschalten, wird in "+str(x)+" Minuten ausgeschalten.")
    sendCommand(items["Yeelights_3"], "ON")
    windowTimer= Timer(x, lambda: events.sendCommand("Yeelights_3","OFF"))

Exception:

2019-01-31 20:48:47.299 [ERROR] [me.automation.jsr223.jython.triggers] - when: Exception [when: "Item Door_Openstatus1 received command OPEN" could not be parsed because "OPEN" is not a valid command for "Door_Openstatus1"]: [Traceback (most recent call last):

  File "/etc/openhab2/automation/lib/python/core/triggers.py", line 309, in when

    raise ValueError("when: \"{}\" could not be parsed because \"{}\" is not a valid command for \"{}\"".format(target, new_state, trigger_target))

ValueError: when: "Item Door_Openstatus1 received command OPEN" could not be parsed because "OPEN" is not a valid command for "Door_Openstatus1"

]

Am I missing something here? Of course, I could just use the Door_lastopened1 item, but I want to use the full functionalites of the core features! Thanks alot in advantage

5iver commented 5 years ago

I'm looking into this...

5iver commented 5 years ago

I should have looked at your post better! The only command a contact can receive is REFRESH. This is the only acceptedCommandType, so there is an error in the Trigger creation. Nothing broken here, except in your rule definition!