couple things… it didn’t like the capitol ‘C’ in the name, had to make lower case. and the quotes in the quotes, changed to double quotes. that is returning a C value now on that new sensor.
next question… how to round the value_template to 2 decimal points ?
thank you so much… such a little thing to bang head into wall for two hours for!
one last question, trying to add the thermometer icon to the new sensor, but when i add
icon: mdi:thermometer
under the sensor, it says [icon] is an invalid option for [sensor.template]
would i have to add the icon line under customize instead?
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”.
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.