Aqara button refreshing after Loading model 'default.items'


I have a problem with my button. It refreshing it’s state after every change in item files.
I’m checking button status with trigger:

Item Button received update

and I’m getting

2023-01-04 21:09:30.476 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model ‘default.items’
2023-01-04 21:09:30.654 [INFO ] [script.Button] - Button status: single

Button removed from mapdb persistence.
Configured with zigbee module and mosquitto:

String Button { channel=“mqtt:topic:home:aaaa:action”}

Is it a proper behavior for this button? Can I stop it?

All items in an items file are updated whenever it’s saved. Do you save the file often enough that it’s an issue? If so, your options are:

  1. Create a separate file for that item, so that it doesn’t get updated when you save default.items.
  2. Change the trigger in your rule so that it doesn’t fire on every update. I don’t know how you’re using it, but “received command” or “changed” is typically sufficient for most purposes.

I’ve also tried to use it with ‘expire’ and update the state to UNDEF, but after item refresh it somehow backs to ‘single’ state and trigger with ‘changed’ my light.
In the beginning I suspected mapdb, but when I disabled it doesn’t help.

So you’ve installed MapDB and are using that. Did you remove rrd4j? If not did you create an rrd4j.persist file so that this Item is not saved and restored on startup also? By default, without a .persist file to tell it otherwise, most persistence add-ons will save all Items on every change and restoreOnStartup.

rrd4j still exists, but has it’s own rrd4j.persist file with specific ‘Items’ defined. There is no mentioned button and defined strategy is:

strategy = everyMinute, everyChange

I don’t want to use another file with items - I need to prevent such situation when openhab will be restarted.

I came across this issue. My solution is to update the button to an empty string, and return from the rule if it’s updated to an empty string.

As @rpwong mentioned, in the majority of cases triggering on change instead of update will do just fine and prevents the item update event from being fired when saving the items file.

Just using change trigger isn’t going to work.
When you pressed the button, it updates it with the value ‘single’ and when you pressed it again, it will update it again with ‘single’. No state changes there so you’ll miss the second and all subsequent press events.

I was trying to use your approach with empty string, I was updating it with expire=“1s,state=UNDEF” and it doesn’t help - when items file is saved od OH restarted it refreshes to ‘single’ value somehow and turns my light on…

Yup came across that problem too.
I set a dummy command topic on mqtt, then also send a command out.

Is your state topic retained by zigbee2mqtt? If it is, that could be another source of the problem.

It seems yes - there is action: N/A after expiry, so should be fine.
If you’re asking if any changes happens on zigbe2mqtt level when I’m saving items - no, I didn’t noticed any changes in logs. I just see reaction in openhab.

I use “received command” for this scenario.

Mqtt only updates state… But wait… I’ve just reread mqtt docs, it has a postCommand option! Thanks @rpwong I’ve learnt something new!

1 Like

What do you mean postCommand? How to use it? When I change trigger to ‘received command’ it’s not working.

In your mqtt thing channel config, set postCommand to true

Pure coincidence. I’ve never used “received command” with an MQTT item, so I didn’t realize that would be an issue until you pointed out that it’s not. :wink:

I’ve now reconfigured all my mqtt based buttons to postCommand and it works beautifully so far. It simplifies things, now I no longer have to update the item to blank to detect changes. Thanks again! I love it when a better solution comes along!

1 Like

yeah… I’m still testing but it seems it’s finally working !! Great, thanks for help !