[SOLVED] How to get event from thing (LIFX light

Hi

I would like to know if the lamp is online / offline. Is there a way to get the following event to an item?

2018-10-21 10:37:47.373 [hingStatusInfoChangedEvent] - 'lifx:colorlight:D073D512DF32' changed from OFFLINE (COMMUNICATION_ERROR) to ONLINE

There is an option to check the thing status (Using Hue ONLINE / OFFLINE Events in rules) but this means I have to run it periodically.

Thx

It depends on the binding. Some have it implemented others don’t

After more searching I’ve found that I can use Thing trigger in a rule. I can use it to send status to an Item. Still be nice if there is an option to send status directly to an item and not via rule (I assume that this depends on the binding as @vzorglub wrote).

I use the option you linked to for my LifX lamps. It works fine and doesn’t seem to affect overall system performance.

That being said it wold be great to not have a rule/s for something that seems so closely baked in.

You can post a feature request on gitHub if you like
The easiest thing would be to add an online switch channel to the item…

Yep, probably I will add request to LIFX binding to add online channel (@vzorglub if that what you mean)

Seems that I have issues with the rule. getThingStatusInfo doesn’t work for me (openHAB 2.3.0-1 (Release Build))

  var thingStatusInfo
  thingStatusInfo = getThingStatusInfo("lifx:colorlight:D073D512DF32")
  if ((thingStatusInfo != null) && (thingStatusInfo.getStatus().toString() == "ONLINE")) {
    Lifx_Online.postUpdate(ON)
  } else {
    Lifx_Online.postUpdate(OFF)
  } 

This cause error:

Rule 'Lifx status': Unknown variable or command '!='; line 28, column 8, length 23

Something simple that I am missing :frowning:

Thx

Try:

 var thingStatusInfo = getThingStatusInfo("lifx:colorlight:D073D512DF32") 

And you need to use !== to check for null

@vzorglub

yes,I’ve used !== but i changed it ot != after I saw the error … In any case, I will try your suggestion and update

Yes, this did the trick. The var needed a type …

Thx

Cool, please tick the solution, thanks

I have successfully implemented a rule where I can get a proxy switch to trigger based on the thing status. My challenge is I want the LIFX color item to be set to OFF when the thing is detected as OFFLINE. Seems when it is OFFLINE, sending it a command or update results in an error

2018-12-05 01:07:47.949 [WARN ] [.lifx.internal.LifxLightStateChanger] - SetLightPowerRequest failed (unacknowledged 4 times)
2018-12-05 01:08:05.764 [WARN ] [.lifx.internal.LifxLightStateChanger] - SetColorRequest failed (unacknowledged 4 times)

A postUpdate should work.
Post your code, please

yes but its really the same result as the IOS GUI - color item is not responsive and cant be turned off when device is offline

rule "lifx Jackson online"
when
  Thing "lifx:colorlight:D073D5203016" changed 
then
 var thingStatusInfo = getThingStatusInfo("lifx:colorlight:D073D5203016")
  if ((thingStatusInfo !== null) && (thingStatusInfo.getStatus().toString() == "ONLINE")) {
    Lifx_JC_Online.postUpdate(ON)
  } else {
    Lifx_JC_Online.postUpdate(OFF)
    Lifx_JC.sendCommand(OFF)
  }
end 

items

Color      Lifx_JC   "LIFX Jackson"  {channel="lifx:colorlight:D073D5203016:color"
Switch      Switch_Lifx_JC   "LIFX Jackson" {channel="lifx:colorlight:D073D5203016:color"}
Switch      Lifx_JC_Online

You can turn the item off. But not the light itself of course, because it is offline. OH can’t reach it.
Your code makes sense, it’s just that Lifx_JC.sendCommand(OFF) will never work if the thing if offline.

Lifx_JC.postUpdate(OFF)

Will turn off the item in OH. But not the light itself.

OK postUpdate works - I did try this but perhaps I tried it on the switch item not the color item. Thanks for your help.