Solved: Unable to find current Custom Ringtone number for Xiaomi Gateway (Custom ringtone not playing)

xiaomi
Tags: #<Tag:0x00007f1b963cf808>

#1

I uploaded far too many custom ringtones on my Xiaomi Gateway during troubleshooting and was unable to identify what the current custom ringtone number was.

For those not aware, when you upload a ringtone to the Xiaomi device for the first time it assigns ringtone id 10001. Ever substantial ringtone uploaded continues in sequence even if it is deleted.

Fortunately I was able to alter some code by PPLucky to slowly increase the ringtone id until I found it. I was all the way up to 10034…

To use the below code simply select a desired number on the slider and turn on the “Test” switch. To stop the loop turn on “mute test”. Volume can be changed and “delay” will affect the loop delay.

Configuration.yaml:

input_boolean:
  test_mute:
    name: Mute Test
    icon: mdi:volume-off
  test_switch:
    name: test
    initial: off

input_number:
  test_number:
    name: Slider
    initial: 10001
    min: 10001
    max: 10100
    step: 1

automations.yaml

- alias: Test
    trigger:
      platform: state
      entity_id: input_boolean.test_switch
      to: 'on'
    action:
      - service: script.play_sound
        data:
          ringtone_vol: 50
          delay: 2

  - alias: mute test
    trigger:
      platform: state
      entity_id: input_boolean.test_mute
      to: 'on'
    action:
      - service: xiaomi_aqara.stop_ringtone
        data:
          gw_mac: !secret xiaomi_mac
      - delay: 
          seconds: 10
      - service: input_boolean.turn_off
        data:
          entity_id: input_boolean.test_mute

scripts.yaml

####################################################
#                                                  #
#             Alarm Sound Play Scripts             #
#                                                  #
####################################################
### Play Provided sound in loop on Gateway ###
  play_sound:
    alias: "Play Sound"
    sequence:
### Turn off gateway mute to play sound ###
      - condition: state
        entity_id: input_boolean.test_mute
        state: 'off'
### Play ringtone sound provided ###
      - service: xiaomi_aqara.play_ringtone
        data_template:
          gw_mac: !secret xiaomi_mac
          ringtone_id: "{{states.input_number.test_number.state|int}}"
          ringtone_vol: "{{ ringtone_vol }}"
### Wait & call another script that call this one ###
### in order to generate an infinite loop until gateway ###
### mute is turned on by some other action ###
      - delay: '00:00:{{ delay | int }}'
      - service: script.play_sound_loop
        data_template:
          ringtone_id: "{{states.input_number.test_number.state|int}}"
          ringtone_vol: "{{ ringtone_vol }}"
          delay: "{{ delay }}"

  play_sound_loop:
    alias: "Play Sound in Loop"
### Wait & call script that called this one ###
### in order to generate an infinite loop until ###
### gateway mute is turned on by some other action ###
    sequence:
      - delay: '00:00:{{ delay | int }}'
      - service: script.play_sound
        data_template:
          ringtone_id: "{{states.input_number.test_number.state|int}}"
          ringtone_vol: "{{ ringtone_vol }}"
          delay: "{{ delay }}"