def __init__(self): self.load_config() if (self.mqtt_user is not None and self.mqtt_pass is not None and self.mqtt_pass is not None): mqtt_opts = MqttOptions(username=self.mqtt_user, password=self.mqtt_pass, broker_address=self.mqtt_host) else: mqtt_opts = MqttOptions(broker_address=self.mqtt_host) with Hermes(mqtt_options=mqtt_opts) as h: h.subscribe_intents(self.intent_received).start()
def start_blocking(self): mqtt_addr = "{}:{}".format(self.config["global"]["mqtt_ip_addr"], self.config["global"]["mqtt_port"]) mqtt_opts = MqttOptions(username=self.config["secret"]["mqtt_user"], password=self.config["secret"]["mqtt_pw"], broker_address=mqtt_addr) with Hermes(mqtt_options=mqtt_opts) as h: h.subscribe_intents(self.master_intent_callback).start()
def recordatorioTomar(e, intentMessage, Snips): if (Snips.EventoActivo(e)): if (e.usuario == Snips.usuario): with Hermes(mqtt_options=MqttOptions()) as clienteMQTT: if (e.veces < 6): Snips.log(e, Snips.usuario, '', 'Recordatorio', '') clienteMQTT.publish_start_session_action( site_id=intentMessage, session_init_text=e.usuario + '¿ te has tomado ' + e.med + '?', session_init_intent_filter=[ "caguilary:Confirmar", "caguilary:Negar" ], session_init_can_be_enqueued=True, session_init_send_intent_not_recognized=True, custom_data=None) mensaje = "" print(e.usuario + '¿te has tomado ' + e.med + '?:Vez ' + str(e.veces)) Snips.Incrementar(e) e.IncrementarVeces() clienteMQTT.publish_end_session(intentMessage, mensaje) else: mensaje = e.usuario + ' ha ignorado el evento tomar ' + e.med say(intentMessage, mensaje) if (not e.rep): Snips.EventoFinalizado(e) else: Snips.NingunaVez(e) if (e.rep): Snips.planificador1.remove_job( 'Evento repetitivo: recordando tomar ' + e.med + ' a ' + e.usuario + ' cada ' + e.cuando) else: Snips.planificador1.remove_job( 'Evento no repetitivo: recordando tomar ' + e.med + ' a ' + e.usuario) clienteMQTT.publish_end_session(intentMessage, mensaje) else: print("Usuario actual distinto al del evento") if (e.rep): Snips.planificador1.remove_job( 'Evento repetitivo: recordando tomar ' + e.med + ' a ' + e.usuario + ' cada ' + e.cuando) else: Snips.planificador1.remove_job( 'Evento no repetitivo: recordando tomar ' + e.med + ' a ' + e.usuario) else: print("El evento ya ha sido confirmado") if (e.rep): Snips.planificador1.remove_job( 'Evento repetitivo: recordando tomar ' + e.med + ' a ' + e.usuario + ' cada ' + e.cuando) else: Snips.planificador1.remove_job( 'Evento no repetitivo: recordando tomar ' + e.med + ' a ' + e.usuario)
def main(): mqtt_opts = MqttOptions(username=MQTT_USERNAME, password=MQTT_PASSWORD, broker_address=MQTT_BROKER_ADDRESS) global station station = NetatmoWeatherStation(config) logger.debug('Start listening on {}'.format(MQTT_BROKER_ADDRESS)) with Hermes(mqtt_options=mqtt_opts) as h: h.subscribe_intent("JasperJuergensen:OutdoorWeather", weatherOutdoor).loop_forever()
def action_wrapper(hermes, intentMessage, conf): if len(intentMessage.slots.call) > 0 and len(intentMessage.slots.person) > 0: person = intentMessage.slots.person.first().value # We extract the value from the slot "person" result_sentence = "Do you want to make a call to : {}".format(str(person)) # The response that will be said out loud by the TTS engine. elif len(intentMessage.slots.call) > 0 and len(intentMessage.slots.number) > 0: number = intentMessage.slots.number.first().value # We extract the value from the slot "number" result_sentence = "Dialing the number : {}".format(str(number)) # The response that will be said out loud by the TTS engine. else: result_sentence = "I did not understand that! Could you please repeat?" current_session_id = intentMessage.session_id hermes.publish_end_session(current_session_id, result_sentence) if __name__ == "__main__": mqtt_opts = MqttOptions() with Hermes(mqtt_options=mqtt_opts) as h: h.subscribe_intent("Aniket_J:MakeCalls", subscribe_intent_callback) \ .start()
def read_configuration_file(configuration_file): try: with io.open(configuration_file, encoding=CONFIGURATION_ENCODING_FORMAT) as f: conf_parser = SnipsConfigParser() conf_parser.readfp(f) return conf_parser.to_dict() except (IOError, ConfigParser.Error) as e: return dict() def subscribe_intent_callback(hermes, intentMessage): conf = read_configuration_file(CONFIG_INI) hermes.publish_end_session(intentMessage.session_id, weather.forecast_temperature(intentMessage)) if __name__ == "__main__": conf = read_configuration_file(CONFIG_INI) weather = Weather(conf) mqtt_addr = "{}:{}".format(conf['global']['mqtt_ip_addr'], conf['global']['mqtt_port']) mqtt_opts = MqttOptions(username=conf['secret']['mqtt_user'], password=conf['secret']['mqtt_pw'], broker_address=mqtt_addr) with Hermes(mqtt_options=mqtt_opts) as h: h.subscribe_intent("domi:searchWeatherForecastTemperature", subscribe_intent_callback).start()
"Oui. ", "En effet, ", "Effectivement, ", ] oui = random.choice(non_array) for w in weather['list'][selected_forecast]['weather']: answer += CONDITION_CODES[w['id']]['snips'][0] + et if condition_name is not None and condition_name in CONDITION_CODES[ w['id']]['snips']: oui = random.choice(oui_array) if len(et) > 0: answer = answer[:-len(et)] answer += " " answer = oui + answer if locality != conf['secret']['default_location']: answer += "à %s" % locality hermes.publish_end_session(intentMessage.session_id, answer) if __name__ == "__main__": f = open("/etc/snips.toml", "rt") config = toml.load(f) mqtt_opts = MqttOptions(username=config["snips-common"]["mqtt_username"], password=config["snips-common"]["mqtt_password"], broker_address=config["snips-common"]["mqtt"]) with Hermes(mqtt_options=mqtt_opts) as h: h.subscribe_intent("searchWeatherForecastCondition", subscribe_intent_callback) \ .start()
def get_mqtt_options(): return MqttOptions(username = get_user(), password = get_pass(), broker_address = get_addr_port())
#!/usr/bin/env python3 # -*- coding: utf-8 -*- import configparser from hermes_python.hermes import Hermes from hermes_python.ffi.utils import MqttOptions from hermes_python.ontology import * import io import os mqtt_opts = MqttOptions(username="******", password="******", broker_address="my-mqtt-broker.com:18852") CONFIGURATION_ENCODING_FORMAT = "utf-8" CONFIG_INI = "config.ini" MQTT_IP_ADDR = "localhost" MQTT_PORT = 1883 MQTT_ADDR = "{}:{}".format(MQTT_IP_ADDR, str(MQTT_PORT)) DIR = os.path.dirname(os.path.realpath(__file__)) + '/alarm/' lang = "EN" class SnipsConfigParser(configparser.SafeConfigParser): def to_dict(self): return { section: { option_name: option for option_name, option in self.items(section)
def test_initialization_with_options(): mqtt_opts = MqttOptions() h = Hermes(mqtt_options=mqtt_opts) assert h.mqtt_options.broker_address == "localhost:1883"
def say(MensajeIntent, texto): with Hermes(mqtt_options=MqttOptions()) as clienteMQTT: clienteMQTT.publish_start_session_notification(MensajeIntent, texto, None)
def __init__(self): with Hermes(mqtt_options=MqttOptions()) as h: threading.Thread.__init__(self)
'Evento no repetitivo: recordando tomar ' + e.med + ' a ' + e.usuario) else: print("El evento ya ha sido confirmado") if (e.rep): Snips.planificador1.remove_job( 'Evento repetitivo: recordando tomar ' + e.med + ' a ' + e.usuario + ' cada ' + e.cuando) else: Snips.planificador1.remove_job( 'Evento no repetitivo: recordando tomar ' + e.med + ' a ' + e.usuario) if __name__ == '__main__': opciones_MQTT = MqttOptions() global_variables() HiloBoton = boton() HiloBoton.start() with Hermes(mqtt_options=opciones_MQTT) as h: h\ .subscribe_intent("caguilary:Anadir_Evento", subscribir_Anadir_llamada) \ .subscribe_intent("caguilary:Cambiar_Usuario", subscribir_Cambiar_usuario_llamada) \ .subscribe_intent("caguilary:Confirmar", subscribir_Confirmar_llamada) \ .subscribe_intent("caguilary:Negar", subscribir_Negar_llamada) \ .subscribe_intent("caguilary:Anadir_usuario", subscribir_Anadir_usuario_llamada) \ .subscribe_intent("caguilary:usuario_Activo", subscribir_Comprobar_usuario_llamada) \ .subscribe_intent("caguilary:Borrar_Evento", subscribir_Borrar_llamada) \ .start()
logging.info(f"Opening session {session_id}") logging.info(f"Intent {intent_name}") resp = requests.get("https://api.icndb.com/jokes/random") if resp.status_code != 200: logging.error( f"{session_id} Invalid response from API (Code: {resp.status_code})" ) result_sentence = "Désolé, je n'ai plus rien en stock" else: print(resp.json()["value"]["joke"]) result_sentence = "Noemy tu pues des fesses" # resp.json()["value"]["joke"] logging.info(f"Ending session {session_id}") requests.post( "http://192.168.1.21:12101/api/text-to-speech", data=result_sentence, ) hermes.publish_end_session(session_id, result_sentence) if __name__ == "__main__": mqtt_opts = MqttOptions(broker_address="192.168.1.21:1883") with Hermes(mqtt_options=mqtt_opts) as h: h.subscribe_intent(INTENT_JOKE, subscribe_intent_callback) logging.info("Subscribed") h.loop_start() h.loop_forever()
return if timer_id > len(TIMER_LIST) - 1: hermes.publish_end_session( intentMessage.session_id, 'Der angegebene Teimer existiert nicht.') return removed_timer = TIMER_LIST.pop(timer_id) removed_timer.event.set() text = 'Der Teimer {} wurde gestoppt.'.format(timer_id + 1) elif len(TIMER_LIST) == 1: removed_timer = TIMER_LIST.pop(0) removed_timer.event.set() text = 'Der Teimer wurde gestoppt.' else: #hermes.publish_continue_session(intentMessage.session_id, 'Welchen Teimer möchtests du beenden?') #return text = 'Ich weiß leider nicht, welchen Teimer ich beenden soll.' hermes.publish_end_session(intentMessage.session_id, text) if __name__ == "__main__": mqtt_opts = MqttOptions(username=MQTT_USERNAME, password=MQTT_PASSWORD, broker_address=MQTT_BROKER_ADDRESS) with Hermes(mqtt_options=mqtt_opts) as h: h.subscribe_intent("JasperJuergensen:StartTimer", simpleTimer)\ .subscribe_intent("JasperJuergensen:StopTimer", timerRemove)\ .subscribe_intent('JasperJuergensen:TimerInfo', getTimerInfo).loop_forever()
process.communicate() process.stdin.close() process.wait() call(startSnipsAudio, shell=True) else: hermes.publish_end_session(intentMessage.session_id, "Can't understand this person") song = AudioSegment.from_wav("endcall.wav") play(song) print('finished execution') if __name__ == "__main__": mqtt_opts = MqttOptions() snips_opts = toml.load('/etc/snips.toml') if 'mqtt' in snips_opts['snips-common']: mqtt_opts.broker_address = snips_opts['snips-common']['mqtt'] if 'mqtt_username' in snips_opts['snips-common']: mqtt_opts.username = snips_opts['snips-common']['mqtt_username'] if 'mqtt_password' in snips_opts['snips-common']: mqtt_opts.password = snips_opts['snips-common']['mqtt_password'] if 'mqtt_tls_hostname' in snips_opts['snips-common']: mqtt_opts.tls_hostname = snips_opts['snips-common'][ 'mqtt_tls_hostname'] if 'mqtt_tls_disable_root_store' in snips_opts['snips-common']: mqtt_opts.tls_disable_root_store = snips_opts['snips-common'][ 'mqtt_tls_disable_root_store'] if 'mqtt_tls_cafile' in snips_opts['snips-common']: mqtt_opts.tls_ca_file = snips_opts['snips-common']['mqtt_tls_cafile']
message_to_tts = '' for magazine_nr in range(0, len(stock_info)): if stock_info[magazine_nr] in [25, 50, 75]: #magazines that are neither completely empty nor completely full message_to_tts += single_message_stock.format( dic_weekdays[magazine_nr], stock_info[magazine_nr]) elif stock_info[magazine_nr] == 100: #magazines that are completely empty message_to_tts += single_message_empty.format( dic_weekdays[magazine_nr]) else: #magazines that are completely full info_message += dic_weekdays[magazine_nr] + ', ' message_to_tts = info_message[:-2] + '. ' + message_to_tts # terminate the session by sending message to tts log_tts_output(message_to_tts) hermes.publish_end_session(intent_message.session_id, message_to_tts) if __name__ == "__main__": mqtt_opts = MqttOptions() with Hermes(mqtt_options=mqtt_opts) as h: #subscribe to the intent "infoRefilling" of the PillDispenser app h.subscribe_intent("carlasailer:infoRefilling", start_infoRefilling).start()
def get_hermes_mqtt_options(): return MqttOptions(username=mqtt_client.get_user(), password=mqtt_client.get_pass(), broker_address=mqtt_client.get_addr_port())