[SOLVED] Persisting items that are changed by rules?

I have a Number item that gets changed by a rule (depending on status of another Text item).
My Item is in a persistence group that should get persisted on everyChange (also tried everyUpdate).

I can’t get that configuration to work (tried postUpdate and sendCommand), the only way I found is to call Item.persist in my rule.

Is that working as intended or did I just found a bug?
If that’s working as intended, it would be good to have that written somewhere clearly visible in documentation.

Show your .persist file and the definition of the relevant Groups and Items.

Okay, I made a simpler example and it also doesn’t work there. Here we go:
I want to log ALL4176_Power on every change

persistence/influxdb.persist

Strategies {
	everyMinute : "0 * * * * ?"
	everyHour : "0 0 * * * ?"
	everyDay  : "0 0 0 * * ?"
	default = everyChange
}

Items {
	GP_Persist_Minute* : strategy = everyMinute
	GP_Persist_Hour* : strategy = everyHour
	GP_Persist_Day* : strategy = everyDay
	GP_Persist_Change* : strategy = everyChange
}
items/Group.items

Group GP_Persist_Minute
Group GP_Persist_Hour
Group GP_Persist_Day
Group GP_Persist_Change
items/Network.items

Number:ElectricPotential ALL4176_Voltage   "Voltage [%.2f V]"  <line> { http="<[http://<ipaddres>/xml/json.php?mode=sensor&id=14{Authorization=Basic <username/password>==}:10000:JSONPATH($[0].value)]" }
Number:ElectricCurrent ALL4176_Current   "Current [%.2f A]"  <line> { http="<[http://<ipaddres>/xml/json.php?mode=sensor&id=15{Authorization=Basic <username/password>==}:10000:JSONPATH($[0].value)]" }
Number:Power ALL4176_Power     "Power [%.2f W]"    <line> (GP_Persist_Restore, GP_Persist_Change) // will be calculated by Sensors.rules
rules/Sensors.rules

rule "Update ALL4176 Power value"
when
    Item ALL4176_Voltage changed or
    Item ALL4176_Current changed
then
    ALL4176_Power.postUpdate(ALL4176_Current.state as Number * ALL4176_Voltage.state as Number)
end

Logging shows (DEBUG log level for org.openhab.persistence.influxdb enabled) that there are no values logged, despite the item gets changed:

2018-12-12 08:35:21.101 [vent.ItemStateChangedEvent] - ALL4176_Voltage changed from 226.37 V to 226.7 V
2018-12-12 08:35:21.104 [vent.ItemStateChangedEvent] - ALL4176_Power changed from 33.9555 W to 34.005 W

Group GP_Persist_Minute works as expected, so persistence itself works:

==> /log/openhab2/events.log <==
2018-12-12 08:34:51.025 [vent.ItemStateChangedEvent] - Memory_Used_Percent changed from 57.4 % to 57.0 %
==> /log/openhab2/openhab.log <==
2018-12-12 08:35:00.008 [DEBUG] [.internal.InfluxDBPersistenceService] - got DecimalType value 57.0

Did you restart OH after making changes to your *.persist file?

Erm… no. Didn’t know that was necessary.

Seems like you are right:

==> /log/openhab2/openhab.log <==
2018-12-12 10:49:57.333 [DEBUG] [.internal.InfluxDBPersistenceService] - got DecimalType value 33.9645
==> /log/openhab2/events.log <==
2018-12-12 10:49:57.331 [vent.ItemStateChangedEvent] - ALL4176_Voltage changed from 226.72 V to 226.43 V
2018-12-12 10:49:57.333 [vent.ItemStateChangedEvent] - ALL4176_Power changed from 34.008 W to 33.9645 W

Memory usage also dropped by restarting OpenHAB :slight_smile:

Thank you very much!

It shouldn’t be, but it doesn’t work all the time.
So whenever I change a .persist file, I restart, just in case

Do I also have to restart, when I don’t touch the .persist file, but add another Item to a Group that gets persisted?
I tried to add an item to the hourly persistence group, but it didn’t get persisted.

Afraid so

Okay yeah, it is so. I had one item that got persisted at full hour trigger (that had assigned this one before last restart), the other ones that I added after restart didn’t…

Good to know, hope I remember that next time :wink: