Telegram Rule for sending LastSeen date and time

Hello,

I have the following rule working like a charm:

rule "Telegram wenn my mobile is connected to wifi"

when

   Item Presence_mobile_tsch changed to OFF

then

   sendTelegram("my-bot", "tsch mobile is now offline.")

end

Now I would like to send the lastseen date and time via Telegram too.
What would be the correct syntax to achieve this?

Thanks a lot for your help.

How’s this?

sendTelegram("my-bot", "tsch mobile is now offline. Presence last seen: " + String::format("%1$tm-%1$td-%1$tY %1$tI:%1$tM.%1$tS %1$tp", (new DateTimeType).zonedDateTime))
1 Like

Thanks a lot Scott for your quick reply.
This works perfectly.

Can you help me with another problem I’m struggeling with namely sending the actual weather condition from my place using openweathermap?
The binding is allready up and running and I display the current weather in Basic UI and on my mobile.

What syntax must I use to send the current weather condition via telegram?
Would the following trigger be correct, to send a message only when the condition is “RAIN”?

when

Item localCurrentCondition changed to rain

then

sendTelegram…

I’m absolutely lost with the syntax for this kind of commands and the documentation seems to complicated for me as non programmer.

Thanks a lot for your help.

There are many conditions that contain “rain”, so best to keep the Trigger generic…

rule "Send Telegram when it rains"
when
    Item localCurrentCondition changed
then
    if (localCurrentCondition.state.toString.contains("rain")) {
        sendTelegram("my-bot", "Current condition: " + localCurrentCondition.state.toString)
    }
end
1 Like

Perfect. Thanks a lot!

With your example I’n now able to check the state of an item and know what the syntax for sending states via telegram (the “+” was my “missing link”).
Can I send german states instead of english language too?

Where can I find additional information about the possible states for different items (to use them as trigger) and examples for rules to learn from?

You really helped me a lot moving forward with rules.

Yes. You set the language in the OpenWeatherMap Account Thing.

You’ll find this information in the documentation and forum. There are also some tutorials in YouTube. The rules DSL is very limited and confusing to use though. Scripted automation is where things are headed. It allows you to use real scripting languages and Jython is by far the most most advanced.

https://openhab-scripters.github.io/openhab-helper-libraries/index.html

1 Like

Thank you very much for your kind support and patience.

1 Like