Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/uartex/PACKET_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Use this guide to turn a device specification or a labelled UART capture into ES
|---|---|---|
| Contact or motion report | `binary_sensor` | Filter by device and opcode with `state`; compare `state_on/off` at the absolute payload offset. |
| One-shot call | `button` | `command_on` runs when pressed. This platform rejects `state` and `command_update`. |
| Relay with feedback | `switch` | Map ON/OFF commands and reports separately. Use `optimistic` when publishing the requested state immediately is appropriate. |
| Relay with feedback | `switch` | Map ON/OFF commands and reports separately. `optimistic` (default `true`, controllable platforms only) publishes the requested state immediately; set `optimistic: false` to wait for feedback. |
| Dimmable light | `light` | RX brightness and TX lambda input use 0–100. For a wire byte 0–255, decode as byte × 100 / 255 and encode as round(x × 255 / 100). |
| Measurement or writable setpoint | `sensor`, `number` | A sensor requires exactly one of `state_number` and `lambda`. For a writable number, also define the input range, step and `command_number`. Verify signedness, byte order and decimal scaling against displayed values. |
| Device status or display text | `text_sensor`, `text` | A text sensor requires a string-returning lambda. Writable text requires `command_text`, which receives `str`. Confirm encoding, terminator and maximum wire length from the device. |
Expand Down
6 changes: 3 additions & 3 deletions components/uartex/README.ko.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ sensor:
| 명령에 ACK 지정 | 예를 들어 `command_on: {data: [0x01, 0x01], ack: [0x01, 0x11]}`로 송신 바이트와 예상 응답 접두사를 지정합니다. 명령의 `mask`는 수신 ACK에 적용됩니다. |
| 다른 채널 값 유지 | 엔티티 명령의 `preserve_state`에 복사할 오프셋을 지정합니다. RX와 TX에서 같은 위치여야 하며 엔티티에 `state`가 필요합니다. 필요한 바이트를 모두 수신할 때까지 명령이 대기합니다. 전송 후에는 다음 일치 상태를 기다립니다. [상태 보존 예제](README.md#command-schema) |
| 수신 직후 송신 허용 | 장치가 정해진 프레임 뒤에만 송신할 수 있으면 `state_response`로 그 프레임을 지정합니다. 가장 최근 수신값이 일치해야 엔티티 큐에서 명령 하나를 꺼낼 수 있습니다. 이미 보낸 명령의 확인 응답은 해당 명령의 `ack`에 지정합니다. |
| 상태 조회 | `command_update`로 조회 패킷을 보내고 `update_interval`로 주기를 정합니다(기본 60초). 피드백이 없는 스위치는 `optimistic: true`로 요청한 상태를 즉시 게시할 수 있습니다. |
| 상태 깜빡임 필터 | 월패드가 `off`↔`heat`처럼 1~2초짜리 일시 상태를 보낼 때 `state_debounce`(기본 `0`, 비활성, 최대 `60s`)를 지정합니다. 엔티티에 `state`가 필요합니다. 기본은 일치한 패킷 전체를 비교하므로 같은 패킷 안의 다른 바이트(예: 현재 온도)가 계속 바뀌면 그 패킷도 지연되고, 패킷 안의 모든 값이 최대 지정 시간만큼 늦게 반영됩니다. 이를 피하려면 아래의 `offset`/`mask` 형식으로 일부 바이트만 비교합니다. 일치한 상태 패킷을 보류했다가 변화가 시작된 시점부터 지정 시간이 지나면 게시하며, 그동안 마지막으로 받은 패킷이 적용됩니다. 마지막으로 적용된 상태와 같은(`mask`를 쓰면 마스크 영역이 같은) 패킷이 오면 보류를 취소하고 즉시 다시 게시합니다. 부팅 후 첫 패킷과, 엔티티 자신의 명령 전송 직후(지정 시간 이내) 처음 수신한 상태 변화는 즉시 적용하므로 `optimistic` 없이도 명령 결과가 지연되지 않습니다(`command_update` 폴링은 해당하지 않고, 마지막 적용 상태와 같은 패킷은 이를 소모하지 않음). 엔티티가 마지막으로 전송한 명령 이후의 첫 상태 변화만 즉시 적용되므로, `ack` 없이 같은 엔티티의 명령이 연달아 나가면 뒤의 결과는 일반 디바운스를 따릅니다. 이 우회는 엔티티의 일반 명령 큐(제어 동작)로 나간 명령이 켜므로, 사용자 람다가 `enqueue_tx_cmd`를 주기적으로 호출하면 계속 켜져 있게 됩니다. `state_response`는 지연하지 않습니다. HA에서 내린 명령은 `control`/`optimistic`으로 즉시 반영되며, 버스에서 관찰한 변화만 최대 지정 시간만큼 늦어집니다. 변화가 보류 중이면 `preserve_state` 명령도 안정될 때까지(보통 지정 시간 이내, 패킷의 일부 바이트가 계속 바뀌면 더 길어질 수 있음) 대기합니다. |
| 상태 조회 | `command_update`로 조회 패킷을 보내고 `update_interval`로 주기를 정합니다(기본 60초). `optimistic`(기본 `true`)이 켜져 있으면 HA에서 내린 명령의 요청 상태를 즉시 반영하며, `false`로 지정하면 명령은 보내되 상태 피드백이 올 때까지 상태를 바꾸지 않습니다. 이전에는 스위치가 기본적으로 피드백을 기다렸으므로 그 동작이 필요하면 `optimistic: false`를 지정하세요. 명령이 설정되지 않은 엔티티는 예전에는 요청을 무시했지만, 기본값에서는 아무것도 보내지 않고 요청을 반영하므로 이전 동작이 필요하면 `optimistic: false`를 지정하세요. 명령 람다가 데이터를 반환하지 않으면 명시적인 거부로 취급되어, `optimistic: true`여도 아무것도 보내지 않고 요청 상태도 반영하지 않습니다. `optimistic`은 제어 가능한 플랫폼(`switch`, `climate`, `cover`, `fan`, `lock`, `media_player`, `number`, `select`, `text`, `valve`, `water_heater`)에서만 사용할 수 있습니다. `light`는 ESPHome 조명 상태가 요청을 즉시 반영하므로 이 옵션을 지원하지 않고, `sensor`, `binary_sensor`, `text_sensor`, `button`도 받지 않습니다. 해당 플랫폼에 `optimistic`을 지정한 설정은 이제 검증에 실패하므로 키를 제거하세요. |
| 상태 깜빡임 필터 | 월패드가 `off`↔`heat`처럼 1~2초짜리 일시 상태를 보낼 때 `state_debounce`(기본 `0`, 비활성, 최대 `60s`)를 지정합니다. 엔티티에 `state`가 필요합니다. 기본은 일치한 패킷 전체를 비교하므로 같은 패킷 안의 다른 바이트(예: 현재 온도)가 계속 바뀌면 그 패킷도 지연되고, 패킷 안의 모든 값이 최대 지정 시간만큼 늦게 반영됩니다. 이를 피하려면 아래의 `offset`/`mask` 형식으로 일부 바이트만 비교합니다. 일치한 상태 패킷을 보류했다가 변화가 시작된 시점부터 지정 시간이 지나면 게시하며, 그동안 마지막으로 받은 패킷이 적용됩니다. 마지막으로 적용된 상태와 같은(`mask`를 쓰면 마스크 영역이 같은) 패킷이 오면 보류를 취소하고 즉시 다시 게시합니다. 부팅 후 첫 패킷과, 엔티티 자신의 명령 전송 직후(지정 시간 이내) 처음 수신한 상태 변화는 즉시 적용하므로 `optimistic: false`여도 명령 결과가 지연되지 않습니다(`command_update` 폴링은 해당하지 않고, 마지막 적용 상태와 같은 패킷은 이를 소모하지 않음). 엔티티가 마지막으로 전송한 명령 이후의 첫 상태 변화만 즉시 적용되므로, `ack` 없이 같은 엔티티의 명령이 연달아 나가면 뒤의 결과는 일반 디바운스를 따릅니다. 이 우회는 엔티티의 일반 명령 큐(제어 동작)로 나간 명령이 켜므로, 사용자 람다가 `enqueue_tx_cmd`를 주기적으로 호출하면 계속 켜져 있게 됩니다. `state_response`는 지연하지 않습니다. `optimistic: true`(기본)이면 HA에서 내린 명령은 `control`로 즉시 반영되고, `optimistic: false`이면 상태 피드백이 올 때만 반영됩니다. 버스에서 관찰한 변화는 최대 지정 시간만큼 늦어집니다. 변화가 보류 중이면 `preserve_state` 명령도 안정될 때까지(보통 지정 시간 이내, 패킷의 일부 바이트가 계속 바뀌면 더 길어질 수 있음) 대기합니다. |
| 동적 명령 | `!lambda`에서 페이로드, 필요하면 ACK와 마스크를 반환합니다. 숫자를 받는 명령은 `x`, 문자열을 받는 명령은 `str`를 사용합니다. [람다 예제](README.md#command-lambda-types) |

```yaml
Expand Down Expand Up @@ -229,7 +229,7 @@ text:

### 냉난방기 (`climate`)

RX 페이로드 `01 18 16`은 난방, 목표 24°C, 현재 22°C입니다. 모드와 목표 온도를 한 패킷으로 보내는 장치는 모드 명령에서 `use_command_target_temperature()`로 이번 요청의 목표값을 읽습니다. 모드와 온도 명령이 독립적인 장치는 각 명령을 따로 정의합니다. 현재 동작(가열·대기)은 `state_action_heating`·`state_action_idle`, 풍향은 `state_swing_*`, 습도는 `state_humidity_current`·`state_humidity_target`으로 표현합니다.
RX 페이로드 `01 18 16`은 난방, 목표 24°C, 현재 22°C입니다. 모드와 목표 온도를 한 패킷으로 보내는 장치는 모드 명령에서 `use_command_target_temperature()`로 이번 요청의 목표값을 읽습니다. 모드 명령이 이번 호출에서 목표값을 읽으면 그 요청에 대해 별도의 온도 명령은 절대 보내지 않으며, 패킷이 큐에 들어가고 `optimistic`이 true이면 목표값도 즉시 반영합니다. 람다가 데이터를 반환하지 않으면 모드와 목표값을 모두 거부합니다. `optimistic: false`이면 `command_temperature`나 `command_preset`에서 `id(thermostat).mode`처럼 엔티티 자신의 현재 상태를 읽는 람다는 같은 호출에서 요청한 값이 아니라 마지막으로 확인된 상태를 봅니다. 모드와 온도 명령이 독립적인 장치는 각 명령을 따로 정의합니다. 현재 동작(가열·대기)은 `state_action_heating`·`state_action_idle`, 풍향은 `state_swing_*`, 습도는 `state_humidity_current`·`state_humidity_target`으로 표현합니다.

```yaml
climate:
Expand Down
19 changes: 12 additions & 7 deletions components/uartex/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -730,9 +730,14 @@ text:
If a mode command also encodes the target temperature, use
`id(thermostat).use_command_target_temperature()` for that packet field.
During a combined request it returns the requested temperature. Otherwise it
returns the current target. Once the combined packet is queued, UARTEx updates
the target and skips the separate temperature command. Devices with distinct
mode and temperature packets continue to send both.
returns the current target. If the mode command reads the target through this call, UARTEx never sends a
separate temperature command for that request. When the packet is queued and
`optimistic` is true, the target is reflected immediately. A lambda that
returns no data rejects both the mode and the target. Devices with distinct
mode and temperature packets continue to send both. With `optimistic: false`,
lambdas that read the entity's own current state (for example
`id(thermostat).mode` in `command_temperature` or `command_preset`) see the last
confirmed state, not the value requested in the same call.

**Packet Example**:
```
Expand Down Expand Up @@ -1072,14 +1077,14 @@ on_...:

## Common Device Options

These options are available for all UARTEx platforms:
These options are available for all UARTEx platforms (except `optimistic`, which only applies to the controllable platforms noted below):

| Option | Type | Default | Description |
|--------|------|---------|-------------|
| `state` | state | - | Base state filter |
| `state_response` | state | - | Response state match |
| `command_update` | command | - | Polling command |
| `optimistic` | bool | `false` | For switches, publish the requested state immediately when enabled. Otherwise, publish on matching `state_on` or `state_off` feedback. Enable this for switches that have no state feedback. |
| `optimistic` (controllable platforms only) | bool | `true` | For controllable entities, reflect a command from Home Assistant immediately, whether or not the entity has a command to send. Set `false` to send the command but wait for matching state feedback before the state changes, so a stale packet cannot make the state bounce. Keep `true` for entities that have no state feedback. `optimistic` is accepted only by the controllable platforms `switch`, `climate`, `cover`, `fan`, `lock`, `media_player`, `number`, `select`, `text`, `valve` and `water_heater`. `light` reflects requests immediately through ESPHome's light state and does not support it; `sensor`, `binary_sensor`, `text_sensor` and `button` do not accept it either, so configs that set `optimistic` on those platforms now fail validation (remove the key). Entities with no command configured used to ignore the request; with the default they now reflect it without sending anything, so set `optimistic: false` to keep the old behavior. A command lambda that returns no data is still treated as an explicit rejection: nothing is sent and the requested state is never reflected, even with `optimistic: true`. Before this default changed, a switch waited for feedback unless `optimistic: true` was set; use `optimistic: false` for that behavior. |
| `state_debounce` | time | `0` | Hold matched state packets and publish only after this time (see below). `0` disables. |
| `update_interval` | time | `60s` | Polling interval |

Expand All @@ -1091,9 +1096,9 @@ Some wallpads emit transient state packets (for example a climate flipping `off`
- Matched state packets are held and published only after the debounce time has elapsed since the change started. The latest packet received during that time wins.
- A packet identical to the last applied one (or equal in the masked bytes when `mask` is set) cancels the pending change (the glitch reverted) and is re-published immediately.
- The first matched packet after boot is applied immediately.
- The first state change received right after the entity's own command (within the debounce time of the transmission) is applied immediately, so command results are not delayed even without `optimistic`. Polling (`command_update`) does not trigger this, and a packet identical to the last applied state does not consume it. Only the first state change after the entity's latest transmitted command is immediate: when several commands from one entity go out back-to-back without `ack`, later results are debounced normally. The bypass is armed by commands from the entity's normal command queue (control actions), so a user lambda that periodically calls `enqueue_tx_cmd` would keep it armed.
- The first state change received right after the entity's own command (within the debounce time of the transmission) is applied immediately, so command results are not delayed even with `optimistic: false`. Polling (`command_update`) does not trigger this, and a packet identical to the last applied state does not consume it. Only the first state change after the entity's latest transmitted command is immediate: when several commands from one entity go out back-to-back without `ack`, later results are debounced normally. The bypass is armed by commands from the entity's normal command queue (control actions), so a user lambda that periodically calls `enqueue_tx_cmd` would keep it armed.
- `state_response` handling is not delayed.
- Commands from Home Assistant are still reflected immediately through `control` / `optimistic`; only changes observed on the bus are delayed, by up to the debounce time.
- With `optimistic: true` (default), commands from Home Assistant are still reflected immediately through `control`; with `optimistic: false` they are reflected only when state feedback arrives. Changes observed on the bus are delayed by up to the debounce time.
- A command with `preserve_state` waits while a change is pending (typically up to the debounce time; longer if bytes in the packet keep changing), because the stored state is not yet settled.
- `0` (default) disables debouncing; the maximum is `60s`.

Expand Down
6 changes: 5 additions & 1 deletion components/uartex/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,10 +542,14 @@ def _validate_entity_state_debounce(config):
cv.Optional(CONF_COMMAND_OFF): cv.templatable(command_hex_schema),
cv.Optional(CONF_COMMAND_UPDATE): cv.templatable(lambda value: reject_update_copy(command_hex_schema(value))),
cv.Optional(CONF_STATE_RESPONSE): state_schema,
cv.Optional(CONF_OPTIMISTIC, default=False): cv.boolean,
cv.Optional(CONF_STATE_DEBOUNCE, default='0ms'): state_debounce_schema,
}).extend(cv.polling_component_schema('60s')).add_extra(_validate_entity_preserve_state).add_extra(_validate_entity_state_debounce)

# Extend this only in controllable platforms where optimistic has an effect.
UARTEX_OPTIMISTIC_SCHEMA = cv.Schema({
cv.Optional(CONF_OPTIMISTIC, default=True): cv.boolean,
})

STATE_NUM_SCHEMA = cv.Schema({
cv.Required(CONF_OFFSET): cv.int_range(min=0, max=128),
cv.Optional(CONF_LENGTH, default=1): cv.int_range(min=1, max=16),
Expand Down
2 changes: 1 addition & 1 deletion components/uartex/climate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def validate_custom_modes(value):
cv.Optional(CONF_SENSOR): cv.use_id(sensor.Sensor),
cv.Optional(CONF_CUSTOM_FAN_MODE): validate_custom_modes,
cv.Optional(CONF_CUSTOM_PRESET): validate_custom_modes,
}).extend(uartex.UARTEX_DEVICE_SCHEMA).extend({
}).extend(uartex.UARTEX_DEVICE_SCHEMA).extend(uartex.UARTEX_OPTIMISTIC_SCHEMA).extend({
cv.Optional(CONF_STATE_TEMPERATURE_CURRENT): cv.templatable(state_num_schema),
cv.Optional(CONF_STATE_TEMPERATURE_TARGET): cv.templatable(state_num_schema),
cv.Optional(CONF_STATE_HUMIDITY_CURRENT): cv.templatable(state_num_schema),
Expand Down
Loading