Add docs and example for unit_of_measurement (#34672)

This commit is contained in:
chammp 2024-09-11 08:50:40 +02:00 committed by GitHub
parent 85d84fb345
commit e4a331a550
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -214,6 +214,11 @@ number:
description: Template for the number's current value.
required: true
type: template
unit_of_measurement:
description: Defines the units of measurement of the number, if any.
required: false
type: string
default: None
set_value:
description: Defines actions to run when the number value changes. The variable `value` will contain the number entered.
required: true
@ -809,6 +814,33 @@ template:
{% endraw %}
### Number entity changing the unit of measurement of another number
This example demonstrates the usage of a template number with a unit of measurement set to change a unit-less value of another number entity.
{% raw %}
```yaml
template:
- number:
- name: "Cutting Height"
unit_of_measurement: "cm"
unique_id: automower_cutting_height
state: "{{ states('number.automower_cutting_height_raw')|int(0) * 0.5 + 1.5 }}"
set_value:
- service: number.set_value
target:
entity_id: number.automower_cutting_height_raw
data:
value: "{{ (value - 1.5) * 2 }}"
step: 0.5
min: 2
max: 6
icon: mdi:ruler
```
{% endraw %}
## Legacy binary sensor configuration format