Echo Devices (Alexa) as Media Player - Testers Needed

I use alexa_Media Player for an alarm automation but i’ve got the following error

'NoneType' object has no attribute 'is_on'
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 133, in handle_call_service
    connection.context(msg),
  File "/usr/src/homeassistant/homeassistant/core.py", line 1233, in async_call
    await asyncio.shield(self._execute_service(handler, service_call))
  File "/usr/src/homeassistant/homeassistant/core.py", line 1258, in _execute_service
    await handler.func(service_call)
  File "/usr/src/homeassistant/homeassistant/components/script/__init__.py", line 139, in service_handler
    if script.is_on:
AttributeError: 'NoneType' object has no attribute 'is_on'

after HA restart it works but after a while if got the same error message.

One example for a lightloop script

alarm_licht_loop:
  alias: Alarm Licht Wiederholung
  sequence:
  - condition: or
    conditions:
    - condition: state
      entity_id: alarm_control_panel.alarmanlage
      state: pending
    - condition: state
      entity_id: alarm_control_panel.alarmanlage
      state: armed_away
    - condition: state
      entity_id: alarm_control_panel.alarmanlage
      state: armed_night
    - condition: state
      entity_id: alarm_control_panel.alarmanlage
      state: triggered
  - data:
      entity_id: script.alarm_licht_an
    service: script.turn_off
  - delay: 00:00:03
  - service: script.alarm_licht_an
alarm_licht_an:
  alias: Alarm Licht an
  sequence:
  - condition: or
    conditions:
    - condition: state
      entity_id: alarm_control_panel.alarmanlage
      state: pending
    - condition: state
      entity_id: alarm_control_panel.alarmanlage
      state: armed_away
    - condition: state
      entity_id: alarm_control_panel.alarmanlage
      state: armed_night
    - condition: state
      entity_id: alarm_control_panel.alarmanlage
      state: triggered
  - device_id: a649f4db576049c4be532d61d2041513
    domain: light
    entity_id: light.eingang
    type: turn_on
  - device_id: ae153657c5c3495d8bb190b24e7fb1e2
    domain: light
    entity_id: light.kuechen_decke
    type: turn_on
  - device_id: ca6d74e907f342fea91cae5f2347dde0
    domain: light
    entity_id: light.treppe
    type: turn_on
  - 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
  - delay: 00:00:20
  - service: script.alarm_licht_loop

another example for an script with alexa_mediaplayer

alarm_sound1_loop:
  alias: Alarm Hundebellen Wiederholung
  sequence:
  - condition: or
    conditions:
    - condition: state
      entity_id: alarm_control_panel.alarmanlage
      state: pending
    - condition: state
      entity_id: alarm_control_panel.alarmanlage
      state: armed_away
    - condition: state
      entity_id: alarm_control_panel.alarmanlage
      state: armed_night
    - condition: state
      entity_id: alarm_control_panel.alarmanlage
      state: triggered
  - data:
      entity_id: script.alarm_sound1_an
    service: script.turn_off
  - delay: 00:00:03
  - service: script.alarm_sound1_an
alarm_sound1_an:
  alias: Alarm Hundebellen an
  sequence:
  - condition: or
    conditions:
    - condition: state
      entity_id: alarm_control_panel.alarmanlage
      state: pending
    - condition: state
      entity_id: alarm_control_panel.alarmanlage
      state: armed_away
    - condition: state
      entity_id: alarm_control_panel.alarmanlage
      state: armed_night
    - condition: state
      entity_id: alarm_control_panel.alarmanlage
      state: triggered
  - data:
      entity_id: media_player.radio_kuche
      volume_level: 0.5
    service: media_player.volume_set
  - data:
      entity_id: media_player.radio_kuche
      media_content_id: Hundebellen - 2 große Hunde bellen bei Türklingel, bellender
        Hund
      media_content_type: AMAZON_MUSIC
    service: media_player.play_media
  - delay: 00:00:35
  - service: script.alarm_sound1_an    

i use those scripts for an alarm automation.
at the light script it helps if it turn the lights on…

example light on

    domain: light
    entity_id: light.eingang
    type: turn_on

… befor i lets start the flash function

example for flash of hue lights

  - data:
      brightness: 255
      entity_id: light.eingang
      flash: long
    service: light.turn_on

But the problem is that i have no idea how i can solve this issue with the alexa_mediaplayer

Have anyone a idea what could going wrong with this or what i can do as workaround for the use of alexa media player?

Or have anyone a script example (with loop) that works?

Just one question:
Why don’t you work with

- service: light.turn_on
    data:
      entity_id: light.treppe
      color_temp: 250
      brightness: 250
      flash: long

?

Hi,
I got this issue this night:

Thu Oct 24 2019 05:10:50 GMT+0200 (Mitteleuropäische Sommerzeit)
Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/config/custom_components/alexa_media/__init__.py", line 390, in update_devices
    raw_notifications = await AlexaAPI.get_notifications(login_obj)
  File "/usr/local/lib/python3.7/site-packages/alexapy/alexaapi.py", line 689, in get_notifications
    '/api/notifications'
  File "/usr/local/lib/python3.7/site-packages/alexapy/alexaapi.py", line 134, in _static_request
    ssl=login._ssl,
  File "/usr/local/lib/python3.7/site-packages/aiohttp/client.py", line 504, in _request
    await resp.start(conn)
  File "/usr/local/lib/python3.7/site-packages/aiohttp/client_reqrep.py", line 847, in start
    message, payload = await self._protocol.read()  # type: ignore  # noqa
  File "/usr/local/lib/python3.7/site-packages/aiohttp/streams.py", line 591, in read
    await self._waiter
aiohttp.client_exceptions.ServerDisconnectedError: None

Everything workes so far.
Something we have to keep an eye on?

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.