I have converted a Tuya Sous Vide to ESPHome, but ran into a few minor issues along the way.
Available data points:
Tuya:
Datapoint 101: switch (value: OFF)
Datapoint 102: enum (value: 0)
Datapoint 103: int value (value: 600)
Datapoint 104: int value (value: 219)
Datapoint 105: int value (value: 0)
Datapoint 106: int value (value: 0)
Datapoint 107: bitmask (value: 0)
Datapoint 108: switch (value: ON)
Datapoint 109: int value (value: 0)
#1:
I have a Number Component to set the cook temperature using the following code:
number:
- platform: "tuya"
id: "tempset"
name: "Set Temperature"
icon: "mdi:thermometer-check"
number_datapoint: 103
min_value: 200
max_value: 950
step: 1
…which works as expected. The Tuya MCU expects an int between 200-950 and divides that to get a temperature range of 20.0-95.0 for the heater. Is there an easy way to apply a function so that this entity shows correctly in HA as a value of 20.0°-95.0° (instead of the current 200-950 range), or do I need to create a separate “helper” template number?
#2:
DP 102 is a sensor that reports the machine status as an enum from the dataset (0=stop,1=working,2=keepwarm). I have tried setting it up as a enum sensor with an options list, but ESPHome doesn’t recognize that as a valid option, even though it’s listed as one of the available device classes.
YAML for reference:
sensor:
- platform: "tuya"
id: "workstatus"
name: "Status"
sensor_datapoint: 102
icon: "mdi:play-pause"
device_class: "enum"
options:
0: stop
1: working
2: keepwarm
And error:
INFO Reading configuration /config/esphome/sous-vide.yaml...
Failed config
sensor.tuya: [source /config/esphome/sous-vide.yaml:134]
platform: tuya
id: workstatus
name: Status
sensor_datapoint: 102
icon: mdi:play-pause
Unknown value 'enum', valid options are '', 'apparent_power', 'aqi', 'battery', 'carbon_dioxide', 'carbon_monoxide', 'current', 'date', 'distance', 'duration', 'energy', 'frequency', 'gas', 'humidity', 'illuminance', 'moisture', 'monetary', 'nitrogen_dioxide', 'nitrogen_monoxide', 'nitrous_oxide', 'ozone', 'pm1', 'pm10', 'pm25', 'power', 'power_factor', 'precipitation_intensity', 'pressure', 'reactive_power', 'signal_strength', 'speed', 'sulphur_dioxide', 'temperature', 'timestamp', 'volatile_organic_compounds', 'voltage', 'volume', 'water', 'wind_speed', 'weight'.
device_class: enum
[options] is an invalid option for [sensor.tuya]. Please check the indentation.
options:
0: stop
1: working
2: keepwarm
If I don’t explicitly define the device_class, the sensor will return the 0/1/2 values, but obviously doesn’t map them to the human readable options within HA. As a workaround, I changed the Tuya sensor to internal, and created a separate text_sensor:
sensor:
- platform: "tuya"
id: "workstatus_internal"
sensor_datapoint: 102
internal: true
on_value:
then:
- lambda: |-
if ((id(workstatus_internal).state == 0)) {
id(workstatus).publish_state("Stopped");
}
else if ((id(workstatus_internal).state == 1)) {
id(workstatus).publish_state("Working");
}
else if ((id(workstatus_internal).state == 2)) {
id(workstatus).publish_state("KeepWarm");
}
text_sensor:
- platform: template
id: "workstatus"
name: "Status"
icon: "mdi:play-pause"
It works, but I am curious why the enum senor device_class isn’t natively supported?