Example #1
0
 def master_callback(self, hermes, intent_message):
     if intent_message.intent.intent_name == 'pezholio:energenie_all_on':
         for i in range(1, 4):
             lamp = Energenie(i)
             lamp.on()
             lamp.on()
     elif intent_message.intent.intent_name == 'pezholio:energenie_all_off':
         for i in range(1, 4):
             lamp = Energenie(i)
             lamp.off()
             lamp.off()
Example #2
0
class terrariumPowerSwitchEnergenieRF(terrariumPowerSwitchSource):
    TYPE = 'eg-pm-rf'

    def load_hardware(self):
        self.__device = Energenie(int(self.get_address()))

    def set_hardware_state(self, state, force=False):
        if state:
            self.__device.on()
        else:
            self.__device.off()

    def stop(self):
        self.__device.close()
Example #3
0
def reset_router():

    """
    Reset home router using energenie sockets and raspberry pi
    """

    # Define router as socket 2 - I have 2 sockets installed
    router = Energenie(2)
    
    # Turn off router
    router.off()
    print('Reset router, now wait 30 seconds before turning back on')
    # Wait to allow router to reset
    time.sleep(30)
    # Turn router back on
    router.on()
Example #4
0
def device_and_settings_loop():

    # Don't share db connection between threads.
    db = sqlite3.connect(dirname + 'vivarium_ctrl.db')
    c = db.cursor()

    # Initialise devices.
    heat_mat = Energenie(constants.HEAT_MAT_SOCKET)
    pump = Energenie(constants.PUMP_SOCKET)
    fan = Energenie(constants.FAN_SOCKET)
    light = Energenie(constants.LIGHT_SOCKET)

    logger.info('Device and settings thread started.')

    # Continue running until interrupted.
    while not running.is_set():

        #  Update device states.
        device_states = c.execute('SELECT * FROM device_states')
        for device_state in device_states:
            if device_state[0] == 'heat-mat':
                if to_bool(device_state[1]) != heat_mat.value:
                    heat_mat.value = to_bool(device_state[1])
            elif device_state[0] == 'pump':
                if to_bool(device_state[1]) != pump.value:
                    pump.value = to_bool(device_state[1])
            elif device_state[0] == 'fan':
                if to_bool(device_state[1]) != fan.value:
                    fan.value = to_bool(device_state[1])
            elif device_state[0] == 'light':
                if to_bool(device_state[1]) != light.value:
                    light.value = to_bool(device_state[1])

        # Check if settings need reloading.
        reload_settings = to_bool(
            c.execute("SELECT state FROM flags WHERE flag='reload_settings'").
            fetchone()[0])
        if reload_settings:
            load_settings()
            c.execute(
                "UPDATE flags SET state = 0 WHERE flag = 'reload_settings'")
            db.commit()

        # Pause briefly.
        running.wait(constants.DEVICE_AND_SETTINGS_INTERVAL)

    # Close db and switch off all devices.
    db.close()
    heat_mat.off()
    pump.off()
    fan.off()
    light.off()
    logger.info(
        'Device and settings thread stopped. All devices have been turned off.'
    )
Example #5
0
class EnergenieOutput(object):
    """
    Use energenie as an output for brumulus.
    """
    def __init__(self, socket):
        super(EnergenieOutput, self).__init__()
        self.socket = socket
        self.state = 'OFF'
        # set the pins numbering mode
        GPIO.setmode(GPIO.BCM)

        # Select the GPIO pins used for the encoder D0-D3 data inputs
        GPIO.setup(17, GPIO.OUT, initial=GPIO.LOW)
        GPIO.setup(22, GPIO.OUT, initial=GPIO.LOW)
        GPIO.setup(23, GPIO.OUT, initial=GPIO.LOW)
        GPIO.setup(27, GPIO.OUT, initial=GPIO.LOW)
        # Select GPIO used to select ASK/FSK (default ASK)
        GPIO.setup(24, GPIO.OUT, initial=GPIO.LOW)
        # Select GPIO used to enable/disable modulator (default disabled)
        GPIO.setup(25, GPIO.OUT, initial=GPIO.LOW)
        self.energenie = Energenie(socket)

    def is_state(self, state):
        if self.state == state:
            return True
        return False

    def set_state(self, state):
        if state == 'ON':
            self.energenie.on()
            self.state = 'ON'
            return 'ON'
        if state == 'OFF':
            self.energenie.off()
            self.state = 'OFF'
            return 'OFF'

        raise Exception('Cannot set EnergenieOutput state to {}'.format(state))

    def get_state(self):
        return self.state
Example #6
0
class EnergenieOutput(object):
    """
    Use energenie as an output for brumulus.
    """
    def __init__(self, socket):
        super(EnergenieOutput, self).__init__()
        self.socket = socket
        self.state = 'OFF'
        self.energenie = Energenie(socket)

    def is_state(self, state):
        if self.state == state:
            return True
        return False

    def set_state(self, state):
        if state == 'ON':
            self.energenie.on()
            return 'ON'
        if state == 'OFF':
            self.energenie.off()
            return 'OFF'

        raise Exception('Cannot set EnergenieOutput state to {}'.format(state))
class PlugDriver(Seizer):

	def __init__(self):
		interestedIdentifiers = ["LightsCommand"]
		super(PlugDriver,self).__init__()
		self.configureSeizer(interestedIdentifiers,True)
		self.livingRoomLights = Energenie(1)
		self.bedRoomLights = Energenie(2)

	def handleLightsCommand(self, header):
		if header == "allOn":
			self.allOn()
                elif header == "bedRoomOn": 
                        self.bedRoomLights.on() 
                elif header == "livingRoomOn":
                        self.livingRoomLights.on()
		elif header == "allOff":
			self.allOff()
		elif header == "bedRoomOff":
			self.bedRoomLights.off()
                elif header == "livingRoomOff": 
                        self.livingRoomLights.off()
		else:
			print "Unrecognised command: " + header + "."

	def allOff(self):
		self.livingRoomLights.off()
		self.bedRoomLights.off()

	def allOn(self):
		self.livingRoomLights.on()
		self.bedRoomLights.on()

	def run(self):
		while True:
			[header, payload] = self.seize()
			if header == "LightsCommand":
				self.handleLightsCommand(payload)
			else:
				print "Unrecognised header"
Example #8
0
def switch_off_boiler():
    from gpiozero import Energenie
    boiler_socket = Energenie(ENERGENIE_BOILER_SOCKET_NUMBER)
    boiler_socket.off()

    logging.debug("Boiler Off")
Example #9
0
class Room:
    """
        Convert gesture actions detected into responses, such as playing music and turning lights
        on. This class is hard-coded for the demo video. It will not work without modification as
        you probably don't have a machine called 'zero' with lock and unlock scripts, or the file
        audio/epic.mp3, which was used under licence.

        To explore your own neural network's behaviour, see run.py instead. Otherwise use this as
        a template to build your own gesture-driven automation.
    """
    def __init__(self):
        self.state = 'empty'
        self.ready = True
        system('ssh zero ./lock &')
        mixer.init()
        self.light = Energenie(1)

    def update(self, action):
        if action == NONE:
            self.ready = True

        if not self.ready:
            return

        if action != NONE:
            self.ready = False

        if action == DOOR:
            if self.state == 'empty':
                self.enter()
                self.state = 'occupied'
            elif self.state == 'occupied':
                self.leave()
                self.state = 'empty'
        elif action == LIGHT:
            self.toggle_light()
        elif action == MUSIC:
            self.play_music()
        elif action == STOP:
            self.dim_music()

    def enter(self):
        stderr.write('\nEnter\n')
        self.light.on()
        mixer.music.load('audio/good-evening.wav')
        mixer.music.set_volume(1.0)
        mixer.music.play()
        system('ssh zero ./unlock &')

    def toggle_light(self):
        if self.light.value:
            stderr.write('\nLight off\n')
            self.light.off()
        else:
            stderr.write('\nLight on\n')
            self.light.on()

    def play_music(self):
        stderr.write('\nMusic play\n')
        mixer.music.load('audio/epic.mp3')
        mixer.music.set_volume(0.5)
        mixer.music.play()

    def dim_music(self):
        stderr.write('\nDim music\n')
        mixer.music.set_volume(0.1)

    def leave(self):
        stderr.write('\nLeave\n')
        mixer.music.fadeout(1)
        mixer.music.load('audio/good-night.wav')
        mixer.music.set_volume(1.0)
        mixer.music.play()
        self.light.off()
        system('ssh zero ./lock &')
        sleep(5)
        mixer.music.load('audio/alarm-active.wav')
        mixer.music.play()
Example #10
0
    def off(self):                                                                                                                                       
	print(self.socket)
        print("Turn off " + self.where)                                                                                                                 
        lamp = Energenie(self.socket)
        lamp.off()
        return True  
Example #11
0
#!/usr/bin/python3
from gpiozero import Energenie
from time import sleep
heater = Energenie(1)
while True:
    heater.on()
    sleep(2)
    heater.off()
    sleep(4)
    
Example #12
0
    thingSpeakIoTKey = "8N9BL598BIFY4LV7"
    requests.post('https://api.thingspeak.com/update.json',
                  data={
                      'api_key': thingSpeakIoTKey,
                      'field1': temperature,
                      'field2': humidity
                  })

    if int(humidity
           ) < enableHumidifierMoistness_Procent and not humidifier.is_active:
        humidifier.on()
        print('Humidifier enabled!')

    if int(humidity
           ) > disableHumidifierMoistness_Procent and humidifier.is_active:
        humidifier.off()
        print('Humidifier disabled!')

    if temperature < enableHeaterTemperature_Celsius and not heater.is_active:
        heater.on()
        print('Heater enabled!')

    if temperature > disableHeaterTemperature_Celsius and heater.is_active:
        heater.off()
        print('Heater disabled!')

    sleep(10.0)

print("Execution terminated!")