diff --git a/scripts/alexa_temperature.py b/scripts/alexa_temperature.py new file mode 100644 index 0000000000000000000000000000000000000000..6de30e97a7cd113a18636f944466215a00374a79 --- /dev/null +++ b/scripts/alexa_temperature.py @@ -0,0 +1,69 @@ +from xaal.lib import Engine,tools +from xaal.schemas import devices +from xaal.monitor import Monitor + +import platform +UUID = tools.get_uuid + +ADDR = UUID('aa16f008-5db4-11ec-a53d-d6bd5fe18736') + +ALEXA = UUID('c968a442-1d59-11ec-90a5-d6bd5fe18701') +GARAGE = UUID('0cbcf21c-92b0-11e8-80cd-408d5c18c800') +OUTDOOR = UUID( '5fcc6ad1-804d-49cb-b66c-e877f2374900') +INDOOR = UUID('43c4a724-055f-11e9-8716-82ed25e6aa00') + +TEMP = [GARAGE,OUTDOOR,INDOOR] + +def filter(msg): + if msg.source in TEMP: + return True + return False + +def get_temp(mon,addr): + dev = mon.devices.get_with_addr(addr) + if dev: + value = dev.attributes.get('temperature',None) + if value: + return value + return None + + +def main(): + engine = Engine() + engine.start() + + dev = devices.scenario(ADDR) + dev.vendor_id = 'IHSEV' + dev.product_id = 'Simple scenario to test Alexa' + dev.info = 'Alexa temperature scene@%s' % (platform.node()) + dev.attributes['enabled'] = True + + engine.add_device(dev) + mon = Monitor(dev,filter_func=filter) + + def run(): + txt = '' + + tmp = get_temp(mon,OUTDOOR) + if tmp: + txt += 'la température extérieure est de %s°, ' % tmp + + tmp = get_temp(mon,GARAGE) + if tmp: + txt += 'la Température du garage est de %s°, ' % tmp + + tmp = get_temp(mon,INDOOR) + if tmp: + txt += 'La température du salon est de %s°.' % tmp + + engine.send_request(dev,[ALEXA],'say',{'msg':txt}) + + + dev.methods['run'] = run + engine.run() + +if __name__ == '__main__': + try: + main() + except KeyboardInterrupt: + print("\nBye!") \ No newline at end of file