Advertisement
mak_user

Untitled

Oct 29th, 2024
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 8.02 KB | None | 0 0
  1. substitutions:
  2.   name: "muse-luxe"
  3.   friendly_name: "RaspiAudio Muse Luxe"
  4.   wifi_ap_password: "1q2w3e4r5t"
  5.  
  6. esphome:
  7.   name: ${name}
  8.   friendly_name: ${friendly_name}
  9.   name_add_mac_suffix: false
  10.   min_version: 2023.10.1
  11.   on_boot:
  12.     then:
  13.       - output.turn_on: dac_mute
  14.       - light.turn_on:
  15.           id: top_led
  16.           effect: slow_pulse
  17.           red: 100%
  18.           green: 60%
  19.           blue: 0%
  20.  
  21. esp32:
  22.   board: esp-wrover-kit
  23.   framework:
  24.     type: arduino
  25.  
  26. logger:
  27. api:
  28.   services:
  29.     - service: start_va
  30.       then:
  31.        - voice_assistant.start
  32.     - service: stop_va
  33.       then:
  34.        - voice_assistant.stop
  35. ota:
  36. - platform: esphome
  37.  
  38. i2c:
  39.   sda: GPIO18
  40.   scl: GPIO23
  41.  
  42. wifi:
  43.   ssid: "mkDevices"
  44.   password: "1q2w3e4r5t"
  45.   manual_ip:
  46.     static_ip: 192.168.1.40
  47.     gateway: 192.168.1.1
  48.     subnet: 255.255.255.0
  49.  
  50. captive_portal:
  51. improv_serial:
  52. external_components:
  53.   - source: github://RASPIAUDIO/esphomeLuxe@main
  54.     components: [es8388]
  55.     refresh: 0s
  56.  
  57. es8388:
  58. globals:
  59.   - id: wifi_connected
  60.     type: bool
  61.     initial_value: "false"
  62.     restore_value: false
  63.  
  64. interval:
  65.   - interval: 1s
  66.     then:
  67.       - if:
  68.           condition:
  69.             and:
  70.               - lambda: "return !id(wifi_connected);"
  71.               - wifi.connected:
  72.           then:
  73.             - globals.set:
  74.                 id: wifi_connected
  75.                 value: "true"
  76.             - light.turn_on:
  77.                 id: top_led
  78.                 effect: pulse
  79.                 red: 0%
  80.                 green: 100%
  81.                 blue: 0%
  82.             - delay: 1s
  83.             - light.turn_off: top_led
  84.  
  85. output:
  86.   - platform: gpio
  87.     id: dac_mute
  88.     pin: GPIO21
  89.     inverted: true
  90.  
  91. i2s_audio:
  92.   - i2s_lrclk_pin: GPIO25
  93.     i2s_bclk_pin: GPIO5
  94.  
  95. media_player:
  96.   - platform: i2s_audio
  97.     name: None
  98.     id: luxe_out
  99.     dac_type: external
  100.     i2s_dout_pin: GPIO26
  101.     mode: stereo
  102.     on_state:
  103.       if:
  104.         condition:
  105.           media_player.is_playing:
  106.         then:
  107.           output.turn_off: dac_mute
  108.         else:
  109.           output.turn_on: dac_mute
  110.  
  111. microphone:
  112.   - platform: i2s_audio
  113.     id: luxe_microphone
  114.     i2s_din_pin: GPIO35
  115.     adc_type: external
  116.     pdm: false
  117.  
  118. voice_assistant:
  119.   id: va
  120.   microphone: luxe_microphone
  121.   media_player: luxe_out
  122.   use_wake_word: true
  123.   on_listening:
  124.     - light.turn_on:
  125.         id: top_led
  126.         blue: 100%
  127.         red: 0%
  128.         green: 0%
  129.         brightness: 100%
  130.         effect: pulse
  131.   on_tts_start:
  132.     - light.turn_on:
  133.         id: top_led
  134.         blue: 60%
  135.         red: 20%
  136.         green: 20%
  137.         effect: none
  138.   on_tts_end:
  139.     - media_player.play_media: !lambda return x;
  140.     - light.turn_on:
  141.         id: top_led
  142.         blue: 60%
  143.         red: 20%
  144.         green: 20%
  145.         effect: pulse
  146.     # This is useful when you want to stream the response on another media_player
  147.      - homeassistant.service:
  148.          service: media_player.play_media
  149.          data:
  150.            entity_id: media_player.googlehome3359
  151.            media_content_id: !lambda 'return x;'
  152.            media_content_type: music
  153.            announce: "true"
  154.   on_client_connected:
  155.     - if:
  156.         condition:
  157.           - switch.is_on: use_wake_word
  158.         then:
  159.           - voice_assistant.start_continuous:
  160.   on_client_disconnected:
  161.     - if:
  162.         condition:
  163.           - switch.is_on: use_wake_word
  164.         then:
  165.           - voice_assistant.stop:
  166.   on_end:
  167.     - delay: 100ms
  168.     - wait_until:
  169.         not:
  170.           media_player.is_playing: luxe_out
  171.     - script.execute: reset_led
  172.   on_error:
  173.     - light.turn_on:
  174.         id: top_led
  175.         blue: 0%
  176.         red: 100%
  177.         green: 0%
  178.         effect: none
  179.     - delay: 1s
  180.     - script.execute: reset_led
  181.     - script.wait: reset_led
  182.     - lambda: |-
  183.         if (code == "wake-provider-missing" || code == "wake-engine-missing") {
  184.           id(use_wake_word).turn_off();
  185.         }
  186. sensor:
  187.   - platform: adc
  188.     pin: GPIO33
  189.     name: Battery voltage
  190.     device_class: voltage
  191.     unit_of_measurement: "V"
  192.     accuracy_decimals: 2
  193.     state_class: measurement
  194.     entity_category: diagnostic
  195.     update_interval: 15s
  196.     attenuation: auto
  197.     filters:
  198.       - multiply: 2 # https://forum.raspiaudio.com/t/esp-muse-luxe-bluetooth-speaker/294/12
  199.       - exponential_moving_average:
  200.           alpha: 0.2
  201.           send_every: 2
  202.       - delta: 0.002
  203.     on_value:
  204.       then:
  205.         - sensor.template.publish:
  206.             id: battery_percent
  207.             state: !lambda "return x;"
  208.  
  209.   - platform: template
  210.     name: Battery
  211.     id: battery_percent
  212.     device_class: battery
  213.     unit_of_measurement: "%"
  214.     accuracy_decimals: 0
  215.     state_class: measurement
  216.     entity_category: diagnostic
  217.     update_interval: 15s
  218.     filters:
  219.       - calibrate_polynomial:
  220.           degree: 3
  221.           datapoints:
  222.            - 4.58 -> 100.0
  223.             - 4.5 -> 97.1
  224.             - 4.47 -> 94.2
  225.             - 4.44 -> 88.4
  226.             - 4.42 -> 82.7
  227.             - 4.41 -> 76.9
  228.             - 4.41 -> 71.1
  229.             - 4.37 -> 65.3
  230.             - 4.35 -> 59.5
  231.             - 4.31 -> 53.8
  232.             - 4.28 -> 48.0
  233.             - 4.26 -> 42.2
  234.             - 4.23 -> 36.4
  235.             - 4.21 -> 30.6
  236.             - 4.19 -> 24.9
  237.             - 4.16 -> 19.1
  238.             - 4.1 -> 13.3
  239.             - 4.07 -> 10.4
  240.             - 4.03 -> 7.5
  241.             - 3.97 -> 4.6
  242.             - 3.82 -> 1.7
  243.             - 3.27 -> 0.0
  244.       - lambda: return clamp(x, 0.0f, 100.0f);
  245.  
  246. binary_sensor:
  247.   - platform: gpio
  248.     pin:
  249.       number: GPIO19
  250.       inverted: true
  251.       mode:
  252.         input: true
  253.         pullup: true
  254.     name: Volume Up
  255.     on_click:
  256.       - media_player.volume_up: luxe_out
  257.   - platform: gpio
  258.     pin:
  259.       number: GPIO32
  260.       inverted: true
  261.       mode:
  262.         input: true
  263.         pullup: true
  264.     name: Volume Down
  265.     on_click:
  266.       - media_player.volume_down: luxe_out
  267.   - platform: gpio
  268.     pin:
  269.       number: GPIO12
  270.       inverted: true
  271.       mode:
  272.         input: true
  273.         pullup: true
  274.     name: Action
  275.     on_click:
  276.       - if:
  277.           condition:
  278.             switch.is_off: use_wake_word
  279.           then:
  280.             - if:
  281.                 condition: voice_assistant.is_running
  282.                 then:
  283.                   - voice_assistant.stop:
  284.                   - script.execute: reset_led
  285.                 else:
  286.                   - voice_assistant.start:
  287.           else:
  288.            - voice_assistant.stop
  289.             - delay: 1s
  290.             - script.execute: reset_led
  291.             - script.wait: reset_led
  292.             - voice_assistant.start_continuous:
  293. light:
  294.   - platform: esp32_rmt_led_strip
  295.     name: None
  296.     id: top_led
  297.     pin: GPIO22
  298.     chipset: SK6812
  299.     num_leds: 1
  300.     rgb_order: grb
  301.     rmt_channel: 0
  302.     default_transition_length: 0s
  303.     gamma_correct: 2.8
  304.     effects:
  305.       - pulse:
  306.           name: pulse
  307.           transition_length: 250ms
  308.           update_interval: 250ms
  309.       - pulse:
  310.           name: slow_pulse
  311.           transition_length: 1s
  312.           update_interval: 2s
  313.  
  314. script:
  315.   - id: reset_led
  316.     then:
  317.       - if:
  318.           condition:
  319.             switch.is_on: use_wake_word
  320.           then:
  321.             - light.turn_on:
  322.                 id: top_led
  323.                 blue: 100%
  324.                 red: 100%
  325.                 green: 0%
  326.                 brightness: 100%
  327.                 effect: none
  328.           else:
  329.             - light.turn_off: top_led
  330.  
  331. switch:
  332.   - platform: template
  333.     name: Use Wake Word
  334.     id: use_wake_word
  335.     optimistic: true
  336.     restore_mode: RESTORE_DEFAULT_ON
  337.     on_turn_on:
  338.       - lambda: id(va).set_use_wake_word(true);
  339.       - if:
  340.           condition:
  341.             not:
  342.              - voice_assistant.is_running
  343.           then:
  344.            - voice_assistant.start_continuous
  345.       - script.execute: reset_led
  346.     on_turn_off:
  347.      - voice_assistant.stop
  348.       - lambda: id(va).set_use_wake_word(false);
  349.       - script.execute: reset_led
  350.    
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement