one more question…
I have a couple more of these sensors coming, and I’m curious how HA associates the template with the sensor entity.
does the template only apply to an entity that has the state lookup in it?
so the current code below; when i have another sensor named something else, does this value show up just because the value template references an attribute of the sensor ?
First, let’s establish the correct terminology. All entities have a state and some also have attributes. That template (above) is using the states() function to get the state of the entity called sensor.sensor_up_hall_temperature_air. To summarize, that template doesn’t reference any attributes.
If you get a new sensor whose entity_id is sensor.sensor_downstairs_hall_temperature_air then you will create another Template Sensor with almost the same template except the states() function will now refer to the new sensor.
sensor:
- platform: template
sensors:
sensor_up_hall_temperature_in_c:
unit_of_measurement: 'C'
friendly_name: Upstairs Hall Temperature
value_template: '{{ "%.2f"|format((( states("sensor.sensor_up_hall_temperature_air") | float ) -32) *5/9) }}'
sensor_downstairs_hall_temperature_in_c:
unit_of_measurement: 'C'
friendly_name: Downstairs Hall Temperature
value_template: '{{ "%.2f"|format((( states("sensor.sensor_downstairs_hall_temperature_air") | float ) -32) *5/9) }}'
Yes i’m still learning the language/ terms, thanks.
I guess what i was curious about, is how this particular virtual sensor entity gets associated with the device. the only “link” i can see is this entity is referring to that state, therefore it links to that device. It was an assumption on my part, that i wanted to clarify so i dont mess up other sutff further down the road.
Thank you for the example, that’s exactly what i was planning on putting in the config for additional sensors.
I’m sorry to say but the guidance here over complicated the situation. If your device is in ºF and you want it in ºC, then put unit_of_measurement: 'ºF' and home assistant will naturally convert it to ºC. So all you needed in customize was:
You have to use the correct degree symbol as well.
The resulting sensor would be °C if you set system units to metric.
To clarify: If you have system units set as °C and you tell the system that a sensor is °C. The system will say “Hey, this doesn’t need to be converted”. Where as if you give the sensor °F, the system will say “Hey, I need to convert this”.
actually, that was the first thing tried.
when i just put a unit of measure of ‘C’ or ‘°C’, it just changes the unit, but does not convert the value.
perhaps HA doesn’t like the fact the original value is just ‘F’ with no degree symbol.
well thanks. that makes the config easier, although i do appreciate the exercise of the manual process in the thread anyway, as i learnt more that way.
Your situation, having to convert Fahrenheit to Celsius (with Metric being the base unit system), is handled nicely by Home Assistant (as per petro’s advice posted above).
In contrast, what’s not (currently) possible is to display two different unit systems (i.e. some entities report in Celsius and others in Fahrenheit). The existing workaround is to omit the leading degree symbol because, without it, Home Assistant does not perform automatic temperature conversion. For more information, see this post.
Part of the problem, earlier in the thread, i wasn’t able to put the degree symbol in, my config was tossing an error about a bad symbol. it took my brain a day to realize i needed to change the encoding on the file to utf-8 and re-save my configs, then suddenly i could actually put a degree symbol in. but by then the manual / hard way solution was in place and working, so i didn’t think too much more about it.
Regardless, thanks everyone for the help. learnt a lot, and i’m still tinkering daily with HA configs. this system is such a yin-yang of complexity wrapped around flexibility. I dont like the fact i’ve sank a week + into learning and still feel like i’m only scratching the surface, but on the other hand, i cant think of anything which HA probably cant do given the correct inputs and figuring out how to write the syntax.
Yeah, that’s super annoying. I don’t know why the files default to ascii encoding. I had to do the same way back when. What text editor are you using to edit the files? That could be the root cause of the encoding errors.
EditPad Pro. a relatively unknown editor that i’ve been using for years, it’s awesome, full regex support and so much more, and no issues with encoding, it’s what i used to change the encoding.
Edit. my HA is in a docker container, using winSCP to actually get at the files on the pi.
I’ll use vi when i’m in linux directly, but nobody likes using vi. lol.
This does not seem to work for me, using the System Monitor sensor platform; it doesn’t seem to recognize the unit_of_measurement argument. I have my overall units set to Imperial, but I’d like to see CPU temperatures in Celsius, since that’s what my brain is calibrated to for computers
The units bit was just ignored, and my CPU temp still shows in F. Am I doing something wrong here, or is there a different/better way to accomplish this?
That’s working as intended. The units are always converted to your system wide units. If you want it to not convert, you have to use something other than ºC or ºF as a unit_of_measurement. You’ll also have to manually perform the conversion yourself.
I see…many thanks for the info. How would I go about doing the conversion myself? I definitely want my overall system units to be ºF, but I want the CPU temps to show in ºC.
I also have this question. I finally understand the posts from @petro, but I imagine for folks in the USA this is a pretty common need. We use imperial, so I want temps generally in Farenheit (humiture sensors, outdoor temp, etc) so my HA is set to that. But, when monitoring Raspberry Pi’s, Synology NAS, and other computers, most of us would want to see those in Celsius. What is the proper, and easiest way to do this in HA in 2021? I’ve been using HA significantly for more than a year now and this is one thing I still have yet to fully grasp…and one day I spent 4+ hours on this problem. Sure, I am probably being dense and over-complicating it some, but from everything I’ve read on the internet I don’t feel that it is incredibly intuitive.
I second this complaint/request. Need to be able to display processor_temperatures in Celsius and not the “system configuration”. When we talk about computer systems temperatures few people use Fahrenheit.
One workaround to use command_line platform to cat /sys/class/thermal… However, this does not work for me on my system as the sensor moves around every boot. Attempting to do a longer code in the command_line platform like below throws command fail error