Alexa Cuckoo Clock Yaml Issue

Hey everyone, just need some advice here. I pulled some code from
AlexaCuckoo/Alexa_Cuckoo_Clock.yaml at bc87b7629280d62a5d869f96f5f4dc8e889cfbce · Didgeridrew/AlexaCuckoo · GitHub in order to get this working with Alexa Media, but I’m running into what feels like endless errors and the final section is what’s killing it.

Here’s the original code:
#automations.yaml

- alias: Alexa - Notify - Cuckoo Clock
  trigger:
  - platform: time_pattern
    minutes: '30'
  - platform: time_pattern
    minutes: '0'
  condition:
  - condition: time
    after: '08:59:00'
    before: '20:31:00'
  - condition: or
    conditions:
    - condition: state
      entity_id: group.family
      state: home
    - condition: state
      entity_id: input_boolean.guest_mode
      state: 'on'
  action:
  - choose:
    - conditions: >-
      {% set ns = namespace(volumes = []) %}
      {% for s in ['media_player.living_room_dot', 'media_player.basement_dot'] %}
      {% set x = is_state_attr(s, 'volume_level', 0.3) %}
      {% set ns.volumes = ns.volumes + ['{}'.format(x)] %}
      {% endfor %}
      {{ 'False' in ns.volumes }}"
      sequence:
      - service: media_player.volume_set
        data:
          entity_id:
          - media_player.living_room_dot
          - media_player.basement_dot
          volume_level: 0.3
  - delay: 3
  - service: notify.alexa_media
    data:
      message: '{{cuckoos}}'
      target:
      - media_player.basement_dot
      - media_player.living_room_dot
      data:
        type: tts
  mode: restart
  variables:
    cuckoos: >-
      {% if now().strftime(\"%M\")|int == 30 %}
      {{"<audio src='https://***YOUR_IP_HERE***/local/mp3/config-sounds-cuckoo-clock-01.mp3'/>\"}}
      {% else %}
      {{"<audio src='https://***YOUR_IP_HERE***/local/mp3/config-sounds-cuckoo-clock-\" + now().strftime(\"%I\") + \".mp3'/>\"}}
      {% endif %}"

Here’s my altered version so far:

automation:
  - alias: Alexa - Notify - Cuckoo Clock
    trigger:
    - platform: time_pattern
      minutes: '30'
    - platform: time_pattern
      minutes: '0'
    condition:
    - condition: time
      after: '08:59:00'
      before: '20:31:00'
    action:
    - choose:
      - conditions: >-
          {% set ns = namespace(volumes = []) %}
          {% for s in ['media_player.living_room_show', 'media_player.kitchen_flex'] %}
          {% set x = is_state_attr(s, 'volume_level', 0.3) %}
          {% set ns.volumes = ns.volumes + ['{}'.format(x)] %}
          {% endfor %}
          {{ 'False' in ns.volumes }}"
        sequence:
        - service: media_player.volume_set
          data:
            entity_id:
            - media_player.living_room_show
            - media_player.kitchen_flex
            volume_level: 0.3
    - delay: 3
    - service: notify.alexa_media
      data:
        message: '{{cuckoos}}'
        target:
        - media_player.kitchen_flex
        - media_player.living_room_show
        data:
          type: tts
    mode: restart
    variables:
      cuckoos: >-
        {% if now().strftime("%M")|int == 30 %}
        {{ "<audio src='https://HAInstance/local/mp3/config-sounds-cuckoo-clock-01.mp3'/>\" }}
        {% else %}
        {{ "<audio src='https://HA Instance/local/mp3/config-sounds-cuckoo-clock-\ + now().strftime("%I") + \.mp3'/>\" }}
        {% endif %}"

And the log error plauguing me:

There are 12 audio files it calls from (from 1 chime to 12), if it helps make sense of it.
Any help would be greatly appreciated

The issue is the vestigal " at the end of the template… Which is my fault because I never removed it from the git. If you’re interested, I have simplified the automation a bit with some of the newer additions to templating.

automation:
  - alias: Alexa - Notify - Cuckoo Clock
    trigger:
    - platform: time_pattern
      minutes: '30'
      id: half
    - platform: time_pattern
      minutes: '0'
    condition:
    - condition: time
      after: '08:59:00'
      before: '20:31:00'
    action:
    - choose:
      - conditions: >-
          {{ (expand('media_player.living_room_show', 'media_player.kitchen_flex')
          | map(attribute='attributes.volume_level') | map('float')
          | select('ne', 0.3) | list | count) | bool }}
        sequence:
          - service: media_player.volume_set
            data:
              entity_id:
                - media_player.living_room_show
                - media_player.kitchen_flex
              volume_level: 0.3
    - delay: 3
    - service: notify.alexa_media
      data:
        message: '{{cuckoos}}'
        target:
          - media_player.kitchen_flex
          - media_player.living_room_show
        data:
          type: tts
    mode: restart
    variables:
      cuckoos: >-
        {% if trigger.id == 'half' %}
        {{ "<audio src='https://HAInstance/local/mp3/config-sounds-cuckoo-clock-01.mp3'/>\" }}
        {% else %}
        {{ "<audio src='https://HA Instance/local/mp3/config-sounds-cuckoo-clock-\ + now().strftime("%I") + \.mp3'/>\" }}
        {% endif %}
1 Like

Awesome! So glad to hear it from the source. Going to make the code change in a few

EDIT: Still getting thrown the same ‘expecting end of print statement’ got src error.

It seems to be related to the Hour chime. The half hour plays as expected on the 30 with some adjustments I made, but the hour fails and she just says “having a problem with your Simon says skill” or something to that effect.

It seems it may not recognize the call to select the correct cuckoo file for the hour. Unfortunately I’m not fantastic with templating so I’m unsure of how to fix it

Solved!

after looking back, somehow I ended up with

{{ '<audio src="https://IPAdress/local/mp3/{{now().strftime("%I")}}-hour.mp3"/>' }}

This was the problem as the audio files are config-cuckoo-clock-01.mp3 and so on.
Took me a bit to follow along and realize it needed to look like this instead

{{ '<audio src="IPAddress/local/mp3/config-sounds-cuckoo-clock-{{now().strftime("%I")}}.mp3"/>' }}

but now it’s working perfectly