Skip to content
This repository was archived by the owner on Feb 8, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,43 @@ All notable changes to this project will be documented in this file.

---

#### [1.1.4] - 2018-04-25

- Added command command to stay awake. This cancels the screen timeout
- Added modulemap can now be a set of modules
- Added command to hide all modules except the selected one. This can be a set from the modulemap so
effectively this can be used to show named pages

#### [1.1.3] - 2018-04-20

- Added Google TTS. Many more languages available than pico2tts
Command conversation can now be in languages other than en-GB,de-DE,es-ES,fr-FR,it-IT like nl-NL
- Added config switch to choose between pico and Google TTS
- Fixed one more bug in GA. Saying "nevermind" just stopped the conversation without returning to listening mode

#### [1.1.2] - 2018-04-20

- Added timeout for screen
- Added screen section in config to specify timeout and screen on/off commands

#### [1.1.1] - 2018-04-19

- Changed handling of config.js so it is now backwards compatible
- fixed some more GA bugs. It should be stable and robust now and handle conversations correctly

#### [1.1.0] - 2018-04-17

- Changed handling of commands in config
- Changed format of models in config.js so an old one will not work (see: assets/config.txt)
- Added commands for screen on and off
- Added commands for showing/hiding a single named module
- Added mapping of spoken module name to actual module name (really helps non-english speakers)
- Added command to play .wav
- Added a single hotword can fire a list of commands and stay in listening mode
for example, a spoken "wake up" can turn on the screen (like PIR) without activating GA or voice command
- Added model specific confirmation sound added in config (parameter "confirm")
- Added translate/nl.json for dutch language


#### [1.0.3] - 2018-03-31

Expand Down
194 changes: 179 additions & 15 deletions MMM-Assistant.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ Module.register("MMM-Assistant",

start: function() {
console.log("[ASSTNT] started!")
this.modulemap = new Map(this.config.modulemap)
this.commands = []
// this.screentimer
this.status = "START"
this.config = this.configAssignment({}, this.defaults, this.config)
this.getCommands( new AssistantCommandRegister(this, this.registerCommand.bind(this)) )
Expand All @@ -99,6 +101,7 @@ Module.register("MMM-Assistant",
getTranslations: function() {
return {
en: "translations/en.json",
nl: "translations/nl.json",
fr: "translations/fr.json",
}
},
Expand Down Expand Up @@ -128,16 +131,31 @@ Module.register("MMM-Assistant",
description: this.translate("CMD_LIST_MODULES_DESCRIPTION"),
callback : 'cmd_asstnt_list_modules'
},
{
command: this.translate("CMD_HIDE_ALL_MODULES_EXCEPT"),
description : this.translate("CMD_HIDE_ALL_MODULES_EXCEPT_DESCRIPTION"),
callback : 'cmd_asstnt_hideall_except',
},
{
command: this.translate("CMD_HIDE_ALL_MODULES"),
description : this.translate("CMD_HIDE_ALL_MODULES_DESCRIPTION"),
callback : 'cmd_asstnt_hideall',
},
{
command: this.translate("CMD_HIDE_MODULE"),
description : this.translate("CMD_HIDE_MODULE_DESCRIPTION"),
callback : 'cmd_asstnt_hide_module',
},
{
command: this.translate("CMD_SHOW_ALL_MODULES"),
description : this.translate("CMD_SHOW_ALL_MODULES_DESCRIPTION"),
callback : 'cmd_asstnt_showall',
},
{
command: this.translate("CMD_SHOW_MODULE"),
description : this.translate("CMD_SHOW_MODULE_DESCRIPTION"),
callback : 'cmd_asstnt_show_module',
},
{
command: this.translate("CMD_SAY"),
description : this.translate("CMD_SAY_DESCRIPTION"),
Expand All @@ -153,6 +171,21 @@ Module.register("MMM-Assistant",
description : this.translate("CMD_REBOOT_DESCRIPTION"),
callback : 'cmd_asstnt_reboot',
},
{
command: this.translate("CMD_WAKE_UP"),
description : this.translate("CMD_WAKE_UP_DESCRIPTION"),
callback : 'cmd_asstnt_wakeup',
},
{
command: this.translate("CMD_STAY_AWAKE"),
description : this.translate("CMD_STAY_AWAKE_DESCRIPTION"),
callback : 'cmd_asstnt_stay_awake',
},
{
command: this.translate("CMD_GOTO_SLEEP"),
description : this.translate("CMD_GOTO_SLEEP_DESCRIPTION"),
callback : 'cmd_asstnt_gotosleep',
},
]
commands.forEach((c) => {
Register.add(c)
Expand All @@ -174,22 +207,117 @@ Module.register("MMM-Assistant",
this.sendSocketNotification('SHUTDOWN')
},

cmd_asstnt_wakeup : function (command, handler) {
if (typeof this.config.screen.on !== 'undefined') {
this.sendSocketNotification('EXECUTE', this.config.screen.on)
} else {
this.sendSocketNotification('EXECUTE', "vcgencmd display_power 1")
}
if (typeof this.config.screen.timeoff !== 'undefined') {
if (typeof this.config.screen.timeoff !== 0) {
clearTimeout(this.screenTimer)
this.screenTimer = setTimeout(() => {
if (typeof this.config.screen.off !== 'undefined') {
this.sendSocketNotification('EXECUTE', this.config.screen.off)
} else {
this.sendSocketNotification('EXECUTE', "vcgencmd display_power 0")
}
}, this.config.screen.timeoff * 1000)
}
}
if (this.status !== "COMMAND_MODE") this.sendSocketNotification("HOTWORD_STANDBY")
},

cmd_asstnt_stay_awake : function (command, handler) {
clearTimeout(this.screenTimer)
if (this.status !== "COMMAND_MODE") this.sendSocketNotification("HOTWORD_STANDBY")
},

cmd_asstnt_gotosleep : function (command, handler) {
if (typeof this.config.screen.off !== 'undefined') {
this.sendSocketNotification('EXECUTE', this.config.screen.off)
} else {
this.sendSocketNotification('EXECUTE', "vcgencmd display_power 0")
}
if (this.status !== "COMMAND_MODE") this.sendSocketNotification("HOTWORD_STANDBY")
},

cmd_asstnt_say : function (command, handler) {
this.sendSocketNotification('LOG', {title: "SAY", message: handler.args.something})
handler.response(handler.args.something)
},

cmd_asstnt_hideall : function (command, handler) {
var text = this.translate("CMD_HIDE_ALL_MODULES_RESULT")
var lockString = this.name
MM.getModules().enumerate( (m)=> { m.hide(0, {lockString:lockString}) })
handler.response(text)
if (this.status !== "COMMAND_MODE") {
this.sendSocketNotification("HOTWORD_STANDBY")
} else {
handler.response(text)
}
},

cmd_asstnt_hide_module : function (command, handler) {
var text = this.translate("CMD_HIDE_MODULE_RESULT")
var lockString = this.name
var target = handler.args['module']
var moduleSet = this.modulemap.get(target)
if (typeof moduleSet == 'undefined') moduleSet = target
MM.getModules().withClass(moduleSet).forEach( (m)=> {
m.hide(0, {lockString:lockString})
})
if (this.status !== "COMMAND_MODE") {
this.sendSocketNotification("HOTWORD_STANDBY")
} else {
handler.response(text)
}
},

cmd_asstnt_showall : function (command, handler) {
var text = this.translate("CMD_SHOW_ALL_MODULES_RESULT")
var lockString = this.name
MM.getModules().enumerate( (m)=> { m.show(0, {lockString:lockString}) })
handler.response(text)
if (this.status !== "COMMAND_MODE") {
this.sendSocketNotification("HOTWORD_STANDBY")
} else {
handler.response(text)
}
},

cmd_asstnt_show_module : function (command, handler) {
var text = this.translate("CMD_SHOW_MODULE_RESULT")
var lockString = this.name
var target = handler.args['module']
var moduleSet = this.modulemap.get(target)
if (typeof moduleSet == 'undefined') moduleSet = target
MM.getModules().withClass(moduleSet).forEach( (m)=> {
m.show(0, {lockString:lockString})
})
if (this.status !== "COMMAND_MODE") {
this.sendSocketNotification("HOTWORD_STANDBY")
} else {
handler.response(text)
}
},

cmd_asstnt_hideall_except : function (command, handler) {
var text = this.translate("CMD_HIDE_ALL_MODULES_EXCEPT_RESULT")
var lockString = this.name
var target = handler.args['module']
var moduleSet = this.modulemap.get(target)
if (typeof moduleSet == 'undefined') moduleSet = target
MM.getModules().exceptWithClass(moduleSet).forEach( (m)=> {
if (m.name != this.name) {m.hide(1000, {lockString:lockString})}
})
MM.getModules().withClass(moduleSet).forEach( (m)=> {
m.show(1000, {lockString:lockString})
})
if (this.status !== "COMMAND_MODE") {
this.sendSocketNotification("HOTWORD_STANDBY")
} else {
handler.response(text)
}
},

cmd_asstnt_list_commands : function (command, handler) {
Expand Down Expand Up @@ -404,16 +532,28 @@ Module.register("MMM-Assistant",
this.sendSocketNotification("HOTWORD_STANDBY")
}
break
case 'NOTIFY':
this.status = "COMMAND_MODE"
if (payload.notification == "COMMAND") {
this.parseCommand(payload.parameter, this.sendSocketNotification.bind(this))
} else if (payload.notification == "EXECUTE") {
this.sendSocketNotification("EXECUTE", payload.parameter)
} else {
this.sendNotification(payload.notification, payload.parameter)
}
break
case 'COMMAND':
this.status = "COMMAND";
console.log("[ASSTNT] Command:", payload)
this.parseCommand(payload, this.sendSocketNotification.bind(this))
//this.sendSocketNotification("HOTWORD_STANDBY")
break;
case 'ERROR':
this.status = "ERROR"
console.log("[ASSTNT] Error:", payload)
//this.sendSocketNotification("HOTWORD_STANDBY")
this.sendSocketNotification("HOTWORD_STANDBY")
break
case 'LOG':
// straight back to node helper
this.sendSocketNotification(notification, payload)
break
case 'MODE':
this.status = payload.mode
Expand Down Expand Up @@ -444,14 +584,36 @@ Module.register("MMM-Assistant",
},

hotwordDetected : function (type) {
if (type == 'ASSISTANT') {
this.sendSocketNotification('ACTIVATE_ASSISTANT')
this.status = 'ACTIVATE_ASSISTANT'
} else if (type == 'MIRROR') {
this.sendSocketNotification('ACTIVATE_COMMAND')
this.status = 'ACTIVATE_COMMAND'
// execute commands
if (typeof this.config.snowboy.models[type.index-1].commands !== 'undefined') {
this.config.snowboy.models[type.index-1].commands.forEach(
(command) => {
this.sendSocketNotification('LOG', {title: "[Command] ", message: command})
if (command.notification == 'ASSISTANT') {
this.sendSocketNotification('ACTIVATE_ASSISTANT')
this.status = 'ACTIVATE_ASSISTANT'
} else if (command.notification == 'MIRROR') {
this.status = 'ACTIVATE_COMMAND'
this.sendSocketNotification('ACTIVATE_COMMAND')
} else {
this.status = "COMMAND_MODE"
this.sendSocketNotification('NOTIFY', command)
}
}
)
} else if (typeof this.config.snowboy.models[type.index-1].hotwords !== 'undefined') {
if (this.config.snowboy.models[type.index-1].hotwords == 'ASSISTANT') {
this.sendSocketNotification('ACTIVATE_ASSISTANT')
this.status = 'ACTIVATE_ASSISTANT'
} else if (this.config.snowboy.models[type.index-1].hotwords == 'MIRROR') {
this.status = 'ACTIVATE_COMMAND'
this.sendSocketNotification('ACTIVATE_COMMAND')
}
}
// if last command was not a call for assistant or voice command then activate snowboy
if (this.status == "COMMAND_MODE") {
this.sendSocketNotification("NOTIFY", {notification: "HOTWORD_STANDBY"})
}

},

parseCommand: function(msg, cb) {
Expand All @@ -461,7 +623,7 @@ Module.register("MMM-Assistant",
cb("HOTWORD_STANDBY")
return
}
var msgText = msg
var msgText = msg.toLowerCase()
var commandFound = 0
var c
for(var i in this.commands) {
Expand Down Expand Up @@ -526,8 +688,10 @@ Module.register("MMM-Assistant",
},

response: function(text, originalCommand, option) {
this.sendSocketNotification('SPEAK', {text:text, option:option, originalCommand:originalCommand} )
this.status = 'SPEAK'
if (this.status !== "COMMAND_MODE") {
this.sendSocketNotification('SPEAK', {text:text, option:option, originalCommand:originalCommand} )
this.status = 'SPEAK'
}
},

loadCSS: function() {
Expand Down
Loading