Moderators: Admin_N, Administrator, Admin_P, Admin_K
switch:
- platform: command_line
switches:
inside_camera_record:
command_on: 'curl -k "http://xxx.xxx.xxx.xxx:10090/record_trigger_on?module=HttpSwitcher.8"'
command_off: 'curl -k "http://xxx.xxx.xxx.xxx:10090/record_trigger_off?module=HttpSwitcher.8"'
command_state: 'curl -k "http://xxx.xxx.xxx.xxx:10090/record_trigger_off?module=HttpSwitcher.8&show_status=true"'
value_template: '{{ "On" in value }}'
skylord123 Wrote:SMTP to trigger your lights.. Oh man. You can definitely easily improve that response time by switching to another method.
import jfxplbase
import jfxplutil
import collections
import smtpd
import asyncore
import time
import smtplib
class CustomSMTPServer(smtpd.SMTPServer):
armed = {};
def process_message(self, peer, mailfrom, rcpttos, data):
try:
isArmed = self.armed[mailfrom]
except:
self.armed[mailfrom] = True
self.iface.send(mailfrom, self.armed[mailfrom], "on")
if self.armed[mailfrom]:
smtp = smtplib.SMTP("172.23.41.10", 25)
smtp.sendmail(mailfrom, rcpttos, data)
def setArmed(self, arm):
self.armed = arm;
def setiface(self, iface):
self.iface = iface
class jfipcam(jfxplbase.jfxplBase):
def __init__(self, sendQueue, id, host, listen, mode, params):
self.mode = mode
self.params = params
self.yearday = -1
self.isdark = True
self.time = time.localtime()
self.inf = collections.OrderedDict()
self.inf["hop"] = "1"
self.inf["source"] = "jf-jfxpl." + id
self.inf["target"] = "*"
super(jfipcam, self).__init__(sendQueue,id, host, listen)
def send(self, address, armed, cmd):
command = "xpl-trig"
schema = "sensor.basic"
data = collections.OrderedDict()
data["device"] = address
data["armed"]= str(armed)
data["command"] = cmd
xpl = jfxplutil.makexpl(command, self.inf, schema, data)
self.sendQueue.put(xpl)
def processMessage(self, command, inf, schema, data):
if super(jfipcam, self).processMessage(command, inf, schema, data):
return True
try:
address = data["address"]
#print data
if data["arm"] == "on":
self.smtpserver.armed[address] = True
else:
self.smtpserver.armed[address] = False
return True
except Exception as e:
print e
return True
def dostart(self):
self.smtpserver = CustomSMTPServer(('172.23.41.52', 1025), None)
self.smtpserver.setiface(self)
super(jfipcam, self).dostart()
return True
Return to Xeoma - General discussion
Users browsing this forum: Bing [Bot], Google [Bot] and 14 guests