Skip to content

Home Assistant Jinja macro for converting IEEE754 hex to floating-point decimal

License

Notifications You must be signed in to change notification settings

Troon/IEEE754-homeassistant

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 

Repository files navigation

IEEE754-homeassistant

Home Assistant Jinja macro for converting IEEE 754 hex strings to floating-point decimal that will handle half, single, and double precision formats.

This is intended for installation as a reusable template:

Then you can use it like this:

{% from 'ieee754.jinja' import ieee754_float %}
{{ ieee754_float("4248") }}
{{ ieee754_float("fl_40490fdb") }}
{{ ieee754_float("4009 21FB 5444 2D18") }}

It handles spacing in the hex and an optional fl_ prefix as used by Senec systems. The infinity and nan special cases both return None / null as Jinja has no sentinel value for infinity.

As with all such macros, the return value is a string, and will need casting before used in calculations. For example:

{% from 'ieee754.jinja' import ieee754_float %}
{{ ieee754_float("4037 0000 0000 0000")|int + 19 }}

Also contains first-draft macros float_ieee754_single(float) and float_ieee754_double(float) to convert in the other direction:

{% from 'ieee754.jinja' import float_ieee754_single %}
{{ float_ieee754_single(-6.2598534e+18) }}

About

Home Assistant Jinja macro for converting IEEE754 hex to floating-point decimal

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages