Convert Decimal to Hexidecimal via template

I’m trying to create a template to convert data coming in from my rtlsdr. It seems that my meter is sending data in ‘decimal’ and when converted to hexidecimal it show the correct meter reading.
I believe I can fix this with a template but it’s not working correctly:

Current value of sensor.water_meter: 0415237

{{ states('sensor.water_meter')}}
{{ states('sensor.water_meter') | int(states('sensor.water_meter'),16) }}

Expected after converted to hexidecimal: 65605
but in the template editor it outputs: 4280887

Can anybody offer any assistance?
(and yes this seems odd that I need to convert this way, but i’ve been recording and have double checked this is how the values are transmitted and sent. It’s not something stuck inside the rtlsdr or elsewhere. ODD

Thanks in advance!

1 Like
{{ '%0x' % states('sensor.water_meter') | int(0) }}

thanks so much!!! appreciate it

1 Like

@123 One last question… how do i get it to 10x that value… from 65605 to 656050. I missed the single gallon digit that it doesn’t report. THANKS!

currently working:

template:
  - sensor:
      - name: "Water Consumption"
        unit_of_measurement: "gal"
        state_class: total_increasing
        state: "{{ '%0x' % states('sensor.water_meter') | int(0) }}"
{{ (('%0x' % states('sensor.water_meter') | int(0)) | int(0)) * 10 }} 
1 Like