Get entity state from Alexa and push to Home Assistant

I have a Schlage Encode smart lock on my front door which Alexa can control. I want to be able to control the lock and view its status from Home Assistant, but it’s not currently supported.

My first workaround for getting the lock status failed for a frustrating reason. I created a Dummy Light in HA, exposed it to Alexa via Nabu Casa, and was able to control it / see it update in HA in real time. Then, I created two routines in Alexa:

  1. If door is locked, turn on Dummy Light
  2. If door is unlocked, turn off Dummy Light

The frustrating part: Despite lock / unlock being available as a trigger in Alexa’s routines, the routines simply will not fire. I tried using the Schlage App, the keypad, yelling at God, and using voice to lock/unlock. No matter what I did, the trigger would not register, so my Dummy Light never changed.

So, I tried some other hacky stuff to see if I could at least control the lock, and I was partially successful. The setup:

  1. A binary Dummy Motion Sensor which was exposed to Alexa
  2. A boolean switch that toggles the “motion” state of the dummy motion sensor, from “detected” to “not detected” and exposed that to Alexa
  3. An Alexa Routine which triggered the door to “Lock” when the Dummy Motion Sensor saw motion

Using this, I was able to use HA to activate the lock. Unlocking could be achieved through sending a TTS message w/ my voice unlock code, but without being able to read the state of the lock, it’s not very useful for my dashboard.

Curious if anyone has ideas for how to read the state of the lock from Alexa, and pass it to HA? One idea that crossed my mind was polling Alexa using TTS on a regular basis, but I’d like a less hacky solution if one exists. Any ideas appreciated.

1 Like

Have a look at voice monkey.
It might help you to trigger Alexa routines from HA. Maybe you will be able later to implement something easier to read the state of the lock.

Hey thanks for the tip!

I’m going to keep digging through their docs, but at first glance it looked like an alternative to what I can do using Nabu + Alexa Media Player. I’ll read on, but if you can describe the incremental benefit I’m all ears.

Hi,
I just discovered Voice Monkey yesterday when I googled your kind of lock.

What did you try to use for triggering the routines?

Since you later (at 3.) were telling Alexa can control your lock by what I think are actions, my suggestion is to trigger two Alexa routines by so called monkeys from VM (Voice Monkey) which would lock/unlock the lock and another routine which toggles the state of a dummy device, when the former actions were fired.

I use a Nuki lock for which I neither need the Nuki Skill, dummy device nor Voice Monkey 'cause its state is directly polled from the lock. I have two buttons who trigger shell_commands for lock/unlocking it and they also reflecting the state of the lock:

Based on this buttons I gave it quick shot and used a similar code but with VM and rest_commands.
Clicking the HA button starts a script which triggers a VM monkey → which triggers an Alexa routine via the VM Skill → which fires the lock action. When the lock action completes another Alexa routine fires an action to toggle the state of a dummy light, which also changes the color of the circles in both buttons.

Video_2021-12-07_163940
The chain HA buttons/script → VM monkeys → Alexa VM Skill → Alexa routine → than triggering the lock or a dummy light is surprisingly fast, but it takes a certain amount of time until the lock itself finishes…

How to start?
Register with Voice Monkey, create two monkeys and install the VM Skill.

Create two routines in Alexa, look in Smart Home for the two monkeys you created (you might have to refresh the view in Alexa to see them) and use them as trigger. As action use the lock/unlock actions of the lock.
For the unlocking action I understand you need to send use a voice command (Alexa says?) a TTS message with the unlock code.

If this is working, means if the monkeys trigger your lock from the Manage Monkeys page, you create two other routines which toggles the state of a proxy device HA is able to “see”/read - in the example code below it’s light.virtual_dummy.
The trigger for this routines is the lock/unlock action of the lock and as action toggle the dummy light.

Now you can create two buttons in HA which trigger the monkeys by rest_commands (via scripts), locking/unlocking the lock and reflecting its state, respectively the state of its proxy.

Here’s the code for the buttons (I am not the creator of this code, I just altered it for this case):

type: vertical-stack
cards:
  - type: horizontal-stack
    cards:
      - type: custom:button-card
        tap_action:
          action: call-service
          service: script.dummyon
          service_data: null
        color_type: card
        color: white
        icon: hass:lock
        name: locked
        styles:
          card:
            - background-color: rgb(131,131,131)
            - border-radius: 5%
            - padding: 10%
            - color: white
            - font-size: 14px
            - text-shadow: 0px 0px 0px black
            - text-transform: capitalize
          grid:
            - position: relative
          custom_fields:
            notification:
              - background-color: |
                  [[[
                    if (states['light.virtual_dummy'].state == 'on')
                      return "green";
                    return "red";
                  ]]]
              - border-radius: 50%
              - position: absolute
              - left: 60%
              - top: 10%
              - height: 28px
              - width: 28px
              - font-size: 0px
              - line-height: 20px
        custom_fields:
          notification: |
            [[[ return Math.floor(states['light.virtual_dummy'].state) ]]]
      - type: custom:button-card
        tap_action:
          action: call-service
          service: script.dummyoff
          service_data: null
        color_type: card
        color: white
        icon: hass:lock-open
        name: unlocked
        styles:
          card:
            - background-color: rgb(131,131,131)
            - border-radius: 5%
            - padding: 10%
            - color: white
            - font-size: 14px
            - text-shadow: 0px 0px 0px black
            - text-transform: capitalize
          grid:
            - position: relative
          custom_fields:
            notification:
              - background-color: |
                  [[[
                    if (states['light.virtual_dummy'].state == 'off')
                        return "green";
                    return "red";
                  ]]]
              - border-radius: 50%
              - position: absolute
              - left: 60%
              - top: 10%
              - height: 28px
              - width: 28px
              - font-size: 0px
              - line-height: 20px
        custom_fields:
          notification: |
            [[[ return Math.floor(states['light.virtual_dummy'].state) ]]]

Create two scripts and use them in the above code.

dummyon:
  alias: DummyOn
  sequence:
  - service: rest_command.trigger_monkey1
  mode: single
dummyoff:
  alias: DummyOff
  sequence:
  - service: rest_command.trigger_monkey2
  mode: single

The rest_commands in my rest_commands.yaml

#voice monkey
trigger_monkey1:
  url: https://api.voicemonkey.io/trigger 
  method: POST
  verify_ssl: true
  content_type: 'application/json; charset=utf-8'
  payload: !secret monkey_payload_1
trigger_monkey2:
  url: https://api.voicemonkey.io/trigger 
  method: POST
  verify_ssl: true
  content_type: 'application/json; charset=utf-8'
  payload: !secret monkey_payload_2

The payloads used in secrets.yaml, calling the monkeys dummyon & dummyoff (insert your tokens and the names of your monkeys)

monkey_payload_1: '{"access_token":"ATOKEN","secret_token":"STOKEN","monkey":"dummyon"}'
monkey_payload_2: '{"access_token":"ATOKEN","secret_token":"STOKEN","monkey":"dummyoff"}'

Good luck.

2 Likes

Hey, I have been swamped the past couple of weeks so I haven’t had a chance to try this. So until that day comes I just wanted to thank you for taking the time. It looks promising!

Darn this encode lock. Trying to pull it into HA has been more difficult than I thought. I dont have nabu. Are you currently able to lock/unlock your encode using nabu. I thought Nabu pulled HA devices into the Alexa world making them usable with a “hey alexa” but didnt bring alexa devices into HA. I dont even have an Alexa but though I might use voicemonkey to trigger an alexa routine to open the lock but not sure that is possible considering it seems you need to send a code via TTS. In any case you have gotten much further than others… Can voicemonkey actually trigger the routine to open the encode before I start going through a lot of set up for this workaround