How to get persistence recording offline status

I’ve just started using openhab and have also got persistence working fine.

I want to get openHAB recording our lighting usage (Hue lights with manual switches mainly) with the aim of getting openHAB to reply past usage when out/on holiday etc.

The persistence is working fine into MySQL but I’m not seeing a record in the database when the light is switched off i.e. goes offline. Is it possible to get persistence to do this?

I’ve a simple persist file at the moment…

Strategies {
	everyMinute : "0 * * * * ?"
	everyHour   : "0 0 * * * ?"
	everyDay    : "0 0 0 * * ?"
}

Items {
    * : strategy = everyChange, restoreOnStartup
}

Every change except offline appears to be recorded!

Can anyone point me in the right direction please?

Thanks

Archaic

Off is not necessarily the same thing as offline. Offline means that OH cannot communicate with it.

Are you saying that a new record is inserted into the database everytime the light turns ON but not when it is turned OFF?

I don’t know much about the MySQL binding but can say that is incorrect behavior. Your persist file looks correct and as far as I know MySQL is supposed to be able to store Switch states (not all of the DBs do).

Yes, I’m saying that when the hue light is turned on at the switch an entry is made by persistence in the appropriate table in MySQL. However, when the light is turned off at the switch, no entry is made.

I’m storing both the brightness and color_temperature and nothing is stored at the time of the switch off.

Assuming that the MySQL persistence can’t do anything, is there any rule that I could add that would do it for me?

Thanks for your help.

Archaic

Are you turning it ON at the switch too?

One thing to note is the brightness and color_temp may not necessarily change when the bulb turns OFF. I don’t do much with color and know nothing about the Hue but suspect the problem isn’t with MySQL but with the fact that the Items linked to these channels (or bound to the bindings) are not changing when the OFF command is received, or the OFF command from the wall switch is not being received by OH.

Watch events.log to see if all of these Items you care about are changing and/or receiving updates when you toggle the switch.

Yes, turning it on at the switch too.

So, checking the events.log and I can see the light being switch on and off at the switch. Here’s both events…

2017-07-24 22:07:45.584 [hingStatusInfoChangedEvent] - 'hue:0220:00178829dcaf:7' changed from OFFLINE: Bridge reports light as not reachable to ONLINE
2017-07-24 22:35:55.467 [hingStatusInfoChangedEvent] - 'hue:0220:00178829dcaf:7' changed from ONLINE to OFFLINE: Bridge reports light as not reachable

So, the ONLINE records in the log and also via persistence but the OFFLINE doesn’t. Is there anything I can do to rectify this?

Sorry for all the questions, I’m still learning how this all works.

Thanks

Archaic

Can you please elaborate a little more on your setup, i.e. exactly what kind of equipment do you have, when you say “manual switch” what do you mean, etc.?

I may be totally wrong, but it sounds to me like you may have replaced a standard light bulb - with a normal manual switch cutting power to the bulb - with a HUE light, and that you are still using the “good old manual switch”. Is this so?

Thanks Kjetil.

Yes, I have a number of Hue bulbs that have replaced standard bulbs and are, on the whole, used as normal lights with a normal manual switch cutting power.

I wish to use persistence to record the manual switching and then replay the persistence while on holiday etc so simulate presence in the house. I realise that for this to happen I need to ensure that the Hue bulbs are turned on at the switch.

What I haven’t succeeded in doing is getting persistence to record the online/offline that happens with the light’s ‘Thing’.

I thought I had for the Online event but it turns out that this was only if I had previously changed the bulb’s colour, brightness or saturation before a manual switch off. Then, when the bulb was turned on it would default to a standard setup and persistence records the change, not the bulb going online.

A simple switch on at the manual switch followed by a switch off leave no trace in the MySQL persistence.

Hope this makes sense.

OK, this is something else entirely.

For the most part, smart bulbs are designed to and expected to remain powered at all time and to be switched on and off through the Hue app or openHAB. This is a major reason why I opt for smart wall switches over smart light bulbs.

There is no “ONLINE/OFFLINE” state for Switches, Contacts, or any other OH Item and it is the OH Item that gets persisted.Things are not persisted.

The use case you are trying to achieve is not really one supported by OH. However, I beleive in the 2.2 Snapshot version of OH you can trigger a Rule or at least query the ONLINE/OFFLINE status of a Thing from a Rule. You could then use this to update an unbound Item which can then be persisted. You will then need to interpret this switch to send the appropriate command to the bulb when simulating persistence.

Ok, now I get it.

Rich’s and pointers from the others has enabled me to find this post

Customising it for my setup gives me…

rule "Detect Hall Study light Online/Offline"
	when 
		Thing "hue:0220:00178829dcaf:7" changed
	then
		var status = ThingAction.getThingStatusInfo("hue:0220:00178829dcaf:7").getStatus()
		//logError("Debug", "Library Rules | " + status)
		
		if (status.toString() == 'OFFLINE')
		{
			//logError("Debug", "Attempting to turn off light")
			HallStudy_Brightness.sendCommand(OFF)			
		}
		else {
			HallStudy_Brightness.sendCommand(100)
		}
	end

Which works fine as MySQL now shows the persistence that I need.

Thank you to all, it’s now fixed.

All I’ve got to do now is work out why the Hue Bridge keeps going offline, but that’s for another question!

Cheers to all

Archaic