Hey everyone, I wanted to share my experience with configuring a Modbus sensor for temperature readings. Initially, I faced some challenges with scaling the sensor data correctly. Let me walk you through how I resolved it and hopefully, this can help someone else too!
The Problem:
I set up a Modbus sensor to read temperature values from a register. The sensor returns the temperature multiplied by 10 as an integer. For example, 184 represents 18.4°C. However, when I tried to configure the sensor using the scale and data_type parameters, it wasn’t giving the expected result. Instead of 18.4, it showed 18 or 0, which wasn’t helpful.
The Solution:
After some research and experimentation, I discovered that using a template sensor was the most reliable way to achieve the desired scaling. Here’s how I configured it:
yaml
sensor:
- platform: modbus
name: Temperature Sensor
hub: Z031
register: 30000
data_type: int
scale: 0.1 - platform: template
sensors:
temperature_scaled:
value_template: ‘{{ states.sensor.temperature_sensor.state | float / 10 }}’
friendly_name: “Temperature”
unit_of_measurement: “°C”
Why This Works:
- The Modbus sensor reads the raw value from the register.
- The
templatesensor then takes this value, converts it to a float, and divides it by 10 to get the correct temperature reading. - This approach ensures that the temperature is displayed accurately without any additional complexity.
Conclusion:
While the Modbus sensor itself didn’t handle the scaling as expected, using a template sensor provided a straightforward and effective workaround. It’s always a bit frustrating when things don’t work out of the box, but finding a solution really makes it worthwhile!
If anyone has similar issues or needs further clarification, feel free to ask. Happy automating! ![]()