openhab-scripters / openhab-helper-libraries

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

WHEN Trigger for Things #379

Open mhbosch opened 3 years ago

mhbosch commented 3 years ago

Hello,

it is possible to add a When Trigger for Things? With the DSL Rule, i can observe a thing, with Jython i dont have a trigger for things.

My example for DSL:

rule "Gerät gestört"
when 
 Thing 'homematic:HM-LC-Sw4-DR:PEQ0172029:KEQ0055288' changed from ONLINE to OFFLINE
 then
 logInfo("Heizung", "Die Heizungskontrolle kann nicht erreicht werden")
   sendTelegram("bot1", "Die Heizungskontrolle kann nicht erreicht werden")
end

rule "Gerät gestört"
when 
 Thing 'homematic:HM-LC-Sw4-DR:PEQ0172029:KEQ0055288' changed from OFFLINE to ONLINE
 then
 logInfo("Heizung", "Die Heizungskontrolle kann wieder erreicht werden")
   sendTelegram("bot1", "Die Heizungskontrolle kann wieder erreicht werden")
end
CrazyIvan359 commented 3 years ago

It is possible, there is an example in the docstring for when:

https://github.com/openhab-scripters/openhab-helper-libraries/blob/03038de498f70e6fa46d2a1457c38c8a4902c4e5/Core/automation/lib/python/core/triggers.py#L62

mhbosch commented 3 years ago

Hello,

thanks. I have seen, the string for the Thing was changed with OH3. Now i tried it a sceond time with the other String and it will works!

mhbosch commented 3 years ago

Hello,

im again.

The Trigger dont have a action.

My Trigger:

@rule("Heizungskontrolle", description="Aenderung bei der Heizungskontrolle", tags=["Script", "Telegram"])
@when("Thing homematic:HM-LC-Sw4-DR:3014F711A061A7D8A98C07FD:KEQ0055288 changed")
def heizungskontrolle(event):
    LogAction.logInfo(u"Heiungskontrolle", "" + ir.getItem(str(event.itemName)).label + " wurde von " + str(event.oldItemState) + " auf " + str(event.itemState) + "geändert")
    actions.get("telegram", "telegram:telegramBot:Telegram_Bot").sendTelegram( ir.getItem(str(event.itemName)).label + " wurde von " + str(event.oldItemState) + " auf " + str(event.itemState) + "geändert")

The Log shows, the Trigger was accepted: 2021-01-08 11:09:45.109 [DEBUG] [jsr223.jython.core.triggers ] - when: target: 'Thing homematic:HM-LC-Sw4-DR:3014F711A061A7D8A98C07FD:KEQ0055288 changed', target_type: 'Thing', trigger_target: 'homematic:HM-LC-Sw4-DR:3014F711A061A7D8A98C07FD:KEQ0055288', trigger_type: 'changed', old_state: 'None', new_state: 'None'

When i have a change, the trigger dont work: LOG: Thing 'homematic:HM-LC-Sw4-DR:3014F711A061A7D8A98C07FD:KEQ0055288' changed from OFFLINE (COMMUNICATION_ERROR) to ONLINE

But no error from script or active trigger.

mhbosch commented 3 years ago

Hello,

thats sound great. It there a Update Script for the library? I think, i miss updates.

CrazyIvan359 commented 3 years ago

No, there isn't one. Did you use the manual installation instructions and are you running OH3?

mhbosch commented 3 years ago

Yes, OH3.

I hope, in near future, there is a script, who inform about updates and a update script,

mhbosch commented 3 years ago

OK,

thanks, i will try it.