Trigger Action on Wake

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

  • Publish an MQTT message
  • Do an http request

Kind Regards

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.

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

2 Likes

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

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.

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()
1 Like

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!

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

1 Like