How to sendCommand to OFFLINE thing? How to force that?

Hello,

my platform OH 4.1.2 on Windows 11 platform.

I have the light sensor which is very unstable (freezing), so I’m checking status of this thing. If the status of this thing is OFFLINE, I would like to sendCommand(0) to channel with lux value to reset previous value.

So my question is - is there possible to sendCommand(0) when the thing is OFFLINE? How to do that?

Can you help me?

You can send a command to any Item any time you want. Whether the Thing the Item is linked to is ONLINE or OFFLINE or even if the Item is linked to multiple Things or no Things at all. You dno’t have to force anything, just sendCommand(0) from a rule.

But if the Thing is OFFLINE then nothing will come of it. A command is sent to an Item to cause a device to do something and if the Thing is OFFLINE, there is no way for OH to communicate with the device.

But this is an XY Problem. You don’t want to send a command to this Item anyway under any circumstances. This Item is a sensor, you never want to send a command to this or any other sensor Item. What you want to do is postUpdate. Posting an update to an Item just changes the state of the Item inside of OH. An update never goes to the binding and out to the end device.

So to reset an Item, just postUpdate(0) instead of sendCommand(0). If you need help with rules, please see the Getting Started Tutorial’s Rules section to start.

Though even that isn’t necessarily the best approach. For one thing, if you can’t really know what state the sensor is in NULL or UNDEF are probably better choices over 0. Those clearly indicate that the Item is in an unusable state. The second thing is you could set expire metadata on the Item to reset the Item to NULL, UNDEF or 0 when the Item doesn’t receive an update for too long of a time. In that case you don’t even need a rule, the Item will jsut timeout and reset on it’s own.

1 Like

Maybe I’m missing something, but you can trigger a rule when the thing goes OFFLINE, and then execute a rule (via Blockly) that sends the value.

@rlkoshak - my Master of OH! :slight_smile: Thank you so much for your reply!

I use the light sensor to periodically check (every 5 min) if the kids have left the lights on and the lux value > 7, then turn off the lights. In this case, if the light sensor “hung up” then I had an outdated lux value (e.g. 15 lux), so I periodically check every 5 min to see if it is working, and if not, I wanted to set the lux value to 0 for the item.

The expire metadata thread you wrote about is very interesting. Can you elaborate on it or provide a link so I can read more about how it can be applied in practice?

1 Like

Another option would be to do everything in a rule.

In a .rules file:

rule TestRule
when Thing "zwave:device:39d51d11b2:node46" changed from ONLINE
then postUpdate(GarageHumidity,0)
end 

Or in the Rules UI:

configuration: {}
triggers:
  - id: "1"
    configuration:
      thingUID: zwave:device:39d51d11b2:node46
      previousStatus: ONLINE
    type: core.ThingStatusChangeTrigger
conditions: []
actions:
  - id: "2"
    configuration:
      itemName: GarageHumidity
      state: "0"
    type: core.ItemStateUpdateAction

Now that I think about it, I’m not sure that expire is in the docs. But it’s very straight forward. In MainUI navigate to Settings → Item → YourItem and under “metadata” click “Add Metadata” and choose “Expiration Timer”. The form should be pretty self explanatory.

For something a little more involved, see Design Patterns: Generic Is Alive.

Great, thank you for the information. I need to explore this part of OH further :slight_smile: