pauln / esphome-linp-doorbell-g03

ESPHome custom component for linp-doorbell-g03
MIT License
44 stars 8 forks source link

Why do calling set_volume service playing tune? #9

Closed notabene00 closed 4 years ago

notabene00 commented 4 years ago

I want to silent (set_volume: 0) my doorbell in the evening till morning. Then the system automatically get volume back to 4 when the sleep mode goes off. And there is ambiguity... In the morning I'll hear the chime, but no one at the door ;(

There is another service for playing tune already...

pauln commented 4 years ago

Unfortunately, that's just how the other microcontroller (STM8S005K6) is programmed (we only tell it to set the volume - it then plays the tune to demonstrate the new volume level), so I don't think that there's anything we can do about it from the ESP32 end.

One partial solution would be to call the linp_stop_tune service immediately after calling linp_set_volume - but it won't completely stop the chime/tune from playing. As long as your chime is long enough for it to receive and process the linp_stop_tune call before the chime finishes, it'll cut it off early - so perhaps instead of "ding-dong" you'll just get the "ding".

I've also experimented with modifying the code to send the two commands one after the other without having the additional delay of a second API request from Home Assistant, but it's still not enough to completely avoid the chime playing. If you'd like to try this, you can add a call to stopTune(); before the get_volume command is enqueued - i.e. make the setVolume function in linp_doorbell.h look like this:

  void setVolume(int volume) {
    if (volume < 0 || volume > 4) {
      ESP_LOGI("linp-doorbell", "Ignoring invalid volume request: %i", volume);
      return;
    }

    ESP_LOGI("linp-doorbell", "Setting volume to: %i", volume);
    String command = String("down set_volume ");
    command.concat(volume);
    commandQueue.enqueue(command);
    stopTune();
    commandQueue.enqueue("down get_volume");
  }