General best practices for maintainable rule and item arrangements

I don’t use Dimmers so I don’t really know if the following has any chance of working.

I think you will need to create a proxy Item (i.e. an Item that is not bound to anything) that is a Dimmer. Put this Dimmer on your sitemap using a Slider. Create a rule when this Dimmer receives a command and based on the command received send the message to your controller.

You may be able to do this in the Item itself with a Mapping or something but I don’t have any experience with Dimmers so can’t say for sure.

A Dimmer is also a Switch so you can send it ON and OFF and it will go to 100 and 0 respectively. You can put it on your sitemap as a Switch. You can also add “switchSupport” to the end of your entry on the sitemap and a single click on the up side will send ON and a single click on the down side will send an OFF.

Thank you for the suggestion Rich,

It is working by using the demo rule for slider, I am receiving the percentage values.

Hi ,

Anybody have rule for checking state of battery operated devices…?
i want to know state of battery operated devices like fibaro motion sensors… if battery is removed.

Thanks in advance

If they are zwave and they implement the BATTERY command class, then you just set up an Item on that command:

Number N_V_COSmoke_Main_Battery   "Main Floor Smoke/CO Alarm Battery [%d]" <temperature> (gCOSmoke_Battery, gBattery) {zwave="5:command=battery"}

Not all battery powered zwave devices support the BATTERY command class (e.g Minimotes).

You should be able to tell in Habmin what command classes the device supports I think.

For other technologies I’ll be of no help.

[quote=“rlkoshak, post:12, topic:1316”]Item gLights received update

Unfortunately this causes three triggers…
[/quote]

Hi Rich,

have you ever found a solution for the trigger being raised multiple times?

Is there a way to find out what raised the trigger:
e.g. on

Item xyz received command

if (receivedCommand==ON) {…}

is possible.

Is there anything alike for

Item gLights received update
if …?

There is no solution. This is just the way OH works.

It is a bit of a hack but if you have persistence on the Items in the Group you can:

val mostRecent = gMyGrouo.members.sortBy[lastUpdate].last

Depending on the speed of your database you may need to add a Thread::sleep(100) before that line to give persistence a chance to process the most recent event.

thanks for your quick reply.

I thought so. That is why I asked the 2nd part of my question.

I know your recommendation (lastUpdate) from your previous posts. Works perfect.

I was wondering whether there are additional variables / information I can get in a “receive update” rule. Like I can access the receivedCommand in a “received command” rule.

Do you know where in the sources, documentation or somewhere else I can look this up. Maybe I can dig in a little bit further.

I’ve not looked at the code myself. There was a thread awhile back where someone coded something for OH 1. I don’t think it ever made it into a pull request.

If you are serious about coding something I would head over to the ESH forum as I think anything you code will be implemented there.

But beyond the lastUpdate hack there is no way to determine the triggering item.

This is the way the DSL-Rule Engine works.
I think openhab provides the item,
since the triggering item is available with jsr223 + jython.

@jo47011:
I encourage you to try jsr223.
It makes lots of stuff much easier. :slight_smile:

@rlkoshak: I understand. I am not yet firm enough to provide any real coding help. As of now I am just interested in the code to find undocumented features/options.

I have another question to your last suggestion:

Since I am now using multiple persistence services (thanks to one of your previous posts), which works fine e.g. for .previousState(true,“rdd4j”). I can not figure out how to set the persistence service if it is not the default one for

gMyGroup.members.sortBy[lastUpdate,"rdd4j"] is not working

@Spaceman_Spiff: is it possible to combine existing *.rules files with jsr223 scripts? I am really curious to test an alternative scripting but I already have some quite complex rules which I do not really want (yet) to rewrite. Also as of now the script engine is not (yet) compatible with OH2. Which of course I want to try once it is officially released (out of beta).

Yes - this is no problem. I am running a mixture of Jython rules and DSL rules with openhab 1 without any issues.

For some.

I’ve heard conflicting accounts. Does JSR233 work with OH 2?

Of course this is just my opinion. I was really struggling, switched to jsr223 + jython and now everything is super easy for me. :smile:

As for OH2:
I did ask for an update in the thread, but did not get a response yet.
As far as I know it should be implemented and there are corresponding tickets in the ESH.

@rlkoshak @Spaceman_Spiff Regarding JSR223 in openhab2, I think the relevant PR to follow is this one

Best
Sami