Dear comunity,
I try to convert an epoche number from zigbee2mqtt epoche to datetime to display the date properly. I use mainly this page: DateTime Conversion
When I receive the Number Item for the epoche with Milliseconds (13 digits) the following rule outputs different numbers.
Rule:
logInfo("Zigbee Devices","Aktualisierung DateTime Lastseen, Epoche aus Item: " + Aqara_Balkon_Lastseen_epoche.state.toString)
val int epoche_Millis = (Aqara_Balkon_Lastseen_epoche.state as Number).intValue
logInfo("Zigbee Devices","Aktualisierung DateTime Lastseen, Epoche Millis: " + epoche_Millis.toString)
But the log shows two different numbers:
2020-02-27 18:50:45.267 [INFO ] [marthome.model.script.Zigbee Devices] - Aktualisierung DateTime Lastseen, Epoche aus Item: 1582825530384
2020-02-27 18:50:45.270 [INFO ] [marthome.model.script.Zigbee Devices] - Aktualisierung DateTime Lastseen, Epoche Millis: -2017401840
Probably some easy error but 60 min + google do not help me somehow
Happy for the right hint - thanks!
Best
MatzeMuc86
Wolfgang_S
(Wolfgang_S)
February 27, 2020, 7:40pm
2
-2017401840 is the 2’s complement of lower 4 bytes of 1582825530384. 1582825530384 does not fit into type int.
Try to use long instead of int:
val long epoche_Millis = (Aqara_Balkon_Lastseen_epoche.state as Number).longValue
logInfo("Zigbee Devices","Aktualisierung DateTime Lastseen, Epoche Millis: " + epoche_Millis.toString)
2 Likes
Thanks - no idea why I have not realized. With long it works perfectly.
rossko57
(Rossko57)
February 28, 2020, 10:49am
4
It may not help depending on what you are doing exactly, but in recent months the openHAB Datetime type Item has been enhanced to parse epoch timestamps directly.
opened 08:35AM - 21 Oct 19 UTC
closed 11:47PM - 10 Nov 19 UTC
If a DateTime Item receives an updated, it parses a String and converts it into … a date and time.
Can you extend this parsing to accept a unix time stamp as well?
The openHAB app for Android sends the next alarm clock time to the server as unix time. This fails if the receiver item is DateTime. While the app can be changed to send a DateTime string, it wouldn't require any migration of the client if the DateTime item can accept unix time.
For further discussion see: https://community.openhab.org/t/android-app-sends-alarm-time-as-long-not-datetime/83758/10
system
(system)
Closed
April 10, 2020, 2:49am
5
This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.