Trigger Action on Wake


#1

Is it possible to trigger an action when mycroft is woken?
e.g.:

  • Publish an MQTT message
  • Do an http request

Kind Regards


#2

Good question @Digl, I don’t know off the top of my head. @forslund or @Mn0491 might know - they’re very busy with a release today, so may take a little time to come back to you.


#3

You can listen for the mycroft.awoken message and trigger a method. In a skil you’d add something like


    def initialize(self):
        self.add_event('mycroft.awoken', self.my_handler)

    def my_handler(self, message):
        print('I\'m awake')

(skill-naptime does this to unmute the device etc.)

Good luck!
/Åke


#4

Hey!

Are you sure that this is how it’s supposed to work?
I have tried it like you wrote, the event handler gets registered - but it doesn’t trigger on "Hey Mycroft"
Also - the naptime skill only triggers on “Hey Mycroft - Wake up” I think…

I want this to trigger everytime I say “Hey Mycroft”…
Do I need to change mycroft-core for that?

Thanks for your help!
Kind regards


#5

Sorry I got the stand up and wake words confused, I think the closes you’ll get is to listen for recognizer_loop:record_begin which will be sent when a wakeword is detected or a user trigger listening some other way.


#6

Perfect, thx!

if anyone is interested in my solution:

from adapt.intent import IntentBuilder
from mycroft.skills.core import MycroftSkill, intent_handler
from mycroft.util import LOG
from requests import post

class NotifyOnWake(MycroftSkill):

    def __init__(self):
        super(NotifyOnWake, self).__init__(name="NotifyOnWake")

    def initialize(self):
        self.add_event('recognizer_loop:record_begin', self.record_begin_handler)
        self.add_event('recognizer_loop:record_end', self.record_end_handler)

    def record_begin_handler(self, message):
        post(url, data=data) # or do anything else

    def record_end_handler(self, message):
         post(url, data=data) # or do anything else

def create_skill():
    return NotifyOnWake()

#7

Sorry, I’ve got one last question.
Is it somehow possible to query attributes of other skills?

I want to know if Mycroft is “sleeping” and if not do the action (e.g. post).
something like this:

def record_begin_handler(self, message):
    if not naptimeskill.sleeping:
        post(url, data=data)

Thanks for all your help!


#8

Currently not, Sorry. You’ll have to listen for the broadcasts to/from the naptime skill and keep track of it that way.