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()
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()
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()
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
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"
def switch_on_pump(): from gpiozero import Energenie pump_socket = Energenie(ENERGENIE_PUMP_SOCKET_NUMBER) pump_socket.on() logging.debug("Pump On")
def switch_on_boiler(): from gpiozero import Energenie boiler_socket = Energenie(ENERGENIE_BOILER_SOCKET_NUMBER) boiler_socket.on() logging.debug("Boiler On")
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()
def on(self): print(self.socket) print("Turn on " + self.where) lamp = Energenie(self.socket) lamp.on() return True
#!/usr/bin/python3 from gpiozero import Energenie from time import sleep heater = Energenie(1) while True: heater.on() sleep(2) heater.off() sleep(4)
while True: lastReadOn = getHumidityAndTemperature() humidity = lastReadOn[0] temperature = lastReadOn[1] 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!')