substitutions:
formaldehyde_unit: "mg/m³"
sensor:
- platform: sfa30
formaldehyde:
name: "Formaldehyde"
unit_of_measurement: "ppb"
accuracy_decimals: 1
temperature:
name: "Temperature"
humidity:
name: "Humidity"
- platform: template
name: "Formaldehyde ({{ formaldehyde_unit }})"
unit_of_measurement: "{{ formaldehyde_unit }}"
accuracy_decimals: 1
icon: "mdi:chemical-weapon"
lambda: |-
return id(formaldehyde_conversion).process(id(sfa30).formaldehyde);
filter:
- platform: custom
lambda: |-
auto formaldehyde_conversion = new LinearTransformFilter(0.086 / 1000);
return formaldehyde_conversion->process(x);
id: formaldehyde_conversion
state:
- operator: assign
id: sfa30_formaldehyde_mg
value: "{{ states('sensor.formaldehyde') | float / 1000 * 1.25 | round(1) }}"
icon: "mdi:chemical-weapon"
unit_of_measurement: "{{ formaldehyde_unit }}"
用gpt 生成的代码,不知道是否可以实现单位转换,回头试试 |