esphome / issues

Issue Tracker for ESPHome
https://esphome.io/
291 stars 34 forks source link

on_rc_switch can only be used with the predefined protocols #5538

Open gabest11 opened 4 months ago

gabest11 commented 4 months ago

The problem

Under the binary_sensor / rc_switch_raw we can define our own rcswitch protocol, but cannot use the code value, it's just a binary_sensor afterall.

Under remote_receiver / on_rc_switch we can get the code and the protocol number, but only one of the predefined 9 protocols gets there.

If all the user defined protocols were included, then it would be possible to catch more codes with changing bitfields, like weather stations or rolling codes, and report them through template sensors.

Which version of ESPHome has the issue?

2023.9.3

What type of installation are you using?

Docker

Which version of Home Assistant has the issue?

2024.1.6

What platform are you using?

ESP32

Board

nodemcu

Component causing the issue

remote_receiver

Example YAML snippet

remote_receiver:
  pin: GPIO32
  dump:
    - rc_switch
  tolerance: 50%
  buffer_size: 2kb
  filter: 250us
  idle: 4ms
  on_rc_switch: # only predefined protocols, not the one below
    - logger.log:
        format: "on_rc_switch: %i %llu"
        args: [x.protocol, x.code]
    - lambda: |- 
        if(matches) id(some_sensor).publish_state(extracted bits);

binary_sensor:
  - platform: remote_receiver
    name: "auriol rc weather station with rain gauge"
    internal: true
    on_press:
      - lambda: |-
          ESP_LOGD("rc_switch", "auriol rc weather station with rain gauge");
    rc_switch_raw:
      # ID(8)BATTERY(1)0(1)CHANNEL(2)TEMP_C(12)1(4)RAIN(24)
      code: 'xxxxxxxxx0xxxxxxxxxxxxxx1111xxxxxxxxxxxxxxxxxxxxxxxx'
      protocol: # yes, this catches it, PPM, same ON time, different OFF time
        pulse_length: 49
        sync: [10,81]
        zero: [10,21]
        one: [10,41]
        inverted: false
    filters:
      - delayed_off: 1000ms

Anything in the logs that might be useful for us?

No response

Additional information

No response

ssieb commented 4 months ago

This is a feature request, not an issue. I don't understand what you're asking for. The on_rc_switch will be called for any rc_switch message regardless of protocol.

gabest11 commented 4 months ago

Then that's my issue. It isn't called.

ssieb commented 4 months ago

Show your actual config and the logs.

gabest11 commented 4 months ago
substitutions:
  plug_name: cc1101_test_esp32

external_components:
  - source:
      type: local
      path: components

packages:
  api: !include packages/api_zsibi4.yaml
  #mqtt: !include packages/mqtt_zsibi4.yaml
  wifi: !include packages/wifi_zsibi4.yaml
  info: !include packages/device_info.yaml

esphome:
  name: ${plug_name}

esp32:
  board: nodemcu-32s
  variant: esp32
  framework:
    type: arduino
    #type: esp-idf
    #version: recommended

logger:
#  level: DEBUG
  level: VERBOSE
#  level: VERY_VERBOSE
#  level: NONE

ota:
  password: !secret every_password

spi:
  clk_pin: 18
  miso_pin: 19
  mosi_pin: 23

switch:
  - platform: cc1101
    name: "${plug_name} cc1101"
    id: transceiver
    cs_pin: 5
    gdo0: 32
    gdo2: 33
    bandwidth: 200
    frequency: 433920

remote_transmitter:
  - pin: GPIO32 # This is GDO0
    carrier_duty_percent: 100%

remote_receiver:
  pin: GPIO33 # This is GDO2
  dump:
    - rc_switch
    #- raw
  # Settings to optimize recognition of RF devices
  tolerance: 50%
  #buffer_size: 2kb
  filter: 250us
  idle: 4ms
  on_rc_switch:
#    - lambda: |-
#        ESP_LOGD("rc_switch", "protocol = %d, code = '%llu'", x.protocol, x.code);
    - logger.log:
        format: "on_rc_switch: %i %llu"
        args: [x.protocol, x.code]

binary_sensor:

  - platform: remote_receiver
    name: "${plug_name} lidl auriol rc weather station with rain gauge"
    internal: true
    on_press:
      - lambda: |-
          ESP_LOGD("rc_switch", "lidl auriol rc weather station with rain gauge");
    rc_switch_raw:
      # ID(8)BATTERY(1)0(1)CHANNEL(2)TEMP_C(12)1(4)RAIN(24)
      # code: 'xxxxxxxxx0xxxxxxxxxxxxxx1111xxxxxxxxxxxxxxxxxxxxxxxx'
      code: '1111000010000000xxxxxxxx111100000000xxxxxxxxxxxxxxxx'
      protocol:
        pulse_length: 49
        sync: [10,81]
        zero: [10,21]
        one: [10,41]
        inverted: false
    filters:
      - delayed_off: 1000ms

  - platform: remote_receiver
    internal: true
    name: "${plug_name} window"
    rc_switch_raw:
      code: '000101101011000000100110'
    filters:
      - delayed_off: 1000ms      

INFO ESPHome 2023.9.3
INFO Reading configuration /config/cc1101_test_esp32.yaml...
WARNING 'cc1101_test_esp32': Using the '_' (underscore) character in the hostname is discouraged as it can cause problems with some DHCP and local name services. For more information, see https://esphome.io/guides/faq.html#why-shouldn-t-i-use-underscores-in-my-device-name
INFO Starting log output from cc1101_test_esp32.local using esphome API
INFO Successfully connected to cc1101_test_esp32.local
[23:43:03][I][app:102]: ESPHome version 2023.9.3 compiled on Feb 26 2024, 23:42:17
[23:43:03][C][wifi:546]: WiFi:
[23:43:03][C][wifi:382]:   Local MAC: FC:B4:67:4E:66:74
[23:43:03][C][wifi:383]:   SSID: [redacted]
[23:43:03][C][wifi:384]:   IP Address: 192.168.0.115
[23:43:03][C][wifi:386]:   BSSID: [redacted]
[23:43:03][C][wifi:387]:   Hostname: 'cc1101_test_esp32'
[23:43:03][C][wifi:389]:   Signal strength: -62 dB ▂▄▆█
[23:43:03][V][wifi:391]:   Priority: 0.0
[23:43:03][C][wifi:393]:   Channel: 6
[23:43:03][C][wifi:394]:   Subnet: 255.255.240.0
[23:43:03][C][wifi:395]:   Gateway: 192.168.0.1
[23:43:03][C][wifi:396]:   DNS1: 192.168.0.10
[23:43:03][C][wifi:397]:   DNS2: 192.168.0.1
[23:43:03][C][logger:357]: Logger:
[23:43:03][C][logger:358]:   Level: VERBOSE
[23:43:03][C][logger:359]:   Log Baud Rate: 115200
[23:43:03][C][logger:361]:   Hardware UART: UART0
[23:43:03][C][spi:067]: SPI bus:
[23:43:03][C][spi:068]:   CLK Pin: GPIO18
[23:43:03][C][spi:069]:   SDI Pin: GPIO19
[23:43:03][C][spi:070]:   SDO Pin: GPIO23
[23:43:03][C][spi:072]:   Using HW SPI: SPI
[23:43:03][C][uptime.sensor:031]: Uptime Sensor 'cc1101_test_esp32 Uptime'
[23:43:03][C][uptime.sensor:031]:   Device Class: 'duration'
[23:43:03][C][uptime.sensor:031]:   State Class: 'total_increasing'
[23:43:03][C][uptime.sensor:031]:   Unit of Measurement: 'd'
[23:43:03][C][uptime.sensor:031]:   Accuracy Decimals: 1
[23:43:03][C][uptime.sensor:031]:   Icon: 'mdi:clock-outline'
[23:43:03][V][uptime.sensor:031]:   Unique ID: 'fcb4674e6674-uptime'
[23:43:03][C][homeassistant.time:010]: Home Assistant Time:
[23:43:03][C][homeassistant.time:011]:   Timezone: 'CET-1CEST,M3.5.0,M10.5.0/3'
[23:43:03][C][version.text_sensor:021]: Version Text Sensor 'cc1101_test_esp32 Version'
[23:43:03][C][version.text_sensor:021]:   Icon: 'mdi:new-box'
[23:43:03][V][version.text_sensor:021]:   Unique ID: 'fcb4674e6674-version'
[23:43:03][C][wifi_info:013]: WifiInfo Mac Address 'cc1101_test_esp32 MAC Address'
[23:43:03][V][wifi_info:013]:   Unique ID: 'fcb4674e6674-wifiinfo-macadr'
[23:43:03][C][status:034]: Status Binary Sensor 'cc1101_test_esp32 Status'
[23:43:03][C][status:034]:   Device Class: 'connectivity'
[23:43:03][C][remote_base:121]: Remote Receiver Binary Sensor 'cc1101_test_esp32 lidl auriol rc weather station with rain gauge'
[23:43:03][C][remote_base:121]: Remote Receiver Binary Sensor 'cc1101_test_esp32 window'
[23:43:03][C][restart.button:017]: Restart Button 'cc1101_test_esp32 Restart'
[23:43:03][C][cc1101.switch:153]: CC1101 partnum 00 version 14 (Arduino):
[23:43:03][C][cc1101.switch:157]:   CC1101 CS Pin: GPIO5
[23:43:03][C][cc1101.switch:158]:   CC1101 GDO0: 32
[23:43:03][C][cc1101.switch:159]:   CC1101 GDO2: 33
[23:43:03][C][cc1101.switch:160]:   CC1101 Bandwith: 200 KHz
[23:43:03][C][cc1101.switch:161]:   CC1101 Frequency: 433920 KHz
[23:43:03][C][remote_transmitter:015]: Remote Transmitter...
[23:43:03][C][remote_transmitter:016]:   Channel: 0
[23:43:03][C][remote_transmitter:017]:   RMT memory blocks: 1
[23:43:03][C][remote_transmitter:018]:   Clock divider: 80
[23:43:03][C][remote_transmitter:019]:   Pin: GPIO32
[23:43:03][C][remote_receiver.esp32:054]: Remote Receiver:
[23:43:03][C][remote_receiver.esp32:055]:   Pin: GPIO33
[23:43:03][W][remote_receiver.esp32:058]: Remote Receiver Signal starts with a HIGH value. Usually this means you have to invert the signal using 'inverted: True' in the pin schema!
[23:43:03][C][remote_receiver.esp32:060]:   Channel: 1
[23:43:03][C][remote_receiver.esp32:061]:   RMT memory blocks: 3
[23:43:03][C][remote_receiver.esp32:062]:   Clock divider: 80
[23:43:03][C][remote_receiver.esp32:063]:   Tolerance: 50%
[23:43:03][C][remote_receiver.esp32:064]:   Filter out pulses shorter than: 250 us
[23:43:03][C][remote_receiver.esp32:065]:   Signal is done after 4000 us of no changes
[23:43:03][C][captive_portal:088]: Captive Portal:
[23:43:03][C][mdns:115]: mDNS:
[23:43:03][C][mdns:116]:   Hostname: cc1101_test_esp32
[23:43:03][V][mdns:117]:   Services:
[23:43:03][V][mdns:119]:   - _esphomelib, _tcp, 6053
[23:43:03][V][mdns:121]:     TXT: version = 2023.9.3
[23:43:03][V][mdns:121]:     TXT: mac = fcb4674e6674
[23:43:03][V][mdns:121]:     TXT: platform = ESP32
[23:43:03][V][mdns:121]:     TXT: board = nodemcu-32s
[23:43:03][V][mdns:121]:     TXT: network = wifi
[23:43:03][C][ota:097]: Over-The-Air Updates:
[23:43:03][C][ota:098]:   Address: cc1101_test_esp32.local:3232
[23:43:03][C][ota:101]:   Using Password.
[23:43:03][C][api:138]: API Server:
[23:43:03][C][api:139]:   Address: cc1101_test_esp32.local:6053
[23:43:03][C][api:143]:   Using noise encryption: NO
[23:43:03][C][wifi_info:009]: WifiInfo IPAddress 'cc1101_test_esp32 IP'
[23:43:03][V][wifi_info:009]:   Unique ID: 'fcb4674e6674-wifiinfo-ip'
[23:43:04][C][wifi_info:011]: WifiInfo SSID 'cc1101_test_esp32 SSID'
[23:43:04][V][wifi_info:011]:   Unique ID: 'fcb4674e6674-wifiinfo-ssid'
[23:43:04][C][wifi_signal.sensor:009]: WiFi Signal 'cc1101_test_esp32 WiFi Signal'
[23:43:04][C][wifi_signal.sensor:009]:   Device Class: 'signal_strength'
[23:43:04][C][wifi_signal.sensor:009]:   State Class: 'measurement'
[23:43:04][C][wifi_signal.sensor:009]:   Unit of Measurement: 'dBm'
[23:43:04][C][wifi_signal.sensor:009]:   Accuracy Decimals: 0
[23:43:04][V][wifi_signal.sensor:009]:   Unique ID: 'fcb4674e6674-wifisignal'
[23:43:08][D][binary_sensor:036]: 'cc1101_test_esp32 window': Sending state ON
[23:43:08][D][main:097]: on_rc_switch: 1 1486886
[23:43:08][I][remote.rc_switch:261]: Received RCSwitch Raw: protocol=1 data='000101101011000000100110'
[23:43:08][D][main:097]: on_rc_switch: 1 1486886
[23:43:08][I][remote.rc_switch:261]: Received RCSwitch Raw: protocol=1 data='000101101011000000100110'
[23:43:08][D][main:097]: on_rc_switch: 1 1486886
[23:43:08][I][remote.rc_switch:261]: Received RCSwitch Raw: protocol=1 data='000101101011000000100110'
[23:43:08][D][main:097]: on_rc_switch: 1 1486886
[23:43:08][I][remote.rc_switch:261]: Received RCSwitch Raw: protocol=1 data='000101101011000000100110'
[23:43:08][D][main:097]: on_rc_switch: 1 1486886
[23:43:08][I][remote.rc_switch:261]: Received RCSwitch Raw: protocol=1 data='000101101011000000100110'
[23:43:08][D][main:097]: on_rc_switch: 1 1486886
[23:43:08][I][remote.rc_switch:261]: Received RCSwitch Raw: protocol=1 data='000101101011000000100110'
[23:43:08][D][main:097]: on_rc_switch: 1 1486886
[23:43:08][I][remote.rc_switch:261]: Received RCSwitch Raw: protocol=1 data='000101101011000000100110'
[23:43:08][D][main:097]: on_rc_switch: 1 1486886
[23:43:08][I][remote.rc_switch:261]: Received RCSwitch Raw: protocol=1 data='000101101011000000100110'
[23:43:08][D][main:097]: on_rc_switch: 1 1486886
[23:43:08][I][remote.rc_switch:261]: Received RCSwitch Raw: protocol=1 data='000101101011000000100110'
[23:43:09][D][main:097]: on_rc_switch: 1 1486886
[23:43:09][I][remote.rc_switch:261]: Received RCSwitch Raw: protocol=1 data='000101101011000000100110'
[23:43:09][D][main:097]: on_rc_switch: 1 1486886
[23:43:09][I][remote.rc_switch:261]: Received RCSwitch Raw: protocol=1 data='000101101011000000100110'
[23:43:09][D][main:097]: on_rc_switch: 1 1486886
[23:43:09][I][remote.rc_switch:261]: Received RCSwitch Raw: protocol=1 data='000101101011000000100110'
[23:43:09][D][main:097]: on_rc_switch: 1 1486886
[23:43:09][I][remote.rc_switch:261]: Received RCSwitch Raw: protocol=1 data='000101101011000000100110'
[23:43:09][D][main:097]: on_rc_switch: 1 1486886
[23:43:09][I][remote.rc_switch:261]: Received RCSwitch Raw: protocol=1 data='000101101011000000100110'
[23:43:09][D][main:097]: on_rc_switch: 1 1486886
[23:43:09][I][remote.rc_switch:261]: Received RCSwitch Raw: protocol=1 data='000101101011000000100110'
[23:43:09][D][main:097]: on_rc_switch: 1 1486886
[23:43:09][I][remote.rc_switch:261]: Received RCSwitch Raw: protocol=1 data='000101101011000000100110'
[23:43:09][D][main:097]: on_rc_switch: 1 1486886
[23:43:09][I][remote.rc_switch:261]: Received RCSwitch Raw: protocol=1 data='000101101011000000100110'
[23:43:09][D][main:097]: on_rc_switch: 1 1486886
[23:43:09][I][remote.rc_switch:261]: Received RCSwitch Raw: protocol=1 data='000101101011000000100110'
[23:43:09][D][main:097]: on_rc_switch: 1 1486886
[23:43:09][I][remote.rc_switch:261]: Received RCSwitch Raw: protocol=1 data='000101101011000000100110'
[23:43:09][D][main:097]: on_rc_switch: 1 743443
[23:43:09][I][remote.rc_switch:261]: Received RCSwitch Raw: protocol=1 data='00010110101100000010011'
[23:43:10][D][binary_sensor:036]: 'cc1101_test_esp32 window': Sending state OFF
[23:43:41][V][sensor:043]: 'cc1101_test_esp32 WiFi Signal': Received new state -61.000000
[23:43:41][D][sensor:094]: 'cc1101_test_esp32 WiFi Signal': Sending state -61.00000 dBm with 0 decimals of accuracy
[23:43:47][D][binary_sensor:036]: 'cc1101_test_esp32 lidl auriol rc weather station with rain gauge': Sending state ON
[23:43:47][D][rc_switch:081]: lidl auriol rc weather station with rain gauge
[23:43:48][D][binary_sensor:036]: 'cc1101_test_esp32 lidl auriol rc weather station with rain gauge': Sending state OFF
[23:44:41][V][sensor:043]: 'cc1101_test_esp32 WiFi Signal': Received new state -62.000000
[23:44:41][D][sensor:094]: 'cc1101_test_esp32 WiFi Signal': Sending state -62.00000 dBm with 0 decimals of accuracy
[23:44:44][D][binary_sensor:036]: 'cc1101_test_esp32 lidl auriol rc weather station with rain gauge': Sending state ON
[23:44:44][D][rc_switch:081]: lidl auriol rc weather station with rain gauge
[23:44:45][D][binary_sensor:036]: 'cc1101_test_esp32 lidl auriol rc weather station with rain gauge': Sending state OFF```
ssieb commented 4 months ago

Looks like it's working to me. What's the issue?

gabest11 commented 4 months ago

Updated the config and the log with a window sensor. There is triggers the on_rc_switch, because it uses one of the predefined protocols and I think those are analyzed separately for the trigger mechanism.

gabest11 commented 4 months ago

Can you see on_rc_switch for the weather station?

ssieb commented 4 months ago

I don't see a received rc_switch message for the weather station either. That's a strange protocol to use for a weather station anyway...

gabest11 commented 4 months ago

It's towards the end, I logged it from on_press "ESP_LOGD("rc_switch", "lidl auriol rc weather station with rain gauge");"

The modulation is not PWM, but PPM.

triq.org

Set Slicer to PPM, Short: 2222, Long: 1111, Sync: 3333 and it will show F0 80 E1 F0 00 10 A0 repeated a couple of times.

ssieb commented 4 months ago

Oh, you're just making up a protocol. That's not rc switch. You're just hacking the timings to make the rc switch decoder accept it. You need to make a proper decoder or use the pronto or raw receiver for it. https://docplayer.net/46869335-Rf-transmission-protocol.html

gabest11 commented 4 months ago

Well. I'm not making one up. The 9 timings in RC_SWITCH_PROTOCOLS are made up, any device I get have slightly different timings. Even the last one on the list RCSwitchBase(250, 2500, 250, 1250, 250, 250, false) looks PPM to me. 250+1250 and 250+250 are not equally long for one and zero, only the high pulse is the same. Similar to that weather station.

gabest11 commented 4 months ago

Anyhow. The real problem is the on_rc_switch trigger. I think there is some fundamental problem here, but I cannot perfectly understand the code yet.

ssieb commented 4 months ago

No, it's not going to accept your random timings. If remote.rc_switch isn't going to detect the transmission, then the trigger isn't going to work either.

gabest11 commented 4 months ago

I does detect it perfectly fine. This is not my first device where I analyze the timings and set them in a custom protocol. But the first one where it would be nice to report the masked values in a sensor.

ssieb commented 4 months ago

The rc switch protocol timings are not made up. There's a list of standard timings. And yes, there are usually slightly different timings depending on the device that's sending and receiving and that's why there are receiver options to account for that.

ssieb commented 4 months ago

This is not going to work the way you want it to.

gabest11 commented 4 months ago

So you think there cannot be other timings, only those you know of? Why does the custom protocol option exist?

ssieb commented 4 months ago

You can use it for the binary sensor and for sending, but it won't work for general receiving.

gabest11 commented 4 months ago

I see, so as you suggested I need to create a no_rc_switch_that_works_for_me receiver. It will be a learning experience.

ssieb commented 4 months ago

If you're going to do that, you should just create a decoder for the actual protocol.

TheChatty commented 1 month ago

@gabest11: There's a workaround for you.

Basically you're patching rc_switch_protocol.cpp with your own protocols.

One way to achieve this is to make this file available outside it's container, e.g. in /config/esphome. You will need to redo the last step after each esphome update.

# ssh username@homeassistant
... enter password...
# docker exec -it $(docker ps -f name=esphome -q) cp /esphome/esphome/components/remote_base/rc_switch_protocol.cpp /config/esphome/
# docker exec -it $(docker ps -f name=esphome -q) ln -sf /config/esphome/rc_switch_protocol.cpp /esphome/esphome/components/remote_base/

So after including your own protocols you can simply edit your yaml and install it normally like you did before.

gabest11 commented 1 month ago

That's what I do to make the dashboard work with IIS (https://github.com/esphome/esphome/pull/6845), but the changes are lost with every update, so it's a bit inconvenient.