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
Unixtime ist truncated when exported with mqqt
Moderators: grovkillen, Stuntteam, TD-er
Unixtime ist truncated when exported with mqqt
- Attachments
-
- eso_easy_device.png (88.98 KiB) Viewed 3626 times
-
- eso_easy_log.png (258.94 KiB) Viewed 3626 times
Re: Unixtime ist truncated when exported with mqqt
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.
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.
Re: Unixtime ist truncated when exported with mqqt
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
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
Re: Unixtime ist truncated when exported with mqqt
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
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
Re: Unixtime ist truncated when exported with mqqt
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.
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.
Re: Unixtime ist truncated when exported with mqqt
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
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
Who is online
Users browsing this forum: No registered users and 5 guests