Using Hue ONLINE / OFFLINE Events in rules

hue
rules
things
Tags: #<Tag:0x00007f0142b59060> #<Tag:0x00007f0142b58de0> #<Tag:0x00007f0142b58c28>

(Michael LaFleur) #1

Recent updates (Spring 2017) have allowed using Thing Status Info changes in rules. I was able to use these new features to fix a lighting problem in my Frankenhouse (the light switch only controlled 1 electrical outlet, the others are always on). Using hue lights with the below rules, I now have lights responding to the physical switch (where they weren’t responding before).

Note: that there can be a delay of about a minute between flipping the switch, and having all the lights turn on / off.
Note: You’ll need to pull the thing’s id from Paper UI (or from /userdata/logs/events.log).

rule "Turn on/off Library light"
	when 
		Thing "hue:0210:288baea3:6" changed
	then
		var status = ThingAction.getThingStatusInfo("hue:0210:288baea3:6").getStatus()
		//logError("Debug", "Library Rules | " + status)
		
		if (status.toString() == 'OFFLINE')
		{
			//logError("Debug", "Attempting to turn off light")
			Library1_Brightness.sendCommand(OFF)			
		}
		else {
			Library1_Brightness.sendCommand(ON)
		}
	end		

Determine light offline/online state?
Detecting offline Things
ZWave & dead nodes identifying in openHAB2
How to get persistence recording offline status
Openhab 2 & Kodi
Tradfri Bulb Status
HttpBinding time-related?
Using Hue lamps with no power when turned off
[SOLVED] How to get event from thing (LIFX light
Zwave battery device status
Detect offline zwave thing (the moment it actually gets offline)
Item state HUE lamp with traditional wall switch
Put Thing Status in an Item
About REST using
(SiHui) #2

Further reference: https://github.com/eclipse/smarthome/pull/3001


(Michael LaFleur) #3

Thanks.


(Dan) #4

that is awesome - thank you.

Is it possible to use this approach to check all the Things for any that are offline, without having to list them individually?

Dan


(Thomas) #5

The Thing status is detected but it is not working all the time :frowning:

In the stable OH version I was able yo follow the Online/Offline status in the Thing section and it worked very responsive … doing the same now in the latest Snapshot I have delays in the Online/Offline status in the Thing section.

Its a step in the right direction but not working reliable :wink:

Anybody with similar experience ?


(SiLeX) #6

I am using this with my Z-Wave bulb and here the Thing is only going OFFLINE if the gateway tries to contact the bulb but it didn’t answer within 10 seconds.

If I don’t send any commands at all to the bulb after cutting the power, it stays ONLINE until the gateway tries to pull a status from it (which is every 10 minutes in my setup). So this is very expected and correct behaviour IMHO.

I have a dimmable Z-Wave bulb in a simple relay-microwave-lamp, so it will cut the power when there is nobody in the room. I use the ONLINE OFFLINE state to detect presence in that room and power on/off the wall panels.


(Michael LaFleur) #7

I haven’t looked into that use case at all. If there is a way to get all of your thing’s ids then I suppose you could do it in a loop. Note that I’m still relatively new to openHab, and am hacking my way through problems as I run into them.


(Michael LaFleur) #8

There is definitely a delay between the online/offline switch, and the responsiveness of the rule. In my brief testing I’ve seen it take up to 1 minute before the second light responds … which was good enough for my purposes.


(Markus Kräckmann) #9

Hi there,

not sure if it’s the right place to post this question, but I can’t get this to work.

The rule is triggered whenever the Thing status changes, which if fine, however as soon as I try to read the status via

var status = ThingAction.getThingStatusInfo(...)

it results in a null reference error…

Is there anything I need to import?

I tried several import statements but the Designer rejects all of them.

Any help is appreciated!

Thanks!


(Mao) #10

One reason why it’s null is because the thing got removed. Thus it doesn’t exist and there is not status.


(Christoph Weitkamp) #11

Hi Markus,

I am not sure if you have to prepend the ThingAction part in front of the getThingStatusInfo(...) method call. The documentation doesn’t use it (see http://docs.openhab.org/addons/actions.html#thing-status-action). It is also recommended to check for null on the getThingStatusInfo(...) result before trying to access the real status value.