How to get device connection state in rules?

Hello,

How to get device connection state in rules?
This need for sending telegram messages if device connection state changed.

There are, of course a few ways. You can use thing status changes as rule triggers and set a proxy-item state accordingly: when Thing XXXXX changed. See the thing-based triggers in the rules docs:

You can then use the state of your proxy-item easily in other rules. For most of my use cases I find this to be effective because I also want to be able to see the status of the thing in a sitemap and using the proxy-item or group of proxy-items is a very efficient way of doing that.

If you’re using the jsr223 next gen rules then there are some very handy direct interaction methods in the core thing library:

https://openhab-scripters.github.io/openhab-helper-libraries/Guides/But%20How%20Do%20I.html#get-thing-status

Forgive, please, for the incomplete explanation of my message.
I need to get the status of the connection of a device based on the Andoid operating system to the OpenHub server to fulfill the condition: if the device is not connected, send a message to telegram

OK, then I’m still not entirely sure what you are looking for.

Do you want to be able to detect if an android device is connected to the same network as openhab?

Do you want to be able to detect if an android device is communicating with the openhab server through the openhab android app?

Do you want to be able to detect if an android device has any active network connection at all (wi-fi or cellular)?

i want to be able to detect if android device is communicating with openhab server via openhab android app?

To my knowledge there is no feature of the Android app that will let you do this directly.

I would probably go about this by using the tasker integration with the OH app. Start by setting up tasker to change the state of an item every minute or some time interval that you are comfortable with. Set that item up with the timestamp-update profile (or just have tasker update that item with the current time, but I don’t know if this is possible). Now you have an item with the last time the android app communicated with the server and you can set up a cron based rule to check that item and make sure the update has occurred within your preferred timeframe.

Thank you for the clarification