|
@@ -4,6 +4,9 @@ import os
|
|
|
|
|
|
|
|
import logging
|
|
import logging
|
|
|
from timeit import default_timer
|
|
from timeit import default_timer
|
|
|
|
|
+from random import choice
|
|
|
|
|
+import time
|
|
|
|
|
+
|
|
|
import requests
|
|
import requests
|
|
|
|
|
|
|
|
from ameise import app, ask, log
|
|
from ameise import app, ask, log
|
|
@@ -23,6 +26,15 @@ ROOM2POWER_DOMO_IDX = {
|
|
|
'wohnzimmer': 2840,
|
|
'wohnzimmer': 2840,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+class RoomState(object):
|
|
|
|
|
+ def __init__(self):
|
|
|
|
|
+ self.last_switches = {}
|
|
|
|
|
+ for room in ROOM2POWER_DOMO_IDX:
|
|
|
|
|
+ self.last_switches[room] = time.time()
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+STATE = RoomState()
|
|
|
|
|
+
|
|
|
# map alexa slot to domoticz switch value
|
|
# map alexa slot to domoticz switch value
|
|
|
ON_OFF_SLOT = {'an': 'On', 'aus': 'Off'}
|
|
ON_OFF_SLOT = {'an': 'On', 'aus': 'Off'}
|
|
|
|
|
|
|
@@ -61,4 +73,14 @@ def toggle_switch(OnOff):
|
|
|
log.info('domoticz: device %s switch: %s' % (domo_idx, switchcmd))
|
|
log.info('domoticz: device %s switch: %s' % (domo_idx, switchcmd))
|
|
|
|
|
|
|
|
domo_command(param='switchlight', idx=domo_idx, switchcmd=switchcmd)
|
|
domo_command(param='switchlight', idx=domo_idx, switchcmd=switchcmd)
|
|
|
- return statement('Ich habe das Licht im %s %sgeschaltet.' % (room, OnOff))
|
|
|
|
|
|
|
+
|
|
|
|
|
+ delta_last = time.time() - STATE.last_switches[room]
|
|
|
|
|
+ STATE.last_switches[room] = time.time()
|
|
|
|
|
+
|
|
|
|
|
+ if delta_last < 30:
|
|
|
|
|
+ return statement('')
|
|
|
|
|
+ else:
|
|
|
|
|
+ if choice(range(10)) == 0:
|
|
|
|
|
+ return statement('Ich habe das Licht im %s %sgeschaltet.' % (room, OnOff))
|
|
|
|
|
+ else:
|
|
|
|
|
+ return statement('OK')
|