Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Persistent volume between restarts for Onju Voice #63

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

VivantSenior
Copy link

Added persistent (between device restarts and firmware updates) volume value. Please test as I am using MicroWakeWord flavor.

Added persistent (between device restarts and firmware updates) volume value.
@jherby2k
Copy link

Doesn't work for me. Tried both a firmware update and a hard power cycle. Back to 100% each time.

Shouldn't you be storing it inside the set_volume function?

@VivantSenior
Copy link
Author

Tried to put the logic in the set_volume but as far as I remember during my tests I noticed this function is not used when changing volume from Home Assistant UI. Please note that ESP saves variables to the memory at some interval (60s ?) therefor if you set new value and there is a is sudden loss of voltage it won't restore the newest value. It works when you upload new firmware or use Restart ESPHome function.

Try to add debug logs and paste it here.

logger:
  level: DEBUG
      - media_player.volume_set:
          id: onju_out
          volume: !lambda |-
            ESP_LOGD("persistent_volume", "--- volume_percent restored value: %f ---", id(volume_percent));
            return id(volume_percent);
media_player:
  - platform: adf_pipeline
    id: onju_out
    name: None
    internal: false
    keep_pipeline_alive: true
    pipeline:
      - self
      - resampler
      - adf_i2s_out
    on_state:
      then:
        - lambda: |-
            static float old_volume = -1;
            float new_volume = id(onju_out).volume;
            if(abs(new_volume-old_volume) > 0.0001) {
              if(old_volume != -1) {
                id(show_volume)->execute();
              }
            }
            old_volume = new_volume;
            ESP_LOGD("persistent_volume", "--- volume_percent before change: %f ---", id(volume_percent));
            id(volume_percent) = old_volume;
            ESP_LOGD("persistent_volume", "--- volume_percent after change: %f ---", id(volume_percent));
      - media_player.volume_set:
          id: onju_out
          volume: !lambda |-
            ESP_LOGD("persistent_volume", "--- volume_percent restored value: %f ---", id(volume_percent));
            return id(volume_percent);

@jherby2k
Copy link

jherby2k commented Jul 30, 2024

Ah, issue seems to be here. I i just change this lambda to return id(volume_percent); it works, but i assume the clamping is there for a reason and I don't really understand this very well, so i'll let you fix it appropriately.

  - id: set_volume
    mode: restart
    parameters:
      volume: float
    then:
      - media_player.volume_set:
          id: onju_out
          volume: !lambda return clamp(id(onju_out).volume+volume, 0.0f, 1.0f);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants