ChristopherRogers1991 / mycroft-hue

A Mycroft skill for controlling Phillips Hue lights
GNU General Public License v3.0
16 stars 16 forks source link

Scenes can not be activated #37

Open Burbelrain opened 1 year ago

Burbelrain commented 1 year ago

Hi Everyone,

I am running Picroft version 21.2.2 in German Language.

As soon as I try to activate an existing scene (in this case "Schlafen") I get the error (self.speak_dialog('scene.not.found', {'scene': scene_name}) for not finding the this scene.

This is what Debug looks like:

 18:14:47.996 | DEBUG    |   778 | mycroft.skills.intent_service:_normalize_all_utterances:72 | Utterances: [('Stelle die Lichter auf Schlafen', 'stelle die lichter auf schlafen')]
 18:14:48.049 | DEBUG    |   778 | mycroft.skills.intent_services.padatious_service:_match_level:47 | Padatious Matching confidence > 0.95
 18:14:51.032 | DEBUG    |   778 | urllib3.connectionpool | Starting new HTTPS connection (1): api.mycroft.ai:443

Now the strange thing is that if I try a non existing scene, I get a total different error:


 18:14:53.283 | DEBUG    |   778 | mycroft.skills.intent_service:_normalize_all_utterances:72 | Utterances: [('Stelle die Lichter auf Schlafe', 'stelle die lichter auf schlafe')]
 18:14:53.346 | DEBUG    |   778 | mycroft.skills.intent_services.padatious_service:_match_level:47 | Padatious Matching confidence > 0.95
 18:14:53.422 | DEBUG    |   778 | mycroft.skills.fallback_skill:handler:67 | Checking fallbacks in range 0 - 5
 18:14:53.480 | DEBUG    |   778 | mycroft.skills.fallback_skill:handler:67 | Checking fallbacks in range 5 - 90
 18:14:53.484 | INFO     |   778 | QuestionsAnswersSkill | Searching for Stelle die Lichter auf Schlafe
 18:14:53.494 | DEBUG    |   778 | mycroft.skills.mycroft_skill.event_container:add:153 | Added event: fallback-query.mycroftai:QuestionQueryTimeout
 18:14:54.034 | DEBUG    |   778 | mycroft.skills.mycroft_skill.event_container:remove:163 | Removing event fallback-query.mycroftai:QuestionQueryTimeout
 18:14:54.035 | INFO     |   778 | QuestionsAnswersSkill | Timeout occured check responses
 18:14:54.547 | DEBUG    |   778 | mycroft.skills.fallback_skill:handler:67 | Checking fallbacks in range 90 - 101

I can replicate this with all of my scenes (hue default ones and custom ones).

So for me it seems like the skill is recognizing the existence and the name of the scene but is not able to make the correlation to the ID of the scene in order to send the correct API call.

I have tried to understand what self.scenes_to_ids_map and self.register_vocabulary is doing but was unable to do so.

Can you help me?

Best Regards Burble

ChristopherRogers1991 commented 1 year ago

Hello Burble,

This skill uses the adapt intent parser. The calls to register_vocabulary register keywords with adapt. Once registered, the skill can define "intents," specifying which keywords are required, optional, etc. Mycroft sends the utterance (the user's spoken phrase, converted to text) to Adapt, which parses the phrase for keywords, and determines which skill and intent should be triggered.

The second error you mentioned looks like it is because Adapt does not associate the phrase you've given with the Hue skill at all - this makes some sense if the scene name is not recognized, because the utterance is lacking that keyword, and likely doesn't contain enough other keywords trigger the Hue skill. From your logs, ultimately Mycroft starts looking for 'fallback' skills, which are intended to catch phrases that don't match any other skill.

The library being used to control the Hue lights requires a scene ID be given, rather than a scene name; to activate a scene this skill must supply that number value, rather than the text name value, so we have to convert from the text value to the numerical value. This is the reason for the scenes_to_ids_map, and is unfortunately not an especially precise process, because it relies on the speech-to-text to give the correct name, properly formatted. You can see at registration time, the skill does some minimal normalization, by just making everything lowercase, and then does the same later when looking for the ID. This can sometimes cause some conflicts, when trying to find activate a scene.

In theory, your error should never happen - adapt should only match the scene intent if a scene name is found (see here, and it is added to the scenes_to_ids_map and registered with adapt with no other changes between (see here. But clearly something is amiss here.

To debug, I've created a branch that has some logging: https://github.com/ChristopherRogers1991/mycroft-hue/compare/missing-scene-log?expand=1

Can you checkout the missing-scene-log branch, attempt to trigger a known scene, and send the logs? You should be able to checkout the branch by just running git fetch && git checkout missing-scene-log from the hue skill directory. (I'm not able to test the changes myself at the moment - I'm away from all of my Hue stuff for the next ~3 weeks - but I think this should work. Please let me know if you hit any issues.)

-Chris

Burbelrain commented 1 year ago

Hi Chris,

First of all thank you for your super fast reply.

Since I am at the begging of my Picroft setup my knowledge is not deep, , please excuse my (future) beginner questions: I have found two possible hue skill directories:

  1. /home/pi/mycroft-core/mycroft/skills/mycroft-hue/
  2. /opt/mycroft/skills/mycroft-hue.christopherrogers1991/

If I go to /home/pi/mycroft-core/mycroft/skills/mycroft-hue/ and use git fetch && git checkout missing-scene-log debug looks the same.

If I go to /opt/mycroft/skills/mycroft-hue.christopherrogers1991/ and do the same hue skill is broken and I get the following errors:

 21:59:01.254 | INFO     |   832 | mycroft.skills.skill_loader:reload:179 | ATTEMPTING TO RELOAD SKILL: mycroft-hue.christopherrogers1991
 21:59:01.260 | INFO     |   832 | mycroft.skills.skill_loader:_execute_instance_shutdown:217 | Skill mycroft-hue.christopherrogers1991 shut down successfully
 21:59:01.270 | DEBUG    |   832 | mycroft.skills.skill_loader:remove_submodule_refs:44 | Skill module: mycroft-hue_christopherrogers1991
 21:59:01.352 | INFO     |   832 | mycroft.skills.settings:get_local_settings:83 | /home/pi/.config/mycroft/skills/mycroft-hue.christopherrogers1991/settings.json
 21:59:01.356 | ERROR    |   832 | mycroft.skills.skill_loader:_create_skill_instance:295 | Skill __init__ failed with AttributeError("'PhillipsHueSkill' object has no attribute 'config'")
Traceback (most recent call last):
  File "/home/pi/mycroft-core/mycroft/skills/skill_loader.py", line 292, in _create_skill_instance
    self.instance = skill_module.create_skill()
  File "/opt/mycroft/skills/mycroft-hue.christopherrogers1991/__init__.py", line 494, in create_skill
    return PhillipsHueSkill()
  File "/opt/mycroft/skills/mycroft-hue.christopherrogers1991/__init__.py", line 99, in __init__
    self.brightness_step = int(self.config.get('brightness_step'))
AttributeError: 'PhillipsHueSkill' object has no attribute 'config'
 21:59:01.360 | ERROR    |   832 | mycroft.skills.skill_loader:_communicate_load_status:351 | Skill mycroft-hue.christopherrogers1991 failed to load
  ^--- NEWEST ---^

If I go back to master with git fetch && git checkout master everything is looking ok. Reboot doesn't changed anything.

Do I miss something?

Best Regards Burble

ChristopherRogers1991 commented 1 year ago

Hmm... this line: self.brightness_step = int(self.config.get('brightness_step')), does not exist in the code. If I recall correctly, there was a change to mycroft-core that had an API break, and I had to update this to use settings map rather than the config map. Based on that, it seems like the version of the skill your picroft is running is several years old (that change was made just over 5 years ago).

How did you install the skill?

I think what we probably want to do is blow away both of your old versions (or if you want to be safe, move them somewhere outside the mycroft skills directories - they can stay on disk as a backup, but they need to be somewhere mycroft is not looking for skills), and then install the latest version (see the steps here).

ChristopherRogers1991 commented 1 year ago

If you have msm installed, you might be able to use mycroft-msm install https://github.com/ChristopherRogers1991/mycroft-hue to install it, rather than using git manually. That might be a little easier than trying to find the right directory, and getting it all set up manually. See https://mycroft-ai.gitbook.io/docs/skill-development/mycroft-skills-manager#from-a-github-repository.

Burbelrain commented 1 year ago

Hi Chris,

I found out why there was old code: I did a manual diff of the __init__.py file and found out the the branch "missing-scene-log" is not based on the current master because there are multiple differences.

Anyway I edited the file manually and this is the debug you wanted: 2023-02-01 16:32:02.231 | DEBUG | 851 | mycroft-hue_christopherrogers1991 | Scene name was nightcity; available scenes are {"2": {"sonnenuntergang savanne": "ZTy7bY5Z-PHZ17m", "nordlichter": "guLxTIG5TBPJWeQ", "tropend\u00e4mmerung": "aCiwZuj57LbsNcv", "fr\u00fchlingsbl\u00fcten": "tm2yvSeqMFPsWBn", "entspannen": "c6d63yyCqnhV6vF", "gedimmt": "LllA6mUBBIz8Lxj", "konzentrieren": "E0ySzGNOnBcdNfA", "hell": "F2CyO0Rd3MonquI", "energie tanken": "Bl2f25u13j-D1rJ", "schlafen": "Mzy5hedEstfEL6M", "lesen": "-Gf41BziLkYEFdF", "goldener teich": "tIkD-ksR4nKG7Bq", "\u2665": "t7HC-DDWSZWVvVf", "nightcity": "Iv2lMTN9VcapBe3"}, "0": {"hell": "DGZWRR35lknfzNL", "gedimmt": "20srjTiUxiNO0cI"}, "null": {}}

Best Regards Burble

ChristopherRogers1991 commented 1 year ago

I found out why there was old code: I did a manual diff of the init.py file and found out the the branch "missing-scene-log" is not based on the current master because there are multiple differences.

oof, my apologies. I'm not sure why my local repo was so out of date - I guess I haven't developed this skill on this machine since copying things over from a backup. Anyway, thanks for manually editing, and providing the log.

I think I know what the issue is. Here's the scenes_to_ids_maps, pretty printed:

{
    "2": {
        "sonnenuntergang savanne": "ZTy7bY5Z-PHZ17m",
        "nordlichter": "guLxTIG5TBPJWeQ",
        "tropend\u00e4mmerung": "aCiwZuj57LbsNcv",
        "fr\u00fchlingsbl\u00fcten": "tm2yvSeqMFPsWBn",
        "entspannen": "c6d63yyCqnhV6vF",
        "gedimmt": "LllA6mUBBIz8Lxj",
        "konzentrieren": "E0ySzGNOnBcdNfA",
        "hell": "F2CyO0Rd3MonquI",
        "energie tanken": "Bl2f25u13j-D1rJ",
        "schlafen": "Mzy5hedEstfEL6M",
        "lesen": "-Gf41BziLkYEFdF",
        "goldener teich": "tIkD-ksR4nKG7Bq",
        "\u2665": "t7HC-DDWSZWVvVf",
        "nightcity": "Iv2lMTN9VcapBe3"
    },  
    "0": {
        "hell": "DGZWRR35lknfzNL",
        "gedimmt": "20srjTiUxiNO0cI"
    },  
    "null": {}
}

My memory seems to have failed me a little here, in addition to the code I was looking at being out of date - the map structure is a little different than I remembered. With the code updated, I'm seeing this is a map from group id -> scene name -> scene id. The scenes are specific to groups, and if you do not specify a group in the command, it uses your default group. If you haven't manually set that to something else, it would be group 0, which is all of the lights associated with the hub. Could you try activating hell or gedimmt, and see if those work?

If those two scenes work, you have three options:

1) Set your default group in the config. See https://github.com/ChristopherRogers1991/mycroft-hue#configuration. 2) Specify the group name in your commands, e.g. 'activate scene nightcity in the living room' (where "living room" is the group name - replace as necessary). 3) Redefine the scenes in terms of group 0.

Option 1 seems best to me - it should be easy to change the config, and based on the number of scenes you have defined there, seems like it's probably what you'd want your default to be anyway.

I thought I had better docs in the README about the default group value, but apparently I don't and will need to add some. In the meantime, the quick version is if you want Mycroft to address a specific set of lights by default, you'll need to set the default group to something other than 0. The default group will be used for all commands - e.g. "turn the lights on" will refer to that specific group only. The idea was if you have multiple Mycroft units in different rooms, you probably don't want the one in the living room to control the lights in the bedroom - each can have their own default group set, and then you don't have to worry about specifying the group (unless you actually want to control lights in another room, in which case you just override it in the command, e.g. "turn the lights on in the kitchen," where kitchen is the group name).

Burbelrain commented 1 year ago

Dear Chris,

Great thanks for the tip, that was exactly the error.

Both the scenes in group 0 and adding the group to the command worked. I then set the default group via https://home.mycroft.ai/#/skill to the value 2 and after a restart everything works.

To be honest this was my first guess before I wrote and after I found out via Hue Api that my scenes were all in the group with ID 2 and not 0. I had already set the default group to 2 at that time, but either not rebooted or only did it only in mycroft.conf, I can't remember exactly.

Thanks again for your super fast help and support.

Best Regards Burble

ChristopherRogers1991 commented 1 year ago

Great! Glad it worked. I'll leave this open until I update the README with better docs about the default group.