From 312fbafec81a871bac6020259e171a4dcbd40cb7 Mon Sep 17 00:00:00 2001
From: jkerdreu <jkerdreu@b32b6428-25c9-4566-ad07-03861ab6144f>
Date: Wed, 15 Dec 2021 15:57:08 +0000
Subject: [PATCH] Sample example howto to use Alexa TTS to tell sensors state
 (here indoor/outdoor temperature)

git-svn-id: https://redmine.imt-atlantique.fr/svn/xaal/code/Python/branches/0.7@2779 b32b6428-25c9-4566-ad07-03861ab6144f
---
 scripts/alexa_temperature.py | 69 ++++++++++++++++++++++++++++++++++++
 1 file changed, 69 insertions(+)
 create mode 100644 scripts/alexa_temperature.py

diff --git a/scripts/alexa_temperature.py b/scripts/alexa_temperature.py
new file mode 100644
index 00000000..6de30e97
--- /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
-- 
GitLab