Advertisement
kornelremete

roomassist

Jan 8th, 2025
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.86 KB | Fixit | 0 0
  1. # info https://smarthomecircle.com/How-to-setup-on-device-wake-word-for-voice-assistant-home-assistant
  2.  
  3. #pinout microfon:
  4. # ESP -> INMP441 mikrofon
  5. # gpio2 SCK
  6. # gpio3 WS
  7. # gpio4 SD
  8. # 3.3v Vdd
  9. # GND GND + L/R
  10.  
  11. #pinout ws2812 RGB LEDring
  12. # ESP -> ws2812
  13. # gpio13 DI
  14. # 5v 5v
  15. # GND GND
  16.  
  17.  
  18.  
  19. substitutions:
  20. name: "smallroomassist"
  21. friendly_name: SmallroomAssist
  22. esp_board: "esp32-s3-devkitc-1"
  23. device_description: "esp32s3"
  24. # Phases of the Voice Assistant
  25. # IDLE: The voice assistant is ready to be triggered by a wake-word
  26. voice_assist_idle_phase_id: '1'
  27. # LISTENING: The voice assistant is ready to listen to a voice command (after being triggered by the wake word)
  28. voice_assist_listening_phase_id: '2'
  29. # THINKING: The voice assistant is currently processing the command
  30. voice_assist_thinking_phase_id: '3'
  31. # REPLYING: The voice assistant is replying to the command
  32. voice_assist_replying_phase_id: '4'
  33. # NOT_READY: The voice assistant is not ready
  34. voice_assist_not_ready_phase_id: '10'
  35. # ERROR: The voice assistant encountered an error
  36. voice_assist_error_phase_id: '11'
  37. # MUTED: The voice assistant is muted and will not reply to a wake-word
  38. voice_assist_muted_phase_id: '12'
  39. #Micro
  40. #micro_wake_word_model: hey_jarvis
  41.  
  42. external_components:
  43. - source:
  44. type: git
  45. url: https://github.com/gnumpi/esphome_audio
  46. ref: main
  47. #type: local
  48. #path: /Users/siekmann/Privat/Projects/espHome/esphome_audio/esphome/components
  49. components: [ adf_pipeline, i2s_audio ]
  50.  
  51.  
  52. esphome:
  53. name: ${name}
  54. comment: ${device_description}
  55. friendly_name: ${friendly_name}
  56. min_version: 2024.6.0
  57. name_add_mac_suffix: false
  58. platformio_options:
  59. build_flags: -DBOARD_HAS_PSRAM
  60. board_build.flash_mode: dio
  61. board_upload.maximum_size: 16777216
  62. on_boot:
  63. priority: 600
  64. then:
  65. # Run the script to refresh the LED status
  66. # If after 30 seconds, the device is still initializing (It did not yet connect to Home Assistant), turn off the init_in_progress variable and run the script to refresh the LED status
  67. - delay: 30s
  68. - if:
  69. condition:
  70. lambda: return id(init_in_progress);
  71. then:
  72. - lambda: id(init_in_progress) = false;
  73.  
  74.  
  75. esp32:
  76. board: ${esp_board}
  77. variant: ESP32S3
  78. flash_size: 16MB
  79. framework:
  80. type: esp-idf
  81. sdkconfig_options:
  82. # need to set a s3 compatible board for the adf-sdk to compile
  83. # board specific code is not used though
  84. CONFIG_ESP32_S3_BOX_BOARD: "y"
  85. CONFIG_ESP32_WIFI_STATIC_RX_BUFFER_NUM: "16"
  86. CONFIG_ESP32_WIFI_DYNAMIC_RX_BUFFER_NUM: "512"
  87. CONFIG_TCPIP_RECVMBOX_SIZE: "512"
  88.  
  89. CONFIG_TCP_SND_BUF_DEFAULT: "65535"
  90. CONFIG_TCP_WND_DEFAULT: "512000"
  91. CONFIG_TCP_RECVMBOX_SIZE: "512"
  92.  
  93.  
  94. # Enable logging
  95. logger:
  96.  
  97.  
  98. globals:
  99. # Global initialisation variable. Initialized to true and set to false once everything is connected. Only used to have a smooth "plugging" experience
  100. - id: init_in_progress
  101. type: bool
  102. restore_value: no
  103. initial_value: 'true'
  104. # Global variable tracking the phase of the voice assistant (defined above). Initialized to not_ready
  105. - id: voice_assistant_phase
  106. type: int
  107. restore_value: no
  108. initial_value: ${voice_assist_not_ready_phase_id}
  109.  
  110.  
  111. psram:
  112. mode: octal
  113. speed: 80MHz
  114.  
  115. wifi:
  116. enable_rrm: true
  117. ssid: !secret wifi_ssid
  118. password: !secret wifi_password
  119. fast_connect: true
  120.  
  121. # Optional manual IP
  122. # manual_ip:
  123. # static_ip: 10.10.10.109
  124. # gateway: 10.10.10.1
  125. # subnet: 255.255.255.0
  126. # Enable fallback hotspot (captive portal) in case wifi connection fails
  127. ap:
  128. ssid: "Smalroomassist Fallback Hotspot"
  129. password: "9ulKpPRzf55I"
  130.  
  131.  
  132.  
  133. # Enable Home Assistant API
  134. api:
  135. encryption:
  136. key: "XXXXXXXXXXXXXXXXXXXXXXXXXXX"
  137.  
  138. # services:
  139. # - service: play_audio
  140. # variables:
  141. # audio_url: string
  142. # then:
  143. # - homeassistant.service:
  144. # service: media_player.play_media
  145. # data:
  146. # entity_id: media_player.csaladi_szoba
  147. # media_content_id: !lambda 'return audio_url;'
  148. # media_content_type: "music"
  149.  
  150.  
  151.  
  152. # Allow Over-The-Air updates
  153. ota:
  154. - platform: esphome
  155. password: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
  156.  
  157.  
  158. # Allow provisioning Wi-Fi via serial
  159. improv_serial:
  160.  
  161.  
  162. #----------------------
  163.  
  164. adf_pipeline:
  165. - platform: i2s_audio
  166. type: audio_out
  167. id: adf_i2s_out
  168. i2s_audio_id: i2s_speaker
  169. i2s_dout_pin: GPIO9
  170.  
  171. - platform: i2s_audio #microfon
  172. type: audio_in
  173. id: adf_i2s_in
  174. i2s_audio_id: i2s_in
  175. i2s_din_pin: GPIO4
  176. pdm: false
  177. channel: left
  178. sample_rate: 16000
  179. bits_per_sample: 32bit
  180.  
  181. # Audio and Voice Assistant Config
  182. i2s_audio:
  183. - id: i2s_in
  184. i2s_lrclk_pin: GPIO3 #WS
  185. i2s_bclk_pin: GPIO2 #SCK
  186. - id: i2s_speaker
  187. i2s_lrclk_pin: GPIO6 #LRC
  188. i2s_bclk_pin: GPIO7 #BLCK
  189.  
  190. microphone:
  191. - platform: adf_pipeline
  192. id: adf_microphone
  193. keep_pipeline_alive: true
  194. pipeline:
  195. - adf_i2s_in
  196. - self
  197.  
  198. #media_player:
  199. # - platform: adf_pipeline
  200. # id: adf_media_player
  201. # name: media_player
  202. # keep_pipeline_alive: true
  203. # internal: false
  204. # pipeline:
  205. # - self
  206. # - resampler
  207. # - adf_i2s_out
  208.  
  209.  
  210.  
  211. #micro_wake_word:
  212. # models:
  213. # - model: ${micro_wake_word_model} #"https://raw.githubusercontent.com/esphome/micro-wake-word-models/refs/heads/main/models/v2/experiments/choo_choo_homie.json"
  214. # - model: "https://raw.githubusercontent.com/esphome/micro-wake-word-models/refs/heads/main/models/hey_jarvis.json"
  215. micro_wake_word:
  216. models:
  217. - model: "https://raw.githubusercontent.com/esphome/micro-wake-word-models/refs/heads/main/models/hey_jarvis.json"
  218. on_wake_word_detected:
  219. # - media_player.stop:
  220. - light.turn_on:
  221. id: led_ring
  222. blue: 0%
  223. red: 0%
  224. green: 100%
  225. brightness: 75%
  226. effect: pulse
  227. - voice_assistant.start:
  228.  
  229. voice_assistant:
  230. microphone: adf_microphone
  231. ####media_player: adf_media_player
  232. use_wake_word: false
  233. #vad_threshold: 3
  234. #noise_suppression_level: 1
  235. auto_gain: 31dBFS
  236. #volume_multiplier: 15.0
  237.  
  238.  
  239. on_tts_start:
  240. - homeassistant.service:
  241. service: media_player.volume_set
  242. data:
  243. entity_id: media_player.csaladi_szoba # Replace with your media player entity_id
  244. volume_level: '0.4' # Lower volume to 20%
  245.  
  246. - homeassistant.service:
  247. # service: tts.cloud_say
  248. # data:
  249. # media_player_entity_id: media_player.csaladi_szoba
  250. # # entity_id: media_player.csaladi_szoba #media_player.announcements
  251. # data_template:
  252. # message: !lambda 'return x;' #"{{ my_stt }}"
  253. # variables:
  254. # my_stt: return x;
  255.  
  256. service: tts.speak
  257. data:
  258. # cache: true
  259. message: !lambda 'return x;'
  260. media_player_entity_id: media_player.csaladi_szoba
  261. entity_id: tts.google_cloud
  262. language: hu-HU
  263.  
  264.  
  265.  
  266. - light.turn_on:
  267. id: led_ring
  268. blue: 0%
  269. red: 0%
  270. green: 100%
  271. brightness: 75%
  272. effect: pulse
  273.  
  274.  
  275. # on_tts_end:
  276. # - homeassistant.service:
  277. # service: media_player.play_media
  278. # data:
  279. # entity_id: media_player.csaladi_szoba
  280. # media_content_type: music
  281. # data_template:
  282. # media_content_id: "{{ my_stt }}"#"{{ my_url }}"
  283. # variables:
  284. # my_url: return x;
  285. # - homeassistant.service:
  286. ## service: tts.speak
  287. # data:
  288. # media_player_entity_id: media_player.csaladi_szoba #replace this with your media player entity id
  289. # message: !lambda 'return x;'
  290. # entity_id: tts.google_cloud #replace this with your piper tts entity id.
  291.  
  292. on_client_connected:
  293. - lambda: id(init_in_progress) = false;
  294. - if:
  295. condition:
  296. switch.is_on: use_wake_word
  297. then:
  298. - micro_wake_word.start:
  299. - lambda: id(voice_assistant_phase) = ${voice_assist_idle_phase_id};
  300. - script.execute: reset_led
  301. else:
  302. - lambda: id(voice_assistant_phase) = ${voice_assist_muted_phase_id};
  303.  
  304. on_client_disconnected:
  305. - lambda: id(voice_assistant_phase) = ${voice_assist_not_ready_phase_id};
  306. - voice_assistant.stop
  307. - micro_wake_word.stop
  308. - light.turn_on:
  309. id: led_ring
  310. blue: 0%
  311. red: 100%
  312. green: 100%
  313. brightness: 50%
  314. effect: connecting
  315.  
  316. on_listening:
  317. - light.turn_on:
  318. id: led_ring
  319. blue: 100%
  320. red: 0%
  321. green: 0%
  322. brightness: 25%
  323. effect: wakeword
  324.  
  325. on_end:
  326. then:
  327. - light.turn_off:
  328. id: led_ring
  329. - voice_assistant.stop
  330. #- wait_until:
  331. # not:
  332. # media_player.is_playing:
  333. - script.execute: reset_led
  334. - if:
  335. condition:
  336. switch.is_on: use_wake_word
  337. then:
  338. - micro_wake_word.start:
  339. on_error:
  340. - light.turn_on:
  341. id: led_ring
  342. blue: 0%
  343. red: 100%
  344. green: 0%
  345. brightness: 100%
  346. effect: none
  347. - delay: 1s
  348. - script.execute: reset_led
  349. - script.wait: reset_led
  350. - lambda: |-
  351. if (code == "wake-provider-missing" || code == "wake-engine-missing") {
  352. id(use_wake_word).turn_off();
  353. }
  354. - if:
  355. condition:
  356. switch.is_on: use_wake_word
  357. then:
  358. - micro_wake_word.start:
  359. - script.execute: reset_led
  360.  
  361. script:
  362. - id: reset_led
  363. then:
  364. - if:
  365. condition:
  366. switch.is_on: use_wake_word
  367. then:
  368. - light.turn_on:
  369. id: led_ring
  370. blue: 100%
  371. red: 0%
  372. green: 0%
  373. brightness: 25%
  374. effect: none
  375. else:
  376. - light.turn_off: led_ring
  377.  
  378. button:
  379. - platform: restart
  380. id: restart_btn
  381. name: "${friendly_name} REBOOT"
  382.  
  383. switch:
  384. - platform: template
  385. name: Enable Voice Assistant
  386. id: use_wake_word
  387. optimistic: true
  388. restore_mode: RESTORE_DEFAULT_ON
  389. icon: mdi:assistant
  390. # When the switch is turned on (on Home Assistant):
  391. # Start the voice assistant component
  392. # Set the correct phase and run the script to refresh the LED status
  393. on_turn_on:
  394. - logger.log: "switch on"
  395. - if:
  396. condition:
  397. lambda: return !id(init_in_progress);
  398. then:
  399. - logger.log: "condition 1"
  400. - lambda: id(voice_assistant_phase) = ${voice_assist_idle_phase_id};
  401. - voice_assistant.stop
  402. - delay: 1s
  403. - if:
  404. condition:
  405. not:
  406. - voice_assistant.is_running
  407. then:
  408. - logger.log: "Starting MWW"
  409. #- voice_assistant.start_continuous
  410. - micro_wake_word.start:
  411. - script.execute: reset_led
  412. on_turn_off:
  413. - if:
  414. condition:
  415. lambda: return !id(init_in_progress);
  416. then:
  417. - voice_assistant.stop
  418. - micro_wake_word.stop
  419. - lambda: id(voice_assistant_phase) = ${voice_assist_muted_phase_id};
  420. - script.execute: reset_led
  421.  
  422. - platform: template
  423. name: Pipeline
  424. id: pipeline_switch
  425. optimistic: true
  426. restore_mode: RESTORE_DEFAULT_OFF
  427.  
  428. # on_turn_off:
  429. #- media_player.stop
  430.  
  431. light:
  432. - platform: esp32_rmt_led_strip
  433. id: led_ring
  434. name: "${friendly_name} Front LED"
  435. #pin: GPIO48 #on board led 1pc led
  436. pin: GPIO13 #on board led 1pc led
  437. num_leds: 12 #1
  438. rmt_channel: 0 #1
  439. rgb_order: GRB
  440. chipset: ws2812
  441. default_transition_length: 0s
  442. effects:
  443. - pulse:
  444. name: "Pulse"
  445. transition_length: 0.5s
  446. update_interval: 0.5s
  447. - addressable_twinkle:
  448. name: "Working"
  449. twinkle_probability: 5%
  450. progress_interval: 4ms
  451. - addressable_color_wipe:
  452. name: "Wakeword"
  453. colors:
  454. - red: 0%
  455. green: 50%
  456. blue: 0%
  457. num_leds: 12
  458. add_led_interval: 20ms
  459. reverse: false
  460. - addressable_color_wipe:
  461. name: "Connecting"
  462. colors:
  463. - red: 60%
  464. green: 60%
  465. blue: 60%
  466. num_leds: 1
  467. - red: 60%
  468. green: 60%
  469. blue: 0%
  470. num_leds: 1
  471. add_led_interval: 100ms
  472. reverse: true
  473.  
  474.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement