openhab-scripters / openhab-helper-libraries

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

Openhab 3 . Channel Trigger WHEN error / MQTT action #378

Closed mhbosch closed 3 years ago

mhbosch commented 3 years ago

I tried OG3 with Helper library. With 2.5 the WHEN Rule will accept: @rule("Wall Buttons", description="Irgend ein Schalter im Wohnzimmer") @when("Channel mqtt:topic:boschhome:EG_Livingroom_Wallswitch:action triggered")

With 3 (i installed OH3 Helper update, too):

2020-12-28 17:49:36.179 [WARN ] [jsr223.jython.core.triggers         ] - when: "Channel mqtt:topic:boschhome:EG_Livingroom_Wallswitch:action triggered" could not be parsed because 'mqtt:topic:boschhome:EG_Livingroom_Wallswitch:action' is not a trigger Channel

2020-12-28 17:49:36.181 [WARN ] [jsr223.jython.core.rules            ] - rule: not creating rule 'Wall Buttons' due to an invalid trigger definition

But the Channel will be triggered: `2020-12-28 17:52:46.737 [INFO ] [openhab.event.ChannelTriggeredEvent ] - mqtt:topic:boschhome:EG_Livingroom_Wallswitch:action triggered button_5_single


Jython version: 2.7.2.final

Operating system: Linux

OS Version: 5.4.78-2-pve

Java vendor: Azul Systems, Inc.

Java VM name: OpenJDK 64-Bit Server VM

Java runtime name: OpenJDK Runtime Environment

Java runtime version: 11.0.9.1+1-LTS

configuration.py installed: True

sys.path: /etc/openhab/automation/lib/python

                        /var/lib/openhab/cache/org.eclipse.osgi/225/0/bundleFile/Lib

                        __classpath__

                        __pyclasspath__/

mhbosch commented 3 years ago

Hello,

i will try it in the next Year. At the moment i‘m in winter holiday.

mhbosch commented 3 years ago

Hello,

same problem with new source,

2021-01-02 18:47:33.722 [INFO ] [ab.core.service.AbstractWatchService] - Loading script '/etc/openhab/automation/jsr223/python/personal/aqara_wall.py'

2021-01-02 18:47:35.110 [DEBUG] [ipt.internal.ScriptEngineManagerImpl] - Added ScriptEngine for language 'py' with identifier: file:/etc/openhab/automation/jsr223/python/personal/aqara_wall.py

2021-01-02 18:47:37.127 [WARN ] [jsr223.jython.core.triggers         ] - when: "Channel mqtt:topic:boschhome:EG_Livingroom_Wallswitch:action triggered" could not be parsed because 'mqtt:topic:boschhome:EG_Livingroom_Wallswitch:action' is not a trigger Channel

2021-01-02 18:47:37.129 [WARN ] [jsr223.jython.core.rules            ] - rule: not creating rule 'Wall Buttons' due to an invalid trigger definition

It is the definition of Action: Type string : action "Action" [ stateTopic="zigbee2mqtt/Wandschalter", trigger="true", retained=true]

If can change the trigger to an item, but it dont think, it is not the same.

How you have define a trigger and use it in a @when rule?

mhbosch commented 3 years ago

I have comment in the Trigger.py File the lines:

        #elif target_type == "Channel" and things.getChannel(ChannelUID(trigger_target)).kind != ChannelKind.TRIGGER:
        #    raise ValueError(u"when: \"{}\" could not be parsed because '{}' is not a trigger Channel".format(target, trigger_target)) 

With this "old" solution, i can create the Trigger Rule. But this is not best class. How must i define a channel in mqtt for the Helper Library?

I have create this script:

from core.log import logging, LOG_PREFIX
log = logging.getLogger(LOG_PREFIX + ".TEST")
from org.openhab.core.thing import ChannelUID, ThingUID, ThingStatus
from org.openhab.core.thing.type import ChannelKind
log.warn("[{}]".format(things.getChannel(ChannelUID("mqtt:broker:boschhome:EG_Livingroom_Wallswitch")).kind))

Response:

2021-01-03 01:36:38.878 [INFO ] [ab.core.service.AbstractWatchService] - Loading script '/etc/openhab/automation/jsr223/python/personal/test.py'

2021-01-03 01:36:39.545 [DEBUG] [ipt.internal.ScriptEngineManagerImpl] - Added ScriptEngine for language 'py' with identifier: file:/etc/openhab/automation/jsr223/python/personal/test.py

2021-01-03 01:36:39.723 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/etc/openhab/automation/jsr223/python/personal/test.py': AttributeError: 'NoneType' object has no attribute 'kind' in <script> at line number 5

Maybe it will help?!?

CrazyIvan359 commented 3 years ago

I have not had any time to work on this, but it looks like you are doing good tests. I notice in your test script you are looking at the broker and are missing the action, you should change the channel UID to mqtt:topic:boschhome:EG_Livingroom_Wallswitch:action for your test and see what the results are.

Also, looking at your channel thing again I see that you have quotes on the trigger option trigger="true" but none on the retained option retained=true, perhaps removing the quotes will fix the issue?

mhbosch commented 3 years ago

I think, it is my mistake. Under 2.5 the channel can be use as trigger. But it is not really a trigger.