Modbus PLC YAML help

Well, you claim that sensor is in hex, but personally i’m not convinced. It seems odd to me that none of your screenshots on any thread show an actual hex value coming out of sensor.outside_temphex.

{{ states('sensor.outside_temphex') | int(base=16, default=0) / 100 }}

I dunno, it ran for almost a year with the code I showed you calculating the correct temp. Unless something went wacky on the last update. It did give an error that it didn’t like the use of int as a datatype in the template and it all went to hell.

Got it.
All I did was add 16 to the int on each sensor

t1

today

    sensors:
      - name: Pool Temphex
        address: 1024
        scan_interval: 10
        slave: 255       
        data_type: int16 # int or float
        unit_of_measurement: "°F"
        
      - name: outside Temphex
        address: 1026
        scan_interval: 10
        slave: 255       
        data_type: int16 # int or float
        unit_of_measurement: "°F"        
        
        
template:
  - sensor:
      - name: "Pool Temp"
        unit_of_measurement: "°F"
        state: '{{ ("%0x" % (states("sensor.pool_temphex") | int)) | int / 10 }}'
  

      - name: "Outside Temp"
        unit_of_measurement: "°F"
        state: '{{ ("%0x" % (states("sensor.outside_temphex") | int)) | int / 10 }}'

dude, you’re still using

I feel like I’m taking crazy pills. Do you understand taht you should not be using that?

No I don’t understand that guy. I don’t even know what the heck it means. But it must prove it is a hex data input to HA.

That converts TO a hex, not FROM a hex.

You got me man. It’s working. I don’t know why… I would gladly try improvements.

That’s the point, just because it’s an asnwer you expect does not mean it’s correct. If your sensor reports 1422, your temperature result will be 58e. Does that make sense?

Yes but the temp results with the code I shown you there and before has been tested accurate with an actual probe against my Fluke calibrated standard in test baths. I get something doesn’t jive with you. I just do not know what that is.

It’s Decimal to HEX. The sensor must be outputting an int16. So the code would be correct. I was saying it wrong. My apology. So when you convert 1368 to HEX it is 558 then divide by 10 = 55.8. It’s been a while since I looked at all this.

Ok, that makes more sense.

you still run into that problem though, so :man_shrugging:, 1422 will not convert properly.

for giggles, try this in the template editor and you’ll see what I mean

{{ ("%0x" % ("1422" | int)) | int / 10 }}

I will. Where would I put it and what will it do?

So the big question is why would it now crash my YAML when it stated

data_type: int 

instead of

data_type: int16 

That could be a bug, it’s supposed to silently convert int to int16.