I am fairly new to automations and YAML and have done a lot of research trying to find an answer to my question. Unfortunately I’ve been unsuccessful therefore I have turned to this community to seek assistance.
My configuration: Home Assistant on a Raspberry PI4 with Home Assistant 2023.3.2; Supervisor 2023.03.1; Operating System 9.5; Frontend 20230306.0 - latest. Sensor is a Sengled Door/Window sensor; Alexa device is an Echo Dot 2nd Gen. My HA configuration includes HACs 1.31.0 with Alexa Media Player v4.6.1 installed.
Overview: I’ve created an automation that notifies me when mail is inserted into my mailbox. Notification comes through my mobile app using the HA Companion App as well as voice notification on my Echo device in my office. The automation was created following instruction from Ed on SmartHomeJunkie. I’ve also referenced Mark Watt Tech for information related to Notify.Alexa and playing local MP3 files on an Alexa device.
Problem: I’ve create the automation in HA using the visual editor and then switched to YAML view to see the YAML code that gets generated. I use the YAML view to fill in some additional detail for the automation as I find it easier to understand than the visual editor. Once I make the necessary updates and save the changes (but NOT exit the YAML view) the automation is able to be run and works as expected and the local MP3 file is played through the designated Echo device. The troubles begin once I close the YAML view/editor. Upon closing the view, the local MP3 file will no longer play and an error is spoken through the Echo device.
What I’ve observed is that when I go back into the editor to view the YAML file for the automation I see the syntax of the YAML file, in particular the line containing the ‘message: audio src=’ has been changed. This is what is causing the local MP3 file to no longer be able to be played – instead the error message is spoken through the device.
I realize changes could be made to have Alexa use TTS and speak a message however my goal is to be able to create additional automations that use messages and sounds in MP3 formatted files that I create. Furthermore, the issue I am experiencing isn’t in regard to getting the MP3 file to play but instead the issue is with how HA is changing the syntax of a ‘working’ automation in the service section calling Notify.Alexa into a format that does not work.
MY QUESTION: Has anyone experienced the ‘reformatting of YAML’ and how did you stop it from happening? I have included a copy of the automation (YAML format) below. Both the working version followed by the ‘non-working, reformatted’ version. I’ve changed the device ID & name and domain name for privacy. Sorry for the length of this post. This is my first post to the group, thanks in advance for the help!
WORKING VERSION
alias: "Mailbox: New mail notification"
description: ""
trigger:
- type: opened
platform: device
device_id: e33333b43ad781f8ce34ef3309b65421
entity_id: binary_sensor.mailbox_sensor_contact
domain: binary_sensor
condition: []
action:
- service: input_boolean.turn_on
data: {}
target:
entity_id: input_boolean.mail_arrived
- service: input_datetime.set_datetime
data:
timestamp: "{{ now().timestamp() }}"
target:
entity_id: input_datetime.mailbox_last_triggered
- service: notify.mobile_app_sm_g988u1
data:
message: The mail has been delivered.
title: Mail Delivered.
- service: notify.alexa_media_jds_echo_dot
data:
message:
<audio src='https://myhome.duckdns.org/local/alexa_ready_youve-got-mail.mp3'/>
mode: single
NON-WORKING VERSION (syntax changed upon closing yaml in HA)
alias: "Mailbox: New mail notification"
description: ""
trigger:
- type: opened
platform: device
device_id: e33333b43ad781f8ce34ef3309b65421
entity_id: binary_sensor.mailbox_sensor_contact
domain: binary_sensor
condition: []
action:
- service: input_boolean.turn_on
data: {}
target:
entity_id: input_boolean.mail_arrived
- service: input_datetime.set_datetime
data:
timestamp: "{{ now().timestamp() }}"
target:
entity_id: input_datetime.mailbox_last_triggered
- service: notify.mobile_app_sm_g988u1
data:
message: The mail has been delivered.
title: Mail Delivered.
- service: notify.alexa_media_jds_echo_dot
data:
message: >-
<audio
src='https://myhome.duckdns.org/local/alexa_ready_youve-got-mail.mp3'/>
mode: single