[SOLVED] Persistence - from ON to UNDEF

sonoff.things

    Thing topic sonoff-basic "sonoff-basic" {
		Channels:
			Type switch : PowerSwitch [ stateTopic="stat/sonoff-basic/POWER", commandTopic="cmnd/sonoff-basic/POWER" ]
    }	

sonoff.items

Switch Sonoff { channel="mqtt:topic:MQTTBroker:sonoff-basic:PowerSwitch" }

jdbc.persist

// persistence strategies have a name and definition and are referred to in the "Items" section
Strategies {
	everyHour : "0 0 * * * ?"
	everyDay  : "0 0 0 * * ?"

	// if no strategy is specified for an Item entry below, the default list will be used
	default = everyChange
}

/*
 * Each line in this section defines for which Item(s) which strategy(ies) should be applied.
 * You can list single items, use "*" for all items or "groupitem*" for all members of a group
 * Item (excl. the group Item itself).
 */
Items {
	// persist all items once a day and on every change and restore them from the db at startup
	Sonoff : strategy = everyChange, restoreOnStartup
}

events.log

I powered Sonoff ON
2019-10-23 13:28:18.674 [vent.ItemStateChangedEvent] - Sonoff changed from OFF to ON

I restarted OH
2019-10-23 13:33:46.378 [temChannelLinkRemovedEvent] - Link 'Sonoff => mqtt:topic:MQTTBroker:sonoff-basic:PowerSwitch' has been removed.

OH started. Persistence seems to work
2019-10-23 13:34:20.712 [vent.ItemStateChangedEvent] - Sonoff changed from NULL to ON

But (i think) OH reads state from MQTT Broker
2019-10-23 13:34:22.486 [vent.ItemStateChangedEvent] - Sonoff changed from ON to UNDEF

Why?

discussed several times. It’s mqtt binding feature (I and some think it’s wrong, others thinks it’s ok).
you have to use retained messages to be OH able to restore it’s state after restart.

persistence simply does not work on mqtt items for now

Can I make a rule that restores last saved value at startup?

1 Like