From line 78 of this file, it looks like you need to do the following in Python (and yes, it is IEEE-754):
>>> import struct
>>> struct.unpack('!f',bytes.fromhex('fl_43F54001'[3:]))[0]
490.5000305175781
If that value seems reasonable, here’s the same in Jinja:
{% set s = "fl_43F54001" %}
{% set hl = s[3:]|regex_findall('..')|map('int', base=16)|list %}
{% set b = "%c%c%c%c" % (hl[0],hl[1],hl[2],hl[3]) %}
{{ b.encode('latin-1')|unpack('!f') }}
# which returns:
490.5000305175781
So:
command_line:
- sensor:
unique_id: senec002
name: senec_mpp
command: 'curl -d "{\"PV1\":{}}" http://192.168.1.247/lala.cgi'
scan_interval: 60
value_template: >
{% set s = value_json.PV1.MPP_POWER[1] %}
{% set hl = s[3:]|regex_findall('..')|map('int', base=16)|list %}
{% set b = "%c%c%c%c" % (hl[0],hl[1],hl[2],hl[3]) %}
{{ b.encode('latin-1')|unpack('!f') }}
json_attributes:
- result
There’s probably a better way to get from hl
to b
. This method breaks if there are a different number of characters in the response.
Note that the latin-1
encoding is important. At first, I used the default utf-8
and ended up with a smaller answer than the Python solution. I’m not enough of an expert to understand this, but utf-8
encoding turned the 0xf5
(245) into 0xc3
(195), and gave an answer of 391
instead of 490
.
EDIT:
Slightly more compact solution that allows for different-length hex strings:
{% set s = value_json.PV1.MPP_POWER[1] %}
{% set hl = s[3:]|regex_findall('..')|map('int',base=16)|list %}
{{ ("{:c}"*hl|count).format(*hl).encode('latin-1')|unpack('!f') }}