Create a sensor from and entity attribute

Hi all,

I hope this is the right category in this forum to poste my question, else please move this subject to the related category.

My question:
I have one thermometer (from Tuya) that is not really working with home Assistant, but instead of reading the current temperature I can see some corresponding values.

Let me give more detail:

The device entity id is: climate.thermostat
The attribute where I see values is named: current_temperature

But as explained in “current_temperature” I see only value like 3.8 which give 19°C (on the device screen), 3.9 gives 19.5 etc…

What I want to do is create an new entity or senssor from the the above attribute and make a table of correspondance like this:

3.8 ->19 °C
3.9 → 19.5 °C
4 → 20 °C
4.1 → 20.5 °C
4.2 → 21 °C
4.3 → 21.5 °C
4.4 → 22 °C
4.5 → 22.5 °C
4.6 → 23 °C
4.7 → 23.5 °C
etc…

By doing this I can use this new sensor / entity to get the real value of the temperature as I can read it on the screen of the physical device.

I hope my issue is clear for you, else please tell me and I’ll give you more details.

Many thank for all your support.
Phil

Thank you for your quick reply, based on your answer I have trid this, but I get an error message

compensation:
  Room_temperature_wall_mounted:
    source: climate.thermostat
    attribute: current_temperature
    unit_of_measurement: °C
    data_points:
      - [3.8, 19]
      - [3.9, 19.5]
      - [4.0, 20]
      - [4.1, 20.5]

Error message:
Invalid config for [compensation]: [Room_temperature_wall_mounted] is an invalid option for [compensation]. Check: compensation->compensation->Room_temperature_wall_mounted. (See /config/configuration.yaml, line 100).

THank you for your support

You need to get rid of the capital R in the object id.

THanks the correction is done. Now just for my understanding, is this supposed to creat an entity named: room_temperature_wall_mounted, where the converted values will be stored ? if this is the case I can’t see this in the “STATUS” tab ?

Maybe this might help you, I have a separate “sensor” file

Many thanks for your support.

I would probably have used a template sensor instead. Not because it’s better but it would have saved you a lot of manual typing.

sensor:
  - platform: template
    sensors:
      room_temperature_wall_mounted:
        value_template: "{{ state_attr('climate.thermostat', 'current_temperature') | float * 5 }}"
        unit_of_measurement: °C

because 19/3.8 = 5, 19.5/3.9 = 5 and 20.5/4.1 = 5. So there is no reason to create a compensation table in my opinion.
But now that it’s done it won’t make any difference, unless you believe it will go above or below your current range.

What is the

?

Thank you for your answer. Making a template sensor was my first idea and your code seems to be what I wanted to do. Just one question, where and how to enter the conversion value into the code you have given above ?

The “status” tab is as shown below

Umm… it is there. All you need to do is copy it to your configuration and reload template entities.
When that is done it should be visible in states tab

Sorry I didn’t see the float 5 so it’s clear for me. Many thanks I’ll try this and come back to let you know.

Thank you very much, it’s working perfectly.