|
买了一台杂牌的电动升降桌,通过逻辑分析仪,分析得出,当控制器T口发出特定的信号,同时促发另外一个口为高电平的时候,升降桌能够控制。但是在不控制的时候,升降桌也会有数据不断的在传送。网上找了一段乐歌升降桌的控制代码。有没有哪位指导一下,怎样修改代码才能实现我想要的功能。 比如说升的时候,发送指令0x9b, 0x06, 0x02, 0x10, 0x00,这个指令需要每隔11ms发送一次,不间断的发送,桌子就会一直上升,同时把另外一口设置成高电平,就可以实现升。要停止上升的话,只要回复成默认的指令,但是esphome的代码不会写,有人能帮一下忙吗?
substitutions:
device_name: Flexispot E5B
name: flexispot_e5b
min_height: "73.6" # Min height + 0.1
max_height: "122.9" # Max height - 0.1
esphome:
name: ${name}
comment: ${device_name}
platform: ESP8266 # TODO Change to your platform
board: nodemcuv2 # TODO Change to your board
includes:
- desk_height_sensor.h
captive_portal:
# Enable logging
logger:
#level: DEBUG
baud_rate: 0
# Enable Home Assistant API
api:
ota:
wifi:
ssid: "NoNameHome"
password: "abcdef790929"
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "chuangkexiaoxian"
password: "123456789"
uart:
- id: desk_uart
baud_rate: 9600
tx_pin: D5
rx_pin: D6
sensor:
- platform: wifi_signal
name: "WiFi Signal"
update_interval: 60s
- platform: uptime
name: Uptime
- platform: custom
lambda: |-
auto desk_height_sensor = new DeskHeightSensor(id(desk_uart));
App.register_component(desk_height_sensor);
return {desk_height_sensor};
sensors:
id: "desk_height"
name: Desk Height
unit_of_measurement: cm
accuracy_decimals: 1
icon: "mdi:counter"
switch:
- platform: gpio
name: "Virtual Screen"
pin:
number: D2
mode: OUTPUT
restore_mode: ALWAYS_ON
internal: true
- platform: uart
name: "Preset 1"
id: switch_preset1
icon: mdi:numeric-1-box
data: [0x9b, 0x06, 0x02, 0x04, 0x00, 0xac, 0xa3, 0x9d]
uart_id: desk_uart
- platform: uart
name: "Preset 2"
id: switch_preset2
icon: mdi:numeric-2-box
data: [0x9b, 0x06, 0x02, 0x08, 0x00, 0xac, 0xa6, 0x9d]
uart_id: desk_uart
- platform: uart
name: "Preset 3"
id: switch_preset3
icon: mdi:numeric-3-box
data: [0x9b, 0x06, 0x02, 0x10, 0x00, 0xac, 0xac, 0x9d]
uart_id: desk_uart
- platform: uart
name: "Up"
id: switch_up
icon: mdi:arrow-up-bold
data: [0x9b, 0x06, 0x02, 0x01, 0x00, 0xfc, 0xa0, 0x9d]
uart_id: desk_uart
internal: true
- platform: uart
name: "Down"
id: switch_down
icon: mdi:arrow-down-bold
data: [0x9b, 0x06, 0x02, 0x02, 0x00, 0x0c, 0xa0, 0x9d]
uart_id: desk_uart
internal: true
- platform: uart
name: "M"
id: switch_m
icon: mdi:alpha-m-circle
data: [0x9b, 0x06, 0x02, 0x20, 0x00, 0xac, 0xb8, 0x9d]
uart_id: desk_uart
- platform: uart
name: "(wake up)" # Not available on all control panels
id: switch_wake_up
icon: mdi:gesture-tap-button
data: [0x9b, 0x06, 0x02, 0x00, 0x00, 0x6c, 0xa1, 0x9d]
uart_id: desk_uart
cover:
- platform: template
# icon: mdi:table-chair
# icon: mdi-human-male-height-variant
name: "Desk"
assumed_state: true
# Move desk up
open_action:
- while:
condition:
sensor.in_range:
id: desk_height
below: ${max_height}
then:
- logger.log: "Executing up command"
- switch.turn_on: switch_up
- delay: 10ms
# Move desk down
close_action:
- while:
condition:
sensor.in_range:
id: desk_height
above: ${min_height}
then:
- logger.log: "Executing down command"
- switch.turn_on: switch_down
- delay: 10ms
optimistic: true
|
|