Decimal to IEEE754

I’m using the modbus integration to control a temperature controller. New temp setting must be submitted to the modbus.write_register service with the ‘value’ in IEEE754 32-bit floating point format. Ex (sets temp to 75):

service: modbus.write_register
data:
  value: [0x4296,0x0000]
  hub: modbus_hub
  unit: 2
  address: 0

For my use case, I’ll be getting decimal values from the user and need to convert to the required format. I assume a template of some sort is the way to go, but it doesn’t appear there’s a simple filter for this. How would you approach it?

If you can template it (and insert your user value in place of the 75 here), something like:

{% from 'ieee754.jinja' import float_ieee754_single %}
{% set hex_string = float_ieee754_single(75) %}
{{ {'value': ['0x'~hex_string[:4],'0x'~hex_string[4:]]} }}
1 Like