Using a scene to lock a door

I am attempting to lock my front door using a z-wave yale lock when triggering this scene

  - name: Goodnight
      entities:
        group.lights: off
        switch.living_room_fan_switch: off
        media_player.apple_tv: off
        switch.garage_light: off
        lock.front_door_lock_locked: lock

This results in the following error:

[homeassistant.helpers.state] reproduce_state: Unable to reproduce state <state lock.front_door_lock_locked=lock

I then switched to trying to trigger an automation using the scene event as a trigger:

- id: lock_door_using_scene
  alias: Lock Front Door Using Scene
  trigger:
    - platform: event
      event_type: call_service
      event_data:
        service_data:
          entity_id: scene.goodnight
        domain: scene
        service: turn_on
  action:
    - service: lock.lock
      entity_id: lock.front_door_lock_locked

This works when I turn_on the scene via the service panel in the web app but does not work when I invoke the scene using Alexa. The scene is turned on but the automation never triggers.

I’m using Alexa via emulated_hue:

emulated_hue:
  off_maps_to_on_domains:
    - script
    - scene
  exposed_domains:
    - scene
    - input_boolean
    - switch

My full configuration can be found here https://github.com/lucasweb78/home-assistant-config

Questions:

  1. Why did using the scene to trigger the lock service not work?
  2. Why do I not get the scene turn_on event when using Alexa but I do when triggering in in the service panel?
  3. Is there a better way to achieve what I’m trying to do?

Thanks in advance

UPDATE
Looking through the logs, this is what happens when using Alexa

2017-09-02 07:54:59 INFO (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: domain=homeassistant, service=turn_on, service_data=entity_id=scene.going_to_bed, service_call_id=4480884632-35>
2017-09-02 07:54:59 DEBUG (MainThread) [homeassistant.components.api] STREAM 4489665632 FORWARDING <Event call_service[L]: domain=scene, service=turn_on, service_data=entity_id=['scene.going_to_bed'], service_call_id=4480884632-36>
2017-09-02 07:54:59 DEBUG (MainThread) [homeassistant.components.api] STREAM 4489665568 WRITING data: {"event_type": "call_service", "data": {"domain": "scene", "service": "turn_on", "service_data": {"entity_id": ["scene.going_to_bed"]}, "service_call_id": "4480884632-36"}, "origin": "LOCAL", "time_fired": "2017-09-02T14:54:59.311188+00:00"}
2017-09-02 07:54:59 DEBUG (MainThread) [homeassistant.components.api] STREAM 4489665600 WRITING data: {"event_type": "call_service", "data": {"domain": "scene", "service": "turn_on", "service_data": {"entity_id": ["scene.going_to_bed"]}, "service_call_id": "4480884632-36"}, "origin": "LOCAL", "time_fired": "2017-09-02T14:54:59.311188+00:00"}
2017-09-02 07:54:59 DEBUG (MainThread) [homeassistant.components.api] STREAM 4489665616 WRITING data: {"event_type": "call_service", "data": {"domain": "scene", "service": "turn_on", "service_data": {"entity_id": ["scene.going_to_bed"]}, "service_call_id": "4480884632-36"}, "origin": "LOCAL", "time_fired": "2017-09-02T14:54:59.311188+00:00"}
2017-09-02 07:54:59 DEBUG (MainThread) [homeassistant.components.api] STREAM 4489665632 WRITING data: {"event_type": "call_service", "data": {"domain": "scene", "service": "turn_on", "service_data": {"entity_id": ["scene.going_to_bed"]}, "service_call_id": "4480884632-36"}, "origin": "LOCAL", "time_fired": "2017-09-02T14:54:59.311188+00:00"}

this is what happens when using the service panel

017-09-02 07:56:35 INFO (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: domain=scene, service=turn_on, service_data=entity_id=scene.going_to_bed, service_call_id=4480884632-43>
2017-09-02 07:56:35 DEBUG (MainThread) [homeassistant.components.api] STREAM 4489665568 FORWARDING <Event call_service[L]: domain=scene, service=turn_on, service_data=entity_id=scene.going_to_bed, service_call_id=4480884632-43>
2017-09-02 07:56:35 DEBUG (MainThread) [homeassistant.components.api] STREAM 4489665600 FORWARDING <Event call_service[L]: domain=scene, service=turn_on, service_data=entity_id=scene.going_to_bed, service_call_id=4480884632-43>
2017-09-02 07:56:35 DEBUG (MainThread) [homeassistant.components.api] STREAM 4489665616 FORWARDING <Event call_service[L]: domain=scene, service=turn_on, service_data=entity_id=scene.going_to_bed, service_call_id=4480884632-43>
2017-09-02 07:56:35 DEBUG (MainThread) [homeassistant.components.api] STREAM 4489665632 FORWARDING <Event call_service[L]: domain=scene, service=turn_on, service_data=entity_id=scene.going_to_bed, service_call_id=4480884632-43>
2017-09-02 07:56:35 DEBUG (MainThread) [homeassistant.components.api] STREAM 4489665568 WRITING data: {"event_type": "call_service", "data": {"domain": "scene", "service": "turn_on", "service_data": {"entity_id": "scene.going_to_bed"}, "service_call_id": "4480884632-43"}, "origin": "LOCAL", "time_fired": "2017-09-02T14:56:35.484596+00:00"}
2017-09-02 07:56:35 DEBUG (MainThread) [homeassistant.components.api] STREAM 4489665600 WRITING data: {"event_type": "call_service", "data": {"domain": "scene", "service": "turn_on", "service_data": {"entity_id": "scene.going_to_bed"}, "service_call_id": "4480884632-43"}, "origin": "LOCAL", "time_fired": "2017-09-02T14:56:35.484596+00:00"}
2017-09-02 07:56:35 DEBUG (MainThread) [homeassistant.components.api] STREAM 4489665616 WRITING data: {"event_type": "call_service", "data": {"domain": "scene", "service": "turn_on", "service_data": {"entity_id": "scene.going_to_bed"}, "service_call_id": "4480884632-43"}, "origin": "LOCAL", "time_fired": "2017-09-02T14:56:35.484596+00:00"}
2017-09-02 07:56:35 DEBUG (MainThread) [homeassistant.components.api] STREAM 4489665632 WRITING data: {"event_type": "call_service", "data": {"domain": "scene", "service": "turn_on", "service_data": {"entity_id": "scene.going_to_bed"}, "service_call_id": "4480884632-43"}, "origin": "LOCAL", "time_fired": "2017-09-02T14:56:35.484596+00:00"}
2017-09-02 07:56:35 INFO (MainThread) [homeassistant.components.automation] Executing Lock Front Door Using Scene
2017-09-02 07:56:35 INFO (MainThread) [homeassistant.core] Bus:Handling <Event logbook_entry[L]: name=Lock Front Door Using Scene, message=has been triggered, domain=automation, entity_id=automation.lock_front_door_using_scene>

It appears the stream is only forwarded once when using Alexa STREAM 4489665632 FORWARDING but 4 times when using the service panel:

2017-09-02 07:56:35 DEBUG (MainThread) [homeassistant.components.api] STREAM 4489665568 FORWARDING <Event call_service[L]: domain=scene, service=turn_on, service_data=entity_id=scene.going_to_bed, service_call_id=4480884632-43>
2017-09-02 07:56:35 DEBUG (MainThread) [homeassistant.components.api] STREAM 4489665600 FORWARDING <Event call_service[L]: domain=scene, service=turn_on, service_data=entity_id=scene.going_to_bed, service_call_id=4480884632-43>
2017-09-02 07:56:35 DEBUG (MainThread) [homeassistant.components.api] STREAM 4489665616 FORWARDING <Event call_service[L]: domain=scene, service=turn_on, service_data=entity_id=scene.going_to_bed, service_call_id=4480884632-43>
2017-09-02 07:56:35 DEBUG (MainThread) [homeassistant.components.api] STREAM 4489665632 FORWARDING <Event call_service[L]: domain=scene, service=turn_on, service_data=entity_id=scene.going_to_bed, service_call_id=4480884632-43>

Although I’m not really sure what that means

Amusingly I have entities named the exact same things as both scene.goodnight and lock.front_door_lock_locked.

I concluded a while back that the scene itself can’t be used to lock the door. I believe the problem with your automation is triggering the scene via emulated hue. Emulated Hue pretends everything is a light, so it probably doesn’t call the service scene.turn_on - it probably calls either light.turn_on or homeassistant.turn_on. You might try deleting your line domain: scene and see if that fixes it for emulated hue.

I am using a different setup with Alexa to trigger scenes with a custom skill. That skill does call scene.turn_on so I believe the automation you have here should work fine in my case.

So you are able to lock the door with Alexa? What is your custom skill?

For Alexa and locks I created scripts to lock and unlock the doors, then add the scripts to my scenes and emulated hue. Here is part of my config:

  lock_front_door:
    sequence:
      - service: lock.lock
        data:
          entity_id: lock.front_door
  unlock_front_door:
    sequence:
      - service: lock.unlock
        data:
          entity_id: lock.front_door

I was curious about this but from what I’m reading using the scene directly isn’t possible. I’m currently just calling the lock.lock service as one of the actions in the automation.

this is my automation:

- id: sunset
  alias: Sunset
  trigger:
    platform: sun
    event: sunset
  action:
  - service: scene.turn_on
    entity_id: scene.sunset
  - service: lock.lock
    entity_id: group.security