Creating a Rule Action With Timers?

Hi all,

I am still experimenting to see how all this works. Steep learning curve, indeed…

I have items created:

        Switch Schalter_EG_Kueche "Küchenlicht" <light> { channel="enocean:measurementSwitch:FTB3SXG:05194E91:generalSwitchA" }
        Switch Schalter_EG_Vorratsraum "Vorratsraum" <light> { channel="enocean:measurementSwitch:FTB3SXG:05194E91:generalSwitchB" }

Now I have a rule which should trigger when my item changes to “ON”. so I have the followign rule:

rule "Auto-OFF Vorratsraum"
when
        Item Schalter_EG_Vorratsraum changed to ON
then
        Schalter_EG_Kueche.sendCommand(ON)
end

So I want the light in the kitchen (Kueche) to go on at the same time when it goes on in the “Vorratsraum”. thought it might be an easy example. But it is not as I am getting errors im my logfile:

2020-04-25 21:26:01.151 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Auto-OFF Vorratsraum': The name 'Schalter_EG_Kueche' cannot be resolved to an item or type; line 5, column 3, length 18

So is it (again) an item in rules which is not an item from items? Really confusing :unamused:

THanks for any hints here!

/KNEBB

Addion:
I tried to use the sendCommand(Item,Command) instead but got severe error messages (see below)

rule "Auto-OFF Vorratsraum"
when
        Item Schalter_EG_Vorratsraum changed to ON
then
       sendCommand(Schalter_EG_Vorratsraum,ON)
end

But:

2020-04-25 21:38:45.908 [ERROR] [xbase.resource.BatchLinkableResource] - resolution of uriFragment '|::0.2.0.2.0.0::0::/1' failed.
java.lang.NullPointerException: null
        at org.eclipse.smarthome.model.script.ScriptServiceUtil.getActionServices(ScriptServiceUtil.java:111) ~[?:?]
        at org.eclipse.smarthome.model.script.scoping.ActionClassLoader.loadClass(ActionClassLoader.java:37) ~[?:?]
        at java.lang.Class.forName0(Native Method) ~[?:1.8.0_212]
        at java.lang.Class.forName(Class.java:348) ~[?:1.8.0_212]

It might be telling the truth. Did your xxx.items file load successfully after you edited in the new Item? Check in your openhab.log for Loading model 'xxx.items' messages

Hi,

I will not deny it but this happened only once- since them I am getting NullPointer Excceptions whitout usefull error messages. I remember from my issues with sitemaps this happened when ther was not the right “item” used. However, I followed the beginners guide and it is pretty much the same…

So I tried again step-by-step. First, edited the items file to make sure it got read correctly:

Contact Door_Contact "Eingangstuer" <switch> { channel = "enocean:mechanicalHandle:FTB3SXG:FEF70304:contact" }
Switch Net_BackupPC "BackupPC" <network> { channel="network:pingdevice:192_168_9_1:online" }
Switch Schalter_EG_Kueche "Küchenlicht" <light> { channel="enocean:measurementSwitch:FTB3SXG:05194E91:generalSwitchA" }
Switch Schalter_EG_Vorratsraum "Vorratsraum" <light> { channel="enocean:measurementSwitch:FTB3SXG:05194E91:generalSwitchB" }

And yes, no errors:

2020-04-25 22:14:23.751 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'manual.items'
2020-04-25 22:14:24.841 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'manual.items'

Then I created my rules file:

rule "Auto-OFF Vorratsraum"
when
        Item Schalter_EG_Vorratsraum changed to ON
then
        logInfo("KNEBB","Speiseraum ON")
end

Which loaded perfectly fine:

2020-04-25 22:17:57.606 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'speiseraum_timeout.rules'

So I would expect as soon as the state of Schalter_EG_Vorratsraum (for whaever resaon- manual switch or received command) I will see entries in event.log and the configured string in openhab.log.

2020-04-25 22:20:26.271 [ome.event.ItemCommandEvent] - Item 'Schalter_EG_Vorratsraum' received command ON
2020-04-25 22:20:26.316 [nt.ItemStatePredictedEvent] - Schalter_EG_Vorratsraum predicted to become ON
2020-04-25 22:20:26.367 [vent.ItemStateChangedEvent] - Schalter_EG_Vorratsraum changed from OFF to ON
2020-04-25 22:20:27.096 [vent.ItemStateChangedEvent] - enocean_measurementSwitch_FTB3SXG_05194E91_generalSwitchB changed from OFF to ON

Perfect! Events triggered! And I see my log entry:

2020-04-25 22:20:26.567 [INFO ] [eclipse.smarthome.model.script.KNEBB] - Speiseraum ON

Ok, happy! So I assume items and “when” part is absolutely fine. Now trying to change the actions in my rules to send a command to the second channel (on the same thing):
So I change it to the following:

rule "Auto-OFF Vorratsraum"
when
        Item Schalter_EG_Vorratsraum changed to ON
then
        Schalter_EG_Kueche.sendCommand(ON)
end

And boooom I am getting my Java exceptions I can not cope with…

2020-04-25 22:24:09.865 [ERROR] [xbase.resource.BatchLinkableResource] - resolution of uriFragment '|::0.2.0.2.0.0.7.0::0::/1' failed.
java.lang.NullPointerException: null
        at org.eclipse.smarthome.model.script.ScriptServiceUtil.getActionServices(ScriptServiceUtil.java:111) ~[?:?]
        at org.eclipse.smarthome.model.script.scoping.ActionClassLoader.loadClass(ActionClassLoader.java:37) ~[?:?]
        at java.lang.Class.forName0(Native Method) ~[?:1.8.0_212]

So what the heck is wrong here?

I have a similar rule which just works fine. I used the channel instead of the defined item. I might use it here as well but from any documentation it says to use “items”…

rule "Türkontakt Eltako"
when
 Item enocean_mechanicalHandle_FTB3SXG_FEF70304_windowHandleState changed from OPEN to CLOSED
then
        enocean_measurementSwitch_FTB3SXG_05194E91_generalSwitchA.sendCommand(ON)
        logError("KNEBB", "Türe zu!")
end

By using the channel everything works as expected… well, not as expected because I expecte it to use the items and not the channels…

Ok, back to original topic. Now as I use the cahnnel instead of the item at least it works. So now I want to delay the execution of the command for five minutes.

My rules file looks like this: (note: I just added the createTimer line to the working rule):

rule "Auto-OFF Vorratsraum"
when
        Item Schalter_EG_Vorratsraum changed to ON
then
        logInfo("KNEBB","Speiseraum ON")a
       createTimer(now.plusMinutes(1),[ | logInfo("KNEBB", "Timer activated") ])
        enocean_measurementSwitch_FTB3SXG_05194E91_generalSwitchA.sendCommand(ON)
end

And booooom I am getting Java NullPinterExceptions as above!

So what did I do wrong now?

This really pushes me down! So simple changes and no useable error messages… really difficult!

/KNEBB

This -

is NOT a channel. It is an Item.
A channel UID (“name”) looks like enocean:measurementSwitch:FTB3SXG_05194E91:generalSwitchA
(note the colons) and you cannot send commands to a channel, that’s an Items job to do.

So, where did that Item - with a name that looks very much like a channel - come from.
You probably have “Simple mode” set, which auto-creates Items for you, and hides interesting details from you. It’s an abomination, and ruins everone’s day as soon as you progress beyond first “ooh” to actually creating your own Items and first rules.
Use PaperUI to turn it off before you go mad.

Then use PaperUI to hunt down and delete the uselessly/confusingly named Items that it created, that will duplicate what you try to create for yourself, causing confusion.
Late Edit - that advice probably needs amending to remind to delete any channel Links to the unwanted Items, before deleting the Item.

Worry about timers after you have tidied that up.

3 Likes

I just need to tell you that this comment made my day.

2 Likes

Indeedd I had the simple mode on- just as suggested in the beginner’s guide.

I will switch it off, tidy my stuff and see how I am able to proceed.

Thanks!

/KNEBB