afarago/esphome_component_bthome

User Exception

Closed this issue · 2 comments

Kimotu commented

Since there is no button/event support, I made a workaround. Send a binary value and let the receiver reset the state itself.
But when the value of delay_off is too high, I get a user exception.

What I wonder is the line WARNING Decoded 0x4020c1b8: esphome::Action<>::play_complex(). I use the Rtttl Buzzer and its playback is awfully slow. Maybe these two components BTH and rtttl do interfere? Both components do background jobs.

When the button is pressed, its state shall be transmitted and as confirmation of successful button press, a sound shall be played.

Transmitter:

beethowen_transmitter:
  id: bh_transmitter
  connect_persistent: true
  local_passkey: ${local_pass}
  sensors:
    - measurement_type: running
      sensor_id: stop_button
    - measurement_type: battery
      sensor_id: battery
  on_send_finished:
    - logger.log:
        level: INFO
        tag: beethown
        format: "Sent success!"
  on_send_failed:
    - logger.log:
        level: WARN
        tag: beethown
        format: "Sent failed! - Retrying..."
    - lambda: id(bh_transmitter).send(false);

binary_sensor:
  - platform: gpio
    name: "Stop button"
    id: stop_button
    pin:
      number: D6
      inverted: true
      mode:
        input: true
        pullup: true
    device_class: running
    filters:
      - delayed_off: 800ms
# 800ms work, 1s user exception
    on_press:
      - lambda: id(bh_transmitter).send(false);
      - logger.log:
            level: INFO
            tag: button
            format: "Button pressed!"

Receiver:

beethowen_receiver:
  dump: unmatched
  local_passkey: ${local_pass}
  devices:
    - mac_address: ${remote_mac}
      name_prefix: Beethowen Transmitter
      expected_remote_passkey: ${remote_pass}
      dump: all

binary_sensor:
  - platform: beethowen_receiver
    mac_address: ${remote_mac}
    sensors:
      - measurement_type: running
        name: stop_button
        id: stop_button
        on_press:
          - script.execute: stop_timer
          - logger.log:
              level: INFO
              tag: beethowen
              format: "Received remote stop"
#workaround, since button event not supported and somebody has to reset button state :-)
          - lambda: id(stop_button).publish_state(false);

ExceptionDecoderTrace.txt
BHT-Log.txt

There are two issues here.

  1. by mistake on_send_failed was called upon success instead of failure - fixed it
  2. on_send_failed calling send in your scenario can enter an infinite loop. espnow anyhow has retry mechanisms. If it fails, just let it go.
    If you correct it - it will work.
  3. beethowen should not go blocking, but both on transmitter and receiver use a threaded queue --> to be added when time is plenty - adding separate issue for tracking

I recommend to use send action for the .yaml, still infinite loop is to be avoided in user code upon repeated failure.

- beethowen_transmitter.send:
    complete_only: false