Automatic sending of events

Hey , i wanted to know if there is a possibility to automatically send item name and the items new state on change.

I m trying to export all these Data for external use such as Data-analytics.

Kind regards

Most of the persistence-services in openHAB do just that. Take a look at influxdb, if you set it up with everyChange it will log all item changes with item name, value and time. You can then query the database from another application using a REST API.

Thanks for the fast reply,
this solutions seems to me like adding some extra steps,
do you maybe know if i can catch item events via rules ?

kind regards

I guess you could, but that would be even more steps, and rather complicated ones too. The persistence services are there for a reason…

You could perhaps use somthing like:

But that also reqires a persistence service set up.

If you don’t want that I beleive the only way is to write a separate rule for every single item

rule "Save state of [item name]"
        Item [item name] changed
        //Code to save the values to where you want

As I said, persistence exists for a reason.

One of the openHAB gurus like @rlkoshak maybe knows another way, but since persistence is used for exactly this, I don’t think anyone has bothered finding one.

thank you for your insight :slight_smile:

following this Topic would it be possible to get the name&State of the member that last changed ?
@pacive @rlkoshak

Yes, but the gMyGroup.members.sortBy[lastUpdate].last requires a persistence service for the lastUpdate property, otherwise openHAB has no way of knowing when an item was updated.

If you want to do data analytics, how do you collect the data? If using (My-)SQL you get Name and Value whenever an item gets persisted in a sql database (one table each item), you could even use logging persistence (when on openHAB1) and simply get a text file with the format

timestamp - itemname - state

it’s very easy to configure persistence.

@pacive now i understand why the persistence you recommended seems like the easiest way

@Udo_Hartmann using (my-)sql persistence, does every item get their own table automatically?
Im on OH2

Thanks for the help :slight_smile:

Glad to help, good luck getting eferything together! :smiley:

another last question if i got the


how do i get the name and status, since i expect it to be a list(i guessed here from the sortBy)

gMyGroup.members.sortBy[lastUpdate].last returns an Item object, so you can use:

val item = gMyGroup.members.sortBy[lastUpdate].last
val itemName =
val itemState = item.state
val itemUpdated = item.lastUpdate

If you use Eclipse SmartHome Designer to write your rules you can press <ctrl>+<space> to get a list of all available methods for an object.

As already discussed, the easiest way will be to use Persistence using one of the external databases like InfluxDB, Mongo, or MySQL.

Second easiest would be to use the MQTT EventBus which will publish all updates to all Items to MQTT Topics. Then you would write a script or program to subscribe to those updates and save them to the database of your choice. This means you have to write the DB stuff yourself.

Third easiest would be to use JSR223 Rules and implement something in Jython/JavaScript/Groovy. That will give you a little better access to determine what Item triggered a Rule that doesn’t depend on you already having set up Persistence or writing a separate Rule for each Item. Again, this would require writing all the DB stuff yourself AND setting up, configuring, and learning JSR223.

There really is no way to do anything in Rules that will be reliable and that doesn’t already require Persistence to be set up.

Yes. Unfortunately, while Persistence is the correct tool for this job, you have little to no ability to customize how the database gets structured. The typical approach is to have one table per Item. The Tables always get created automatically by the persistence engine. If you change the Type of an Item (e.g. go from a String to a Number) you will have to manually drop the table so OH can recreate it with the new datatype.

It is a List but then we get the last Item in the list. The List is a List<Item> or List<GenericItem>.


While this is totally true, I think, this is not really a downer, as one could build queries or stored procedures at sql-side to get the data restructured :slight_smile: