『瀚思彼岸』» 智能家居技术论坛

 找回密码
 立即注册
12
返回列表 发新帖
楼主: hcfong2020

[技术探讨] 升降桌改造方案的设想,望大佬指点

[复制链接]

34

主题

310

帖子

1432

积分

金牌会员

Rank: 6Rank: 6

积分
1432
金钱
1122
HASS币
0
 楼主| 发表于 2024-5-23 20:31:45 | 显示全部楼层
crazymouse 发表于 2024-5-23 10:17
一个升降桌,为啥需要远程控制?我实在搞不懂

应用场景是,这个桌子是放在幕布前的,平时使用的时候是75厘米高度,当幕布下降的时候,自动下降到50,只为了这个功能。懒人一个,比如说启动娱乐模式,先降下幕布,打开电视,降下升降桌,关闭灯光。
回复

使用道具 举报

34

主题

310

帖子

1432

积分

金牌会员

Rank: 6Rank: 6

积分
1432
金钱
1122
HASS币
0
 楼主| 发表于 2024-5-23 20:32:53 | 显示全部楼层
kjjuhfv 发表于 2024-5-23 15:09
既然知道p口高电平时上升  
那你直接在p口输入高电平看会不会上升
如果会上升那就不需要发射16进制代码了 ...

下降的时候P口也是高电平。平时无动作的时候是低电平。
回复

使用道具 举报

4

主题

266

帖子

2465

积分

金牌会员

Rank: 6Rank: 6

积分
2465
金钱
2199
HASS币
0
发表于 2024-5-24 11:28:39 | 显示全部楼层
hcfong2020 发表于 2024-5-23 20:31
应用场景是,这个桌子是放在幕布前的,平时使用的时候是75厘米高度,当幕布下降的时候,自动下降到50,只 ...

哈哈,我懂,和我最初玩物联网的时候一样,希望一切都自动化,然后最后发现,一个人住还好,一家人的话,大家的习惯不一样,很难
回复

使用道具 举报

4

主题

266

帖子

2465

积分

金牌会员

Rank: 6Rank: 6

积分
2465
金钱
2199
HASS币
0
发表于 2024-5-24 11:34:35 | 显示全部楼层

就是所谓的你是为了鱼呢,还是为了钓鱼
回复

使用道具 举报

4

主题

33

帖子

76

积分

注册会员

Rank: 2

积分
76
金钱
43
HASS币
0
发表于 2024-5-25 22:27:27 | 显示全部楼层
坐等实现学习,我想做一个自动投影抽屉
回复

使用道具 举报

34

主题

310

帖子

1432

积分

金牌会员

Rank: 6Rank: 6

积分
1432
金钱
1122
HASS币
0
 楼主| 发表于 2024-6-2 16:12:47 | 显示全部楼层
本帖最后由 hcfong2020 于 2024-6-2 16:15 编辑
substitutions:
  friendly_name: 'Seisuk'
  device_name: 'seisuk'
  node_name: 'seisuk'
  device_description: 'Seisuk AOKE WP-H01 WP-CB01-001 Desktronic/JSDRIVE DCU_G-PRT5G'
  project_base: 'AOKE' # https://aoke-europe.com/troubleshooting
  project_name: 'WP-H01' # panel
  project_version: 'WP-CB01-001' # control box # https://aoke-europe.com/mwdownloads/download/link/id/88/

    # https://profeqprofessional.nl/media/productattach//e/r/error_codes_wp-cb01-001_2.pdf
    # https://motionwise-products.com/wp-content/uploads/2018/11/MotionWise_sf_Manual_081318_E_Rev-USB.pdf
    # https://profeqprofessional.nl/media/productattach//e/r/error_codes_wp-cb01-001_2.pdf

  min_height: "50.0" # real 65  # Min height + 0.5
  max_height: "100.0" # real 130  # Max height - 0.5
  initial_value: "70"

globals:
  - id: height
    type: float
    restore_value: yes
    initial_value: '70.0'

  - id: min_height
    type: float
    restore_value: yes
    initial_value: '50.0'

  - id: max_height
    type: float
    restore_value: yes
    initial_value: '100.0'

esphome:
  name: ${device_name}
  friendly_name: ${friendly_name}
  name_add_mac_suffix: false
  comment: ${device_description}
  project:
    name: ${project_base}.${project_name}
    version: $project_version
  on_boot:
    - priority: 600.0 
      then:
        - button.press: stop
    - priority: -200.0 
      then:
        - lambda: |-
            id(uart_height).publish_state( id(height) );

api:
web_server:
  port: 80
wifi:
  ssid: "XXXXXXXX"
  password: "XXXXXXXX"



  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "P1Test Fallback Hotspot"
    password: "12345678"

esp8266:
  board: nodemcu
  early_pin_init: false
  restore_from_flash: true

# packages:
#   device_base: !include common/device.base.yaml

ota:
  on_begin:
    then:
      - button.press: stop

logger:
  esp8266_store_log_strings_in_flash: false  
  level: DEBUG
  baud_rate: 0

uart:
  - id: remote_bus
    tx_pin: 1 # WHITE (2nd pin)
    rx_pin: 3 # N/A (3rd pin)
    baud_rate: 9600

  - id: desk_bus
    tx_pin: 4 # N/A (D2)
    rx_pin: 5 # BLACK (D1) 
    baud_rate: 9600
    rx_buffer_size: 256

external_components:
  - source: veli
    components: [ desktronic ]  

desktronic:
  id: seisuk
  desk_uart: desk_bus
  remote_uart: remote_bus
  height:
    name: Wnotworkign desktronic Height
    id: desk_height_sensor
    icon: mdi:human-male-height
    device_class: distance
    unit_of_measurement: cm
    accuracy_decimals: 1    
    internal: true
  move_pin:
    number: 14 # (D5)

binary_sensor:
  - id: moving
    name: Moving
    platform: template
    device_class: moving
    icon: mdi:hand-back-right-off
    lambda: return id(seisuk).current_operation != desktronic::DESKTRONIC_OPERATION_IDLE;
    on_state:
      - while:
          condition:
            binary_sensor.is_on: moving
          then:
            - script.execute: get_debug_height
            - delay: 50ms

  - id: going_up
    name: Moving up
    platform: template
    device_class: moving
    icon: mdi:transfer-up
    entity_category: diagnostic
    lambda: return (id(seisuk).current_operation == desktronic::DESKTRONIC_OPERATION_RAISING) || (id(seisuk).current_operation == desktronic::DESKTRONIC_OPERATION_UP);

  - id: going_down
    name: Moving down
    platform: template
    device_class: moving
    icon: mdi:transfer-down
    entity_category: diagnostic
    lambda: return (id(seisuk).current_operation == desktronic::DESKTRONIC_OPERATION_LOWERING) || (id(seisuk).current_operation == desktronic::DESKTRONIC_OPERATION_DOWN);

sensor:
  - id: uart_height
    platform: template
    name: Height
    icon: mdi:human-male-height
    device_class: distance
    unit_of_measurement: cm
    accuracy_decimals: 1
    update_interval: never
    lambda: |-
      float current = id(height);
      return current;

number:
  - platform: template
    id: desk_height
    name: Height
    icon: mdi:human-male-height-variant
    min_value: $min_height
    max_value: $max_height
    lambda: |-
      return id(height);
    device_class: distance
    unit_of_measurement: cm
    update_interval: never
    mode: box
    step: 0.1
    set_action:
      then:
        - while:
            condition: 
              - lambda: |-
                  float to = std::round(x * 10) / 10;
                  float from = std::round(id(height) * 10) / 10;
                  if ( to != from ) {
                    return true;
                  }
                  else{
                    return false;
                  }
            then:
              - script.execute: 
                  id: move_it
                  to: !lambda 'return x;'
              - delay: 150ms

cover:
  - platform: template
    name: None
    optimistic: true
    device_class: damper
    icon: mdi:desk
    assumed_state: true
    has_position: true    
    lambda: |-
      auto value = (int)id(height);
      float percentage = (float)(value - id(min_height)) / (id(max_height) - id(min_height));
      return percentage;
    open_action:
      - number.set:
          id: desk_height
          value: $max_height
    close_action:
      - number.set:
          id: desk_height
          value: $min_height
    stop_action:
      - button.press: stop
    position_action:
      - number.set:
          id: desk_height
          value: !lambda |-
            int value = id(min_height) + (int)( ( pos ) * (id(max_height) - id(min_height)) );
            return value;

button:
  - platform: template
    name: Stop
    icon: mdi:stop
    entity_category: config
    id: stop
    on_press:
      then:
        - switch.turn_off: takeover
        - script.stop: move_it
        - switch.turn_off: switch_up
        - switch.turn_off: switch_down
        - lambda: |-
            id(seisuk).stop();
        - number.set: 
            id: desk_height
            value: !lambda |-
              float x = id(height);
              return x;
        - component.update: desk_height

switch:
 - platform: gpio
   name: Takeover
   icon: mdi:gesture-tap
   id: takeover
   pin:
     number: 2 # (D4)
     mode: OUTPUT 
   restore_mode:  ALWAYS_OFF   
   entity_category: diagnostic
   disabled_by_default: true
   on_turn_on:
    then:
      - delay: 50ms
      - switch.turn_off: takeover

 - platform: template
   optimistic: true
   name: Move Up
   entity_category: config
   restore_mode: ALWAYS_OFF
   icon: mdi:arrow-up-bold-box
   id: switch_up
   on_turn_on:
     then:
       - switch.turn_on: takeover
       - switch.turn_off: switch_down
       - lambda: |-
           id(seisuk).move_up();
   on_turn_off:
     then:
       button.press: stop
 
 - platform: template
   name: Move Down
   entity_category: config
   restore_mode: ALWAYS_OFF
   optimistic: true
   icon: mdi:arrow-down-bold-box
   id: switch_down
   on_turn_on:
     then:
       - switch.turn_on: takeover
       - switch.turn_off: switch_up #  interlock: [up]
       - lambda: |-
           id(seisuk).move_down();
   on_turn_off:
     then:
       button.press: stop

script:
  - id: move_it
    parameters:
      to: float
    mode: restart
    then:
      - if:
          condition:
              - binary_sensor.is_off: moving
          then:
            - lambda: |-
                float target = std::round(to * 10) / 10;
                float from = std::round(id(height) * 10) / 10;
      
                ESP_LOGI("seisuk", "target %.1f from %.1f", target, from);
      
                if ( target != from ) {  
                  if ( target < from ) { 
                    id(switch_down).turn_on();
                  }
                  else if ( target > from ) {
                    id(switch_up).turn_on();
                  }
                  else if ( target == from ) {
                    id(stop).press();
                    ESP_LOGI("seisuk", "target == from");
                  }          
                  else {
                    id(stop).press();
                    ESP_LOGI("seisuk", "else height same");
                  }
                }
                else{
                  id(stop).press();
                  ESP_LOGI("seisuk", "height not not same");
                }
          else:
          - if:
              condition:
                  - binary_sensor.is_on: going_up 
              then:
              - lambda: |-
                  float target = std::round(to * 10) / 10;
                  float from = std::round(id(uart_height).state * 10) / 10;

                  ESP_LOGI("seisuk", "moving to %.1f from %.1f", target, from);

                  if ( target <= from ) { 
                    id(stop).press();
                    ESP_LOGE("seisuk", "height more");

                    auto call = id(desk_height).make_call();
                    call.set_value(id(uart_height).state);
                    call.perform();                  
                  }
          - if:
              condition:
                  - binary_sensor.is_on: going_down
              then:
              - lambda: |-
                  float target = std::round(to * 10) / 10;
                  float from = std::round(id(uart_height).state * 10) / 10;

                  ESP_LOGI("seisuk", "moving to %.1f from %.1f", target, from);

                  if ( target >= from ) { 
                    id(stop).press();
                    ESP_LOGE("seisuk", "height less");

                    auto call = id(desk_height).make_call();
                    call.set_value(id(uart_height).state);
                    call.perform();                  
                  }
      - delay: 100ms

  - id: get_debug_height
    mode: single
    then: 
      - lambda: |- 

          // before continuing tell its not really moving

          // id(moving).publish_state(false);
          // id(going_up).publish_state(false);
          // id(going_down).publish_state(false);

          uint8_t data[5];
          while (id(desk_bus).available() >= 5) {

            id(desk_bus).read_array(data, 5);
            if (data[0] != 0x5A) {
              break;
            }
            if ((data[1] | data[2] | data[3]) == 0x00) {
              break;
            }

            enum Segment : uint8_t
            {
                SEGMENT_INVALID = 0x00,
                SEGMENT_0 = 0x3f,
                SEGMENT_1 = 0x06,
                SEGMENT_2 = 0x5b,
                SEGMENT_3 = 0x4f,
                SEGMENT_4 = 0x67,
                SEGMENT_5 = 0x6d,
                SEGMENT_6 = 0x7d,
                SEGMENT_7 = 0x07,
                SEGMENT_8 = 0x7f,
                SEGMENT_9 = 0x6f,
            };
          
            auto segment_to_number = [](const uint8_t segment) {
                switch (segment & 0x7f)
                {
                case SEGMENT_0:
                    return 0;
                case SEGMENT_1:
                    return 1;
                case SEGMENT_2:
                    return 2;
                case SEGMENT_3:
                    return 3;
                case SEGMENT_4:
                    return 4;
                case SEGMENT_5:
                    return 5;
                case SEGMENT_6:
                    return 6;
                case SEGMENT_7:
                    return 7;
                case SEGMENT_8:
                    return 8;
                case SEGMENT_9:
                    return 9;
                default:
                    ESP_LOGD("desktronic", "idk");
                }
                return -1;
            };            

            int data0 = segment_to_number(data[1]);
            int data1 = segment_to_number(data[2]);
            int data2 = segment_to_number(data[3]);

            float got_height = 0.0;

            if (data0 < 0x00 || data1 < 0x00 || data2 < 0x00) {
              break;
            }

            got_height = data0 * 100 + data1 * 10 + data2; // + decimal * 0.1;

            // flip height for below 100
            if (data[2] & 0x80 ) { 
              got_height /= 10.0;
            }
            
            // If all correct, publish values
            if (got_height <= id(max_height) - 0.5 && got_height >= id(min_height) + 0.5 ){
              id(height) = got_height;
              id(uart_height).publish_state(got_height);              
            }

            if (got_height >= id(max_height) || got_height <= id(min_height) ){
              // id(stop).press();
              ESP_LOGE("seisuk","stopped, out of bounds");
            }

            // now its moving
            // id(moving).publish_state(true);
            // id(going_up).publish_state(true);
            // id(going_down).publish_state(true);            

          }
      - delay: 50ms

veli.zip (25.74 KB, 下载次数: 0)

用这个代码现在能够控制升降,不过还是有很多问题。
回复

使用道具 举报

34

主题

310

帖子

1432

积分

金牌会员

Rank: 6Rank: 6

积分
1432
金钱
1122
HASS币
0
 楼主| 发表于 2024-6-2 16:30:44 | 显示全部楼层
萌萌之家 发表于 2024-5-23 10:50
一个升降桌,你发三个帖子?我实在搞不懂

不是发三个帖子,是因为上传图片的时候,提示错误,又重新编辑了。所以帖子变多了。也不知道怎么删除。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-6-22 18:31 , Processed in 0.108475 second(s), 29 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表