Nodemcu DTH11 temp sensor how to change unit of measure

I have a nodemcu setup using ESPHome with a DTH11 temp sensor. The default unit of measure is Celsius and I would like to change that to Fahrenheit. Any ideas on how I can accomplish that?

Here is the code insode of ESPHome

sensor:
  - platform: dht
    pin: D6
    temperature:
      name: "NodeMCU2 Temperature"
    humidity:
      name: "NodeMCU2 Humidity"
    update_interval: 30s
    model: DHT11
  - platform: wifi_signal
    name: "NodeMCU2 WiFi Signal"
    update_interval: 60s

You can do it in Home assistant. Click on the temperature entity and select settings > unit of measurement.

Thank you. When I look at the entity, I don’t see a unit of measurement. Maybe I am looking in the wrong place, but I navigate to settings/devices and services/entities(tab), then click on my entity.

What version of home assistant are you running?

This is what my ESPHome DHT entity settings looks like:

Strange. I am usually up to date on my core and HA listed below. Could it be my ESPHome needs updating? It looks like I am at version 1.15.3

This is the nodemcu board info in my ESPHome config file.

esphome:
  name: nodemcu2
  platform: ESP8266
  board: nodemcuv2

It was in 2022.4:

https://www.home-assistant.io/blog/2022/04/06/release-20224/#adjusting-unit-of-measurement-for-sensors

What are the attributes of your sensor?

Developer Tools States:


Strange, the UOM appears to be there.

You don’t have a state class or device class though.

What version of ESPHome was the device complied with?

It has been so long I dont remember even how to compile. Is that the same as validate? I just validated, re-uploaded and restarted HAS. Still looks the same with no “device class”

INFO Reading configuration /config/esphome/NodeMCU2.yaml…
INFO Generating C++ source…
INFO Compiling app…
INFO Running: platformio run -d /config/esphome/nodemcu2
Processing nodemcu2 (board: nodemcuv2; framework: arduino; platform: [email protected])

HARDWARE: ESP8266 80MHz, 80KB RAM, 4MB Flash
PACKAGES:

  • framework-arduinoespressif8266 3.20704.0 (2.7.4)
  • tool-esptool 1.413.0 (4.13)
  • tool-esptoolpy 1.20800.0 (2.8.0)
  • toolchain-xtensa 2.40802.200502 (4.8.2)
    Dependency Graph
    |-- 1.2.3
    | |-- 1.0
    |-- 1.0
    |-- 1.2
    | |-- 1.0
    |-- 1.2.7
    | |-- 1.2.3
    | | |-- 1.0
    | |-- 1.0
    | |-- 1.0
    |-- 1.1.1
    | |-- 1.0
    Retrieving maximum program size /data/nodemcu2/.pioenvs/nodemcu2/firmware.elf
    Checking size /data/nodemcu2/.pioenvs/nodemcu2/firmware.elf
    RAM: [==== ] 44.9% (used 36804 bytes from 81920 bytes)
    Flash: [==== ] 38.2% (used 398972 bytes from 1044464 bytes)
    ========================= [SUCCESS] Took 10.64 seconds =========================
    INFO Successfully compiled program.
    INFO Connecting to 192.168.1.150
    INFO Uploading /data/nodemcu2/.pioenvs/nodemcu2/firmware.bin (403120 bytes)
    Uploading: [============================================================] 100% Done…

INFO Waiting for result…
INFO OTA successful
INFO Successfully uploaded program.
INFO Starting log output from 192.168.1.150 using esphome API
INFO Connecting to 192.168.1.150:6053 (192.168.1.150)
WARNING Initial connection failed. The ESP might not be connected to WiFi yet (Error connecting to 192.168.1.150: timed out). Re-Trying in 1 seconds
INFO Connecting to 192.168.1.150:6053 (192.168.1.150)
INFO Successfully connected to 192.168.1.150
[09:46:55][I][app:105]: ESPHome version 1.15.3 compiled on Jul 2 2022, 09:31:48
[09:46:55][C][wifi:443]: WiFi:
[09:46:55][C][wifi:303]: SSID: [redacted]
[09:46:55][C][wifi:304]: IP Address: 192.168.1.150
[09:46:55][C][wifi:306]: BSSID: [redacted]
[09:46:55][C][wifi:307]: Hostname: ‘nodemcu2’
[09:46:55][C][wifi:311]: Signal strength: -63 dB ▂▄▆█
[09:46:55][C][wifi:315]: Channel: 7
[09:46:55][C][wifi:316]: Subnet: 255.255.255.0
[09:46:55][C][wifi:317]: Gateway: 192.168.1.1
[09:46:55][C][wifi:318]: DNS1: (IP unset)
[09:46:55][C][wifi:319]: DNS2: (IP unset)
[09:46:55][C][logger:185]: Logger:
[09:46:55][C][logger:186]: Level: DEBUG
[09:46:55][C][logger:187]: Log Baud Rate: 115200
[09:46:55][C][logger:188]: Hardware UART: UART0
[09:46:55][C][dht:017]: DHT:
[09:46:55][C][dht:018]: Pin: GPIO12 (Mode: INPUT)
[09:46:55][C][dht:022]: Model: DHT11
[09:46:55][C][dht:027]: Update Interval: 30.0s
[09:46:55][C][dht:029]: Temperature ‘NodeMCU2 Temperature’
[09:46:55][C][dht:029]: Unit of Measurement: ‘°C’
[09:46:55][C][dht:029]: Accuracy Decimals: 1
[09:46:55][C][dht:029]: Icon: ‘mdi:thermometer’
[09:46:55][C][dht:030]: Humidity ‘NodeMCU2 Humidity’
[09:46:55][C][dht:030]: Unit of Measurement: ‘%’
[09:46:55][C][dht:030]: Accuracy Decimals: 0
[09:46:55][C][dht:030]: Icon: ‘mdi:water-percent’
[09:46:55][C][captive_portal:169]: Captive Portal:
[09:46:55][C][ota:029]: Over-The-Air Updates:
[09:46:55][C][ota:030]: Address: 192.168.1.150:8266
[09:46:55][C][ota:032]: Using Password.
[09:46:55][C][api:095]: API Server:
[09:46:55][C][api:096]: Address: 192.168.1.150:6053
[09:46:55][C][wifi_signal.sensor:009]: WiFi Signal ‘NodeMCU2 WiFi Signal’
[09:46:55][C][wifi_signal.sensor:009]: Unit of Measurement: ‘dB’
[09:46:55][C][wifi_signal.sensor:009]: Accuracy Decimals: 0
[09:46:55][C][wifi_signal.sensor:009]: Icon: ‘mdi:wifi’
[09:46:57][D][api.connection:604]: Client ‘Home Assistant 2022.6.7 (192.168.1.141)’ connected successfully!
[09:47:16][D][dht:048]: Got Temperature=23.0°C Humidity=45.0%
[09:47:16][D][sensor:092]: ‘NodeMCU2 Temperature’: Sending state 23.00000 °C with 1 decimals of accuracy
[09:47:16][D][sensor:092]: ‘NodeMCU2 Humidity’: Sending state 45.00000 % with 0 decimals of accuracy
[09:47:33][D][sensor:092]: ‘NodeMCU2 WiFi Signal’: Sending state -63.00000 dB with 0 decimals of accuracy
[09:47:46][D][dht:048]: Got Temperature=23.0°C Humidity=45.0%
[09:47:46][D][sensor:092]: ‘NodeMCU2 Temperature’: Sending state 23.00000 °C with 1 decimals of accuracy
[09:47:46][D][sensor:092]: ‘NodeMCU2 Humidity’: Sending state 45.00000 % with 0 decimals of accuracy

No, upload re-compiles the config file.

this is done very simply and is in the esphom example.

filters:
  - lambda: return x * (9.0/5.0) + 32.0;
unit_of_measurement: "°F"

Example: Converting Celsius to Fahrenheit¶
While I personally don’t like the Fahrenheit temperature scale, I do understand that having temperature values appear in the Fahrenheit unit is quite useful to some users. ESPHome uses the Celsius temperature unit internally, and I’m not planning on making converting between the two simple (:wink:), but you can use this filter to convert Celsius values to Fahrenheit.
Everything for the sensor here

Awesome Lordzid, that worked like a charm! Thank you very much