Unixtime ist truncated when exported with mqqt

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
Rini52
Normal user
Posts: 47
Joined: 19 Jun 2021, 17:23
Location: NL

Unixtime ist truncated when exported with mqqt

#1 Post by Rini52 » 23 Sep 2022, 23:29

all,

The system variable %unixtime% is truncated when exported by the 'Home Assistant (openHAB) MQTT' controller in the Pulse_counter device. I assume that this is caused by the fact somewhere intermediate the value is stored in a 32bit IEEE floating point variable. These 32bit variables can handle about 8 digits while the current unix time contains 10 digits. I tested it by doing a measurement every 20 secs and after 6 measurements the unix time was updated. (see attached log) . As you see from the log the truncation is exactly 128 secs. I hope someone can put some light in the darkness about this?
Regards Rini
Attachments
eso_easy_device.png
eso_easy_device.png (88.98 KiB) Viewed 2651 times
eso_easy_log.png
eso_easy_log.png (258.94 KiB) Viewed 2651 times

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Unixtime ist truncated when exported with mqqt

#2 Post by TD-er » 23 Sep 2022, 23:58

You're right.

That's why we have the %unixday% and %unixday_sec% which essentially split both into roughly half of the 32 bits needed to store unixtime.

To recombine them into unixtime: %unixday% * 86400 + %unixday_sec%

N.B. see the systemvariables page (button on the tools page) for more ideas/suggestions on other system variables.

Rini52
Normal user
Posts: 47
Joined: 19 Jun 2021, 17:23
Location: NL

Re: Unixtime ist truncated when exported with mqqt

#3 Post by Rini52 » 24 Sep 2022, 00:33

Td

Spot on! I overlooked this button. I had a look in the documentation(https://www.letscontrolit.com/wiki/inde ... _Variables) and there only the unixtime was mentioned.
Thanks a lot . it solved indeed my problem.

Regard, Have a nice weekend

Rini52
Normal user
Posts: 47
Joined: 19 Jun 2021, 17:23
Location: NL

Re: Unixtime ist truncated when exported with mqqt

#4 Post by Rini52 » 24 Sep 2022, 00:45

TD,

Sorry i was to quick. It turns out , that producing the same problem . after six intervals its updated. May be you use a 32bit in the export of the mqtt?

Regards

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Unixtime ist truncated when exported with mqqt

#5 Post by TD-er » 25 Sep 2022, 00:06

How do you now send it to the controller?
Using the number of unixdays and the sec on the current day both fit in roughly 16 a 17 bits. Or at least they can be stored in a float without loosing any information.
The values are kept as a float until they are sent to controller.

So you should not combine them until after they are sent.

If you need to process it as full unixtime in one MQTT message, you can send it via the rules using the publish command.
When sending it from the rules, it is converted to a string and further processed as a string without modifying.
You can trigger sending this via publish, by using the event sent by the task.

Rini52
Normal user
Posts: 47
Joined: 19 Jun 2021, 17:23
Location: NL

Re: Unixtime ist truncated when exported with mqqt

#6 Post by Rini52 » 25 Sep 2022, 18:22

TD thanks,

I think I will go for option 2 (via rules) . Indeed I did unixday*64600 + unix_sec in the export field of the device ,which is send by mqtt. There apparently you use a 32bit float.
I will test it next week.

Regards
Rini

Post Reply

Who is online

Users browsing this forum: No registered users and 18 guests