I am new to Home Assistant & in the process of trying to change across from my Vera platform to HA.
I have a number of temperature sensors that are input via modbus. When the measured temperatures are under 0 degrees, the sensor value is 1000 less the actual temperature ( eg if the temperature is -1.2 degrees, then the sensor value is 1001.3.
I need a simple IF function that will return the raw sensor value for sensor values < 1000 and (- sensor value -1000) for values > 1000.
I think the way to go is to use a sensor template, but are completely lost on how to do this as the examples for templates seem to be based on states rather than state values
I think the code below should work or at least be close. This template assumes that the state of the sensor.outside_west_temp is the temperature value in float format.
Now trying to work out why the value is graphed as a bar chart rather than line - thought it might be something to do with needing to convert the value back to float, but that did not work.
Its been a good morning to test as first real frost for the season!
Likely because the result is being viewed as a string rather than a number.
Sorry, what does the’%.1f’ do? If you’re trying to get one decimal use the round function.
Btw states are always strings even if they are numbers (python thing).
Thanks again.
The issue was that I had not given ‘West Temp’ any units of measurement. Adding that into the script solved the problem. The ‘.1f’ trims the value to 1 decimal place, but I dont think it rounds the number. Will try using round later today, but for now the script is now doing pretty much all I wanted, so it will be fine tuning (and learning more) from here on in