Echo Devices (Alexa) as Media Player - Testers Needed

I think this is the issue you are seeing:

Basically, reloading scripts while you have a long-running script like yours (with a loop or a delay) results in that script breaking until a restart. Until this is fixed, you will need to make sure that none of your scripts are executing wile scripts are being reloaded.

1 Like

Just a simple question … does the announce feature work if you point it the whole house audio music group ?

I have a number of echo devices in my lists but they are all out of sync by a few ms

I have the same delay with announce.

@Steven_Rollason ‘ve solved the problem without using scripts and use instead the alexa media player repeat function in the automation

For everyone they are search for an alarmsystem automation with integration of aeotec zwave sensors flashing lights (hue lights over loop script), doorlock (danalock or other), alexa mediaplayer (Sound Alarm on Echo devices) and notification (over mobile phone) feel free to use and adopt my example

configuration.yaml

############
#Alarmanlage
############
alarm_control_panel:
  - platform: manual
    name: alarm_system
    code: 'password'
    code_arm_required: true
    pending_time: 30
    delay_time: 0
    trigger_time: 120
    disarmed:
      trigger_time: 0
    armed_home:
      pending_time: 0
      delay_time: 0

automation.yaml

##########################################################################
# alarm_system
##########################################################################

# automatic arm the alarm_system if all persons left the home, with the trigger of the Danalock doorlock
- id: alarm_system_arm_danalock
  alias: 'alarm_system arm Danalock'
  trigger:
    - platform: time_pattern
    # You can also match on interval. This will match every 30 minutes
      minutes: '/30'
      seconds: 00
    - platform: state
      entity_id:  lock.poly_control_danalock_v3_btze_locked
      from: "unlocked"
      to: "locked"
  condition:
    condition: and
    conditions:
     - condition: state
       entity_id: lock.poly_control_danalock_v3_btze_locked
       state: 'locked'
     - condition: state
       entity_id: person.mike
       state: 'not_home'
     - condition: state
       entity_id: person.dora
       state: not_home
     - condition: state
       entity_id: person.andre
       state: not_home
  action:
   - service: alarm_control_panel.alarm_arm_away
     data:
        entity_id: alarm_control_panel.alarm_system
        code: 'password'

# automatic disarmarm the alarm_system if any person are home, with the trigger of the Danalock doorlock
- id: alarm_system_disarm-danalock
  alias: 'alarm_system disarm Danalock'
  trigger:
    - platform: state
      entity_id:  lock.poly_control_danalock_v3_btze_locked
      from: "locked"
      to: "unlocked"

  condition:
    condition: or
    conditions:
     - condition: state
       entity_id: person.mike
       state: 'home'
     - condition: state
       entity_id: person.dora
       state: home
     - condition: state
       entity_id: person.andre
       state: home

  action:
   - service: alarm_control_panel.alarm_disarm
     data:
        entity_id: alarm_control_panel.alarm_system
        code: 'password'
        
#action (all lights on an script with loop for light show and alexa media player played on echo devices alarmsound) if the alarmsystem was triggered with notification on mobile phone
- id: alarm_system_trigger_absence
  alias: 'alarm_system trigger if alarm_system activ at absence'
  trigger:
    - platform: state
      entity_id: binary_sensor.aeotec_zw100_eingang_sensor
      from: "off"
      to: "on"
    - platform: state
      entity_id: binary_sensor.aeotec_zw100_duschbad_sensor
      from: "off"
      to: "on"

  condition:
    - condition: state
      entity_id: alarm_control_panel.alarm_system
      state: armed_away

  action:
    - service: alarm_control_panel.alarm_trigger
      entity_id: alarm_control_panel.alarm_system
    - service: automation.trigger
      entity_id: automation.alarm_system_notification_if_activiert_at_absence
    - service: light.turn_on
      entity_id: group.all_lights
    - service: switch.turn_off
      entity_id: switch.buro_decke
    - service: script.alarm_light_on
    - service: media_player.play_media
      data:
        entity_id: media_player.radio_kuche
        media_content_id: Siren Auto Alarm
        media_content_type: AMAZON_MUSIC
    - delay: '00:00:02'
    - service: media_player.volume_set
      data: 
        entity_id: media_player.radio_kuche
        volume_level: 1.0
    - delay: '00:00:02'
    - service: switch.turn_on
      data: 
        entity_id: switch.radio_kuche_repeat_switch
    - delay: '00:00:02'

    - service: media_player.play_media
      data:
        entity_id: media_player.radio_duschbad
        media_content_id: Siren Auto Alarm
        media_content_type: AMAZON_MUSIC
    - delay: '00:00:02'
    - service: media_player.volume_set
      data: 
        entity_id: media_player.radio_duschbad
        volume_level: 1.0
    - delay: '00:00:02'
    - service: switch.turn_on
      data: 
        entity_id: switch.radio_duschbad_repeat_switch
    - delay: '00:00:02'
    - service: media_player.play_media
      data:
        entity_id: media_player.radio_wohnzimmer
        media_content_id: Siren Auto Alarm
        media_content_type: AMAZON_MUSIC
    - delay: '00:00:02'
    - service: media_player.volume_set
      data: 
        entity_id: media_player.radio_wohnzimmer
        volume_level: 1.0
    - delay: '00:00:02'
    - service: switch.turn_on
      data: 
        entity_id: switch.radio_wohnzimmer_repeat_switch

#action (reset volume and replay Mediaplayers (Echo devices) and turn off lights) if the alarmsystem was disarmed
- id: alarm_system_disarm
  alias: 'alarm_system disarm'
  trigger:
    - platform: state
      entity_id:  alarm_control_panel.alarm_system
      to: "disarmed"
  action:
   - service: script.turn_off 
     entity_id: script.alarm_light_loop, script.alarm_light_on
   - service: light.turn_off
     entity_id: light.garten, light.eingang, light.kuechen_decke, light.treppe, light.color_temperature_light_1, light.wohnzimmer_leselampe, light.schlafzimmer_decke, light.kinderzimmer_decke
   - service: switch.turn_off
     entity_id: switch.buro_decke
   - service: media_player.media_pause
     entity_id: media_player.radio_kuche, media_player.radio_wohnzimmer, media_player.radio_schlafzimmer, media_player.radio_kinderzimmer, media_player.radio_badezimmer, media_player.radio_duschbad
   - service: switch.turn_off
     entity_id: switch.radio_kuche_repeat_switch, switch.radio_wohnzimmer_repeat_switch, switch.radio_schlafzimmer_repeat_switch, switch.radio_kindezimmer_repeat_switch, switch.radio_badezimmer_repeat_switch, switch.radio_duschbad_repeat_switch
   - service: media_player.volume_set
     data: 
        entity_id: media_player.radio_duschbad
        volume_level: 0.3
   - service: media_player.volume_set
     data: 
        entity_id: media_player.radio_kuche
        volume_level: 0.3
   - service: media_player.volume_set
     data: 
        entity_id: media_player.radio_wohnzimmer
        volume_level: 0.3

# notification on mobile phone if alarmsystem armed 
- id: alarm_system_disarm_notification_absence
  alias: 'alarm_system notification if armed at absence'
  trigger:
    - platform: state
      entity_id: alarm_control_panel.alarm_system
      to: 'armed_away'
  action:
    - service: notify.notify
      data_template:
        message: "ALARM! The alarmsystem is armed because all persons absence {{ states('sensor.date_time') }}"

- id: alarm_system_disarm_notification 
  alias: 'alarm_system notification if alarm_system disarmed'
  trigger:
    - platform: state
      entity_id: alarm_control_panel.alarm_system
      to: 'disarmed'
  action:
    - service: notify.ios_mikes_iphone
      data_template:
        message: "ALARM! The alarm_system is disarmed {{ states('sensor.date_time') }}"

- id: alarm_system_alarm_notification
  alias: 'alarm_system notification if alarm are triggered'
  trigger:
     - platform: state
       entity_id: alarm_control_panel.alarm_system
       to: 'triggered'
  action:
     - service: notify.ios_mikes_iphone
       data:
         message: "ALARM! Alarm is triggered"

script.yaml

alarm_light_on:
  alias: Alarm light on
  sequence:
  - condition: or
    conditions:
    - condition: state
      entity_id: alarm_control_panel.alarm_system
      state: pending
    - condition: state
      entity_id: alarm_control_panel.alarm_system
      state: armed_away
    - condition: state
      entity_id: alarm_control_panel.alarm_system
      state: armed_night
    - condition: state
      entity_id: alarm_control_panel.alarm_system
      state: triggered
  - data:
      brightness: 255
      entity_id: light.eingang
      flash: long
    service: light.turn_on
  - data:
      brightness: 255
      entity_id: light.kuechen_decke
      flash: long
    service: light.turn_on
  - data:
      brightness: 255
      entity_id: light.treppe
      flash: long
    service: light.turn_on
  - data:
      brightness: 255
      entity_id: light.color_temperature_light_1
      flash: long
    service: light.turn_on
  - delay: 00:00:20
  - service: script.alarm_light_loop

alarm_light_loop:
  alias: Alarm light loop
  sequence:
  - condition: or
    conditions:
    - condition: state
      entity_id: alarm_control_panel.alarm_system
      state: pending
    - condition: state
      entity_id: alarm_control_panel.alarm_system
      state: armed_away
    - condition: state
      entity_id: alarm_control_panel.alarm_system
      state: armed_night
    - condition: state
      entity_id: alarm_control_panel.alarm_system
      state: triggered
  - data:
      entity_id: script.alarm_light_on
    service: script.turn_off
  - delay: 00:00:03
  - service: script.alarm_light_on

next step for me is integration of an outdoor zwave flashlight and for the activation by night an automation with door and window zwave sensors. And then an check with notification if any door or window is oppend if we left the house.

Have everyone problems with state change from Echo Dot Gen. 3? In my installation all status changes from all Echo Devices works fine but state changes on the Echo Dot Gen. 3 are most not received frome Alexa Mediaplayer. the commands from the Alexa Mediaplayer to the Echo Dot Gen.3 works fine.

I’ve been trying to do some templating using the sorted_all and sorted_active attributes of the timer and alarm sensors and had problems extracting data from them. This appears to be because the attributes are actually JSON strings and not lists (and you can’t parse json into a list in a template as far as I can tell).
This means that something like this in a template:

{{ state_attr("sensor.kitchen_next_timer", "sorted_all")[0] }}

actually just returns

[

It looks like changing the device_state_attributes property in sensor.py so that

 'sorted_active': json.dumps(self._sorted, default=str),
 'sorted_all': json.dumps(self._all, default=str),

becomes

'sorted_active': self._sorted,
'sorted_all': self._all,

fixes this and makes the attributes return regular Python lists which can be used in templates.

1 Like

Hello guys, It’s me again. Brief recap of my setup: I have built an alarm clock that takes in input a song name z, a time x and an interval of minutes y and repeats on my alexa every y minutes the song z when the current time is past x.

It worked perfectly for a month or so, but now the behaviour is really crazy and I cannot get it to work properly again. I changed nothing. From the log I can see that all my automations are correctly triggered (an automation that calls two scripts: play a song and increase the volume). However, when alexa is in standby the volume is not set… it resets back to None. After some loops apparently it starts to work but it seems random. I cannot get my head around it. It is not even easy to reproduce.

Anybody experienced something like that? Do you have any suggestions like maybe manually change the state to make the alexa responsive 100%, or use a radio instead of a song, dunno… Since it is an allarm it CANNOT fail otherwise I just won’t wake up lol

Thanks.

Ok… I updated to the last version and it seem fixed now. Thanks!

Can you please share your alarmclock configuration im very interested in the option to use alexa from HA as Alarmclock instead to use the Alexa App

Would anyone find value if AMP also was a bluetooth device tracker? The API allows it but I’m not sure about the side effects of having it constantly bluetooth scanning. Let me know. If we had anyone who wanted this, I’d probably need people to volunteer to test to make sure it doesn’t break something important. If you have an opinion/willing to test, let me know in GitHub.

3 Likes

First, I successfully added this to hassio and tested the weather forecast service.

I have a couple of nore-red automations but my automations.yaml is completely empty and I have never coded anything.

So this is what I want to achieve:
Alexa plays weather forecast only 1 time whenever somebody enters the kitchen for the first time. Using a xiaomi motion sensor for this.

  - data:
      entity_id: media_player.my_echo
      media_content_id: Alexa.Weather.Play
      media_content_type: sequence
    service: media_player.play_media

How do I trigger this by the motion sensor AND only 1 time per day?

Would appreciate the code. I assume I will need to add it into automations.yaml ? Restart necessary?

You could add a condition to check if the automation has already been triggered that day.

1 Like

Thanks but I don´t even know how to trigger the sensor output first (again just worked with node-red so far) so can´t figure out how to add an condition either :wink:

Would be great if somebody could pinpoint to a code example of triggering something with a sensor + such a condition.

Try something like this:

- alias: "Alexa Weather"
  trigger:
    - platform: state
      entity_id: binary_sensor.kitchen_motion
      to: 'on'
  condition:
    - condition: template
      value_template: >-
        {% set today = as_timestamp(now()) | timestamp_custom("%w", True) | int %}
        {% set lastTriggered = as_timestamp(state_attr("automation.alexa_weather", "last_triggered")) | timestamp_custom("%w", True) | int %}         

        {{ True if today != lastTriggered else False }}
  action:
    - service: media_player.play_media
      data:
        entity_id: media_player.kitch_echo
        media_content_id: Alexa.Weather.Play
        media_content_type: sequence

Or you use a input_boolean as a condition which is reset a midnight:

input_boolean:
  motion_kitchen_triggered_today:
    name: Triggered today
    initial: off

- alias: "Alexa Weather"
  trigger:
    - platform: state
      entity_id: binary_sensor.kitchen_motion
      to: 'on'
  condition:
    - condition: state
      entity_id: input_boolean.motion_kitchen_triggered_today
      state: 'off'
  action:
    - service: media_player.play_media
      data:
        entity_id: media_player.kitch_echo
        media_content_id: Alexa.Weather.Play
        media_content_type: sequence
    - service: input_boolean.turn_on
      entity_id: input_boolean.motion_kitchen_triggered_today

- alias: "Alexa Weather - Reset"
  trigger:
    - platform: time   
      at: "00:00:00"
  action:
    - service: input_boolean.turn_off
      entity_id: input_boolean.motion_kitchen_triggered_today

Hi all,
i Have a vobot device https://getvobot.com/clock
It has alexa and i installed on Home assistant the Play media component and it discover Vobot.

I’d l’ike to use the buttons on vobot for trigger event in home asssitant.
Every switch or state exposed by the component don’t catch any event.
do you know how i can do?

I managed to add manually via the automation editor a simple “if motion, than play weather”. It works also reliably every time somebody enters the kitchen… :smiley:

The boolean is a big issue. I can test both the weather and reset automation successfully but I can´t get it to triggered by motion.

Does this part go into the automations.yaml or config?

input_boolean:
  motion_kitchen_triggered_today:
    name: Triggered today
    initial: off

Getting following error messages in log depending on which of the two actions I trigger in the automation admin while I have it in the configuration.yaml:

2019-11-08 22:39:44 ERROR (MainThread) [homeassistant.components.automation] Error while executing automation automation.alexa_weather_reset. Service not found for call_service at pos 1: Unable to find service input_boolean/turn_off

2019-11-08 22:39:44 ERROR (MainThread) [homeassistant.components.automation] Error while executing automation automation.alexa_weather_reset. Service not found for call_service at pos 1: Unable to find service input_boolean/turn_off

Edit: I btw also don´t see any card in the “Overview” regarding automations. Just see them in the configuration->automation menu.

The input_boolean belongs in the normal config.

Have it in normal config and getting above error messages in log :frowning:

Were you able to resolve this? I seem to have the same problem. How can I tell which version of alexapy I am running if I’m running latest Alexa Media Player integration (version 2.3.4)?