请选择 进入手机版 | 继续访问电脑版

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

 找回密码
 立即注册
查看: 259|回复: 4

[求助] esphome红外接收代码,死循环,咋解

[复制链接]

24

主题

297

帖子

2121

积分

金牌会员

Rank: 6Rank: 6

积分
2121
金钱
1824
HASS币
0
发表于 2025-3-9 21:58:48 | 显示全部楼层 |阅读模式
本帖最后由 kaka0992 于 2025-3-9 22:06 编辑

问了gpt、deepseek、都解决不了,一直兜圈子
ota:
  platform: esphome
  

wifi:
  ssid: 111
  password:  111
  fast_connect: on

web_server:
  port: 80

uart:
  rx_pin: 5
  tx_pin: 6
  baud_rate: 256000
  parity: NONE
  stop_bits: 1

ld2410:
number:
  - platform: ld2410
    timeout:
      name: timeout
    light_threshold:
      name: light threshold
    max_move_distance_gate:
      name: max move distance gate
    max_still_distance_gate:
      name: max still distance gate



sensor:
  - platform: ld2410
    light:
      name: light
    moving_distance:
      name : Moving Distance
    still_distance:
      name: Still Distance
    moving_energy:
      name: Move Energy
    still_energy:
      name: Still Energy
    detection_distance:
      name: Detection Distance
  - platform: adc
    pin: 3
    # 环境亮度
    name: ${device_name}_brightness
    attenuation: 11db
    update_interval: 5s
    unit_of_measurement: "%"
    icon: mdi:brightness-6
    accuracy_decimals: 0
    filters:
      - lambda: |-
          return ( 3 - x ) / 0.03;

button:
  - platform: template
    # 红外发送 demo
    name: ${device_name}_tv_on_off
    on_press:
      - remote_transmitter.transmit_raw:
          carrier_frequency: 38kHz
          code:
            [
              9045,
              -4500,
              585,
              -520,
              578,
              -527,
              580,
              -525,
              578,
              -527,
              586,
              -518,
              579,
              -525,
              580,
              -525,
              585,
              -519,
              569,
              -1641,
              583,
              -1626,
              585,
              -1624,
              580,
              -1628,
              586,
              -1677,
              579,
              -1630,
              580,
              -526,
              583,
              -1625,
              586,
              -1623,
              586,
              -519,
              586,
              -1622,
              582,
              -1628,
              587,
              -518,
              580,
              -524,
              585,
              -520,
              586,
              -519,
              584,
              -520,
              585,
              -1650,
              584,
              -521,
              588,
              -517,
              580,
              -1630,
              584,
              -1624,
              585,
              -1624,
              586,
              -1623,
              585,
            ]



binary_sensor:
  - platform: ld2410
    has_target:
      name: Presence
    has_moving_target:
      name: Moving Target
    has_still_target:
      name: Still Target
    out_pin_presence_status:
      name: out pin presence status
  - platform: gpio
    pin: 4
    name: "${device_name} PIR Motion Sensor"
    device_class: motion
  - platform: remote_receiver
    # 红外接收 demo
    name: ${device_name}_rr_b_1
    nec:
      address: 0xFF00
      command: 0xBA45



text_sensor:
  - platform: wifi_info
    ip_address:
      name: ${device_name}_ip
    mac_address:
      name: ${device_name}_mac

remote_transmitter:
  pin: 1
  carrier_duty_percent: 50%


light:
  - platform: neopixelbus
    type: GRB
    variant: WS2812
    pin: 2
    num_leds: 1
    name: "${device_name} NeoPixel Light"

##红外接收设置
remote_receiver:
  pin:
    number: 0
    inverted: True
    mode:
      input: True
      pullup: True
  dump: raw
 

错误提示
错误如下
INFO Compiling app...
Processing esp32-ld2410b (board: esp32-c3-devkitm-1; framework: arduino; platform: platformio/[email protected])
--------------------------------------------------------------------------------
HARDWARE: ESP32C3 160MHz, 320KB RAM, 4MB Flash
- toolchain-riscv32-esp @ 8.4.0+2021r2-patch5
Dependency Graph
|-- AsyncTCP-esphome @ 2.1.4
|-- WiFi @ 2.0.0
|-- FS @ 2.0.0
|-- Update @ 2.0.0
|-- ESPAsyncWebServer-esphome @ 3.2.2
|-- ESPmDNS @ 2.0.0
|-- ArduinoJson @ 6.18.5
|-- NeoPixelBus @ 2.7.3
Compiling .pioenvs/esp32-ld2410b/src/main.cpp.o
/config/esphome/esp32-ld2410b.yaml: In function 'void setup()':
/config/esphome/esp32-ld2410b.yaml:46:63: error: no matching function for call to 'esphome::remote_receiver::RemoteReceiverComponent::set_tolerance(int)'
baud_rate: 256000
^
In file included from src/esphome/components/remote_base/abbwelcome_protocol.h:5,
from src/esphome.h:68,
from src/main.cpp:3:
src/esphome/components/remote_base/remote_base.h:210:8: note: candidate: 'void esphome::remote_base::RemoteReceiverBase::set_tolerance(uint32_t, esphome::remote_base::ToleranceMode)'
void set_tolerance(uint32_t tolerance, ToleranceMode tolerance_mode) {
^~~~~~~~~~~~~
src/esphome/components/remote_base/remote_base.h:210:8: note: candidate expects 2 arguments, 1 provided
*** [.pioenvs/esp32-ld2410b/src/main.cpp.o] Error 1
========================= [FAILED] Took 10.43 seconds =========================


然后


我把代码改成这样
remote_receiver:
  pin:
    number: 0
    inverted: True
    mode:
      input: True
      pullup: True
  dump: raw
  tolerance: 50
  tolerance_mode: percent
又提示我
remote_receiver: [source /config/esphome/esp32-ld2410b.yaml:215]
  - pin: 
      number: 0
      inverted: True
      mode: 
        input: True
        pullup: True
    dump: raw
    tolerance: 50
    
    [tolerance_mode] is an invalid option for [remote_receiver]. Did you mean [tolerance]?
    tolerance_mode: percent
回复

使用道具 举报

24

主题

638

帖子

3033

积分

论坛元老

Rank: 8Rank: 8

积分
3033
金钱
2395
HASS币
0
发表于 2025-3-9 22:49:30 | 显示全部楼层
随便改了一下  可以编译了


uart:
  rx_pin: 5
  tx_pin: 6
  baud_rate: 256000
  parity: NONE
  stop_bits: 1

ld2410:
number:
  - platform: ld2410
    timeout:
      name: timeout
    light_threshold:
      name: light threshold
    max_move_distance_gate:
      name: max move distance gate
    max_still_distance_gate:
      name: max still distance gate



sensor:
  - platform: ld2410
    light:
      name: light
    moving_distance:
      name : Moving Distance
    still_distance:
      name: Still Distance
    moving_energy:
      name: Move Energy
    still_energy:
      name: Still Energy
    detection_distance:
      name: Detection Distance
  - platform: adc
    pin: 3
    # 环境亮度
    name: ${device_name}_brightness
    attenuation: 11db
    update_interval: 5s
    unit_of_measurement: "%"
    icon: mdi:brightness-6
    accuracy_decimals: 0
    filters:
      - lambda: |-
          return ( 3 - x ) / 0.03;

button:
  - platform: template
    # 红外发送 demo
    name: ${device_name}_tv_on_off
    on_press:
      - remote_transmitter.transmit_raw:
          carrier_frequency: 38kHz
          code:
            [
              9045,
              -4500,
              585,
              -520,
              578,
              -527,
              580,
              -525,
              578,
              -527,
              586,
              -518,
              579,
              -525,
              580,
              -525,
              585,
              -519,
              569,
              -1641,
              583,
              -1626,
              585,
              -1624,
              580,
              -1628,
              586,
              -1677,
              579,
              -1630,
              580,
              -526,
              583,
              -1625,
              586,
              -1623,
              586,
              -519,
              586,
              -1622,
              582,
              -1628,
              587,
              -518,
              580,
              -524,
              585,
              -520,
              586,
              -519,
              584,
              -520,
              585,
              -1650,
              584,
              -521,
              588,
              -517,
              580,
              -1630,
              584,
              -1624,
              585,
              -1624,
              586,
              -1623,
              585,
            ]



binary_sensor:
  - platform: ld2410
    has_target:
      name: Presence
    has_moving_target:
      name: Moving Target
    has_still_target:
      name: Still Target
    out_pin_presence_status:
      name: out pin presence status
  - platform: gpio
    pin: 11
    name: "${device_name} PIR Motion Sensor"
    device_class: motion
  - platform: remote_receiver
    # 红外接收 demo
    name: ${device_name}_rr_b_1
    nec:
      address: 0xFF00
      command: 0xBA45


text_sensor:
  - platform: wifi_info
    ip_address:
      name: ${device_name}_ip
    mac_address:
      name: ${device_name}_mac

remote_transmitter:
  pin: 8
  carrier_duty_percent: 50%


light:
  - platform: neopixelbus
    type: GRB
    variant: WS2812
    pin: 2
    num_leds: 1
    name: "${device_name} NeoPixel Light"

##红外接收设置
remote_receiver:
  pin:
    number: 9
    inverted: True
  dump: raw
 

回复

使用道具 举报

24

主题

297

帖子

2121

积分

金牌会员

Rank: 6Rank: 6

积分
2121
金钱
1824
HASS币
0
 楼主| 发表于 7 天前 | 显示全部楼层
kjjuhfv 发表于 2025-3-9 22:49
随便改了一下  可以编译了

朋友能帮忙编译下吗(pin 口不要换),我换了个树莓派也不行
substitutions:
  device_name: esp32-ld2410b 

esphome:
  name: ${device_name}

external_components:
  - source: 
      type: local
      path: ./remote_receiver/components

esp32:
  board: esp32-c3-devkitm-1
  framework:
    type: arduino

logger:

# Enable Home Assistant API
api:
  services:
    - service: send_raw_command
      variables:
        command: int[]
      then:
        - delay: 1s
        - remote_transmitter.transmit_raw:
            code: !lambda 'return command;'
            carrier_frequency: 38kHz

ota:
  platform: esphome
  

wifi:
  ssid: zigbee
  password: huc849a1
  fast_connect: on

web_server:
  port: 80




uart:
  rx_pin: 5
  tx_pin: 6
  baud_rate: 256000
  parity: NONE
  stop_bits: 1

ld2410:
number:
  - platform: ld2410
    timeout:
      name: timeout
    light_threshold:
      name: light threshold
    max_move_distance_gate:
      name: max move distance gate
    max_still_distance_gate:
      name: max still distance gate



sensor:
  - platform: ld2410
    light:
      name: light
    moving_distance:
      name : Moving Distance
    still_distance:
      name: Still Distance
    moving_energy:
      name: Move Energy
    still_energy:
      name: Still Energy
    detection_distance:
      name: Detection Distance
  - platform: adc
    pin: 3
    # 环境亮度
    name: ${device_name}_brightness
    attenuation: 11db
    update_interval: 5s
    unit_of_measurement: "%"
    icon: mdi:brightness-6
    accuracy_decimals: 0
    filters:
      - lambda: |-
          return ( 3 - x ) / 0.03;

button:
  - platform: template
    # 红外发送 demo
    name: ${device_name}_tv_on_off
    on_press:
      - remote_transmitter.transmit_raw:
          carrier_frequency: 38kHz
          code:
            [
              9045,
              -4500,
              585,
              -520,
              578,
              -527,
              580,
              -525,
              578,
              -527,
              586,
              -518,
              579,
              -525,
              580,
              -525,
              585,
              -519,
              569,
              -1641,
              583,
              -1626,
              585,
              -1624,
              580,
              -1628,
              586,
              -1677,
              579,
              -1630,
              580,
              -526,
              583,
              -1625,
              586,
              -1623,
              586,
              -519,
              586,
              -1622,
              582,
              -1628,
              587,
              -518,
              580,
              -524,
              585,
              -520,
              586,
              -519,
              584,
              -520,
              585,
              -1650,
              584,
              -521,
              588,
              -517,
              580,
              -1630,
              584,
              -1624,
              585,
              -1624,
              586,
              -1623,
              585,
            ]



binary_sensor:
  - platform: ld2410
    has_target:
      name: Presence
    has_moving_target:
      name: Moving Target
    has_still_target:
      name: Still Target
    out_pin_presence_status:
      name: out pin presence status
  - platform: gpio
    pin: 4
    name: "${device_name} PIR Motion Sensor"
    device_class: motion
  - platform: remote_receiver
    # 红外接收 demo
    name: ${device_name}_rr_b_1
    nec:
      address: 0xFF00
      command: 0xBA45



text_sensor:
  - platform: wifi_info
    ip_address:
      name: ${device_name}_ip
    mac_address:
      name: ${device_name}_mac

remote_transmitter:
  pin: 1
  carrier_duty_percent: 50%


light:
  - platform: neopixelbus
    type: GRB
    variant: WS2812
    pin: 2
    num_leds: 1
    name: "${device_name} NeoPixel Light"

##红外接收设置

remote_receiver:
  pin:
    number: 0
    inverted: True
    mode:
      input: True
      pullup: True
  dump: raw
  tolerance: 50  
回复

使用道具 举报

24

主题

638

帖子

3033

积分

论坛元老

Rank: 8Rank: 8

积分
3033
金钱
2395
HASS币
0
发表于 5 天前 | 显示全部楼层
kaka0992 发表于 2025-3-11 20:09
朋友能帮忙编译下吗(pin 口不要换),我换了个树莓派也不行

你的配置无法编译 我修改了一下 没有修改pin口
esphome:
  name: abc
  friendly_name: abc

esp32:
  board: esp32-c3-devkitm-1
  framework:
    type: arduino

# Enable logging
logger:


ota:
  - platform: esphome
    password: "6faf1ed5e129591f268ee67ce9a681f6"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

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

captive_portal:


# Enable Home Assistant API
api:
  services:
    - service: send_raw_command
      variables:
        command: int[]
      then:
        - delay: 1s
        - remote_transmitter.transmit_raw:
            code: !lambda 'return command;'
            carrier_frequency: 38kHz

web_server:
  port: 80


uart:
  rx_pin: 5
  tx_pin: 6
  baud_rate: 256000
  parity: NONE
  stop_bits: 1

ld2410:
number:
  - platform: ld2410
    timeout:
      name: timeout
    light_threshold:
      name: light threshold
    max_move_distance_gate:
      name: max move distance gate
    max_still_distance_gate:
      name: max still distance gate



sensor:
  - platform: ld2410
    light:
      name: light
    moving_distance:
      name : Moving Distance
    still_distance:
      name: Still Distance
    moving_energy:
      name: Move Energy
    still_energy:
      name: Still Energy
    detection_distance:
      name: Detection Distance
  - platform: adc
    pin: 3
    # 环境亮度
    name: ${device_name}_brightness
    attenuation: 11db
    update_interval: 5s
    unit_of_measurement: "%"
    icon: mdi:brightness-6
    accuracy_decimals: 0
    filters:
      - lambda: |-
          return ( 3 - x ) / 0.03;

button:
  - platform: template
    # 红外发送 demo
    name: ${device_name}_tv_on_off
    on_press:
      - remote_transmitter.transmit_raw:
          carrier_frequency: 38kHz
          code:
            [
              9045,
              -4500,
              585,
              -520,
              578,
              -527,
              580,
              -525,
              578,
              -527,
              586,
              -518,
              579,
              -525,
              580,
              -525,
              585,
              -519,
              569,
              -1641,
              583,
              -1626,
              585,
              -1624,
              580,
              -1628,
              586,
              -1677,
              579,
              -1630,
              580,
              -526,
              583,
              -1625,
              586,
              -1623,
              586,
              -519,
              586,
              -1622,
              582,
              -1628,
              587,
              -518,
              580,
              -524,
              585,
              -520,
              586,
              -519,
              584,
              -520,
              585,
              -1650,
              584,
              -521,
              588,
              -517,
              580,
              -1630,
              584,
              -1624,
              585,
              -1624,
              586,
              -1623,
              585,
            ]



binary_sensor:
  - platform: ld2410
    has_target:
      name: Presence
    has_moving_target:
      name: Moving Target
    has_still_target:
      name: Still Target
    out_pin_presence_status:
      name: out pin presence status
  - platform: gpio
    pin: 4
    name: "${device_name} PIR Motion Sensor"
    device_class: motion
  - platform: remote_receiver
    # 红外接收 demo
    name: ${device_name}_rr_b_1
    nec:
      address: 0xFF00
      command: 0xBA45



text_sensor:
  - platform: wifi_info
    ip_address:
      name: ${device_name}_ip
    mac_address:
      name: ${device_name}_mac

remote_transmitter:
  pin: 1
  carrier_duty_percent: 50%


light:
  - platform: neopixelbus
    type: GRB
    variant: WS2812
    pin: 2
    num_leds: 1
    name: "${device_name} NeoPixel Light"

##红外接收设置

remote_receiver:
  pin:
    number: 0
    inverted: True
    mode:
      input: True
      pullup: True
  dump: raw
回复

使用道具 举报

24

主题

297

帖子

2121

积分

金牌会员

Rank: 6Rank: 6

积分
2121
金钱
1824
HASS币
0
 楼主| 发表于 4 天前 | 显示全部楼层
kjjuhfv 发表于 2025-3-13 23:08
你的配置无法编译 我修改了一下 没有修改pin口

好的好的 感谢
回复

使用道具 举报

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

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2025-3-18 06:04 , Processed in 0.061367 second(s), 26 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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