def on_message(self, client: mqtt.Client, userdata, message: mqtt.MQTTMessage): # Check if this is a message that sets the light in a specific config if message.topic == self.set_topic: # Load the JSON state message_json = json.loads(message.payload) self.set_state(message_json) # Echo it back response = json.dumps(message_json) self.client.publish(self.state_topic, response, qos=1, retain=True) elif message.topic == self.scheduler_topic: payload = message.payload.decode("utf-8") if payload == "ON": self.device.on() elif payload == "OFF": self.device.off() elif payload == "BRI": self.device.brightness = 100 elif payload == "TEMP": self.device.temperature = 3700 elif payload == "COL": self.device.color = (19, 2, 150) else: # Pass it down SIISThing.on_message(self, client, userdata, message) return
def on_message(self, client: mqtt.Client, userdata, message: mqtt.MQTTMessage): if message.topic == self.scheduler_topic: payload = message.payload.decode("utf-8") self.auto_update = False self.fixed_state = payload else: SIISThing.on_message(self, client, userdata, message)
def on_message(self, client: mqtt.Client, userdata, message: mqtt.MQTTMessage): if message.topic == self.scheduler_topic: print( f"Received an unexpected message from the scheduler: {message.payload.decode()}" ) else: # Pass it down SIISThing.on_message(self, client, userdata, message)
def on_message(self, client: mqtt.Client, userdata, message: mqtt.MQTTMessage): if message.topic == self.scheduler_topic: # The barometer should not receive anything from the scheduler logging.error( f"Reveiced an unexpected message from the scheduler: {message.payload.decode()}" ) else: # Pass it down SIISThing.on_message(self, client, userdata, message)
def on_message(self, client: mqtt.Client, userdata, message: mqtt.MQTTMessage): if message.topic == self.scheduler_topic: # Stop the timer to prevent automatic changes self.auto_update = False payload: str = message.payload.decode() if payload == "ON": self.state.notify_of_external_update(True) elif payload == "OFF": self.state.notify_of_external_update(False) else: # Pass it down SIISThing.on_message(self, client, userdata, message)
def on_message(self, client: mqtt.Client, userdata, message: mqtt.MQTTMessage): if message.topic == self.scheduler_topic: state = message.payload.decode("utf-8") print(f"Setting new state to {state}") self.last_state = state self.client.publish(self.state_topic, payload=state, qos=1, retain=True) else: # Pass it down SIISThing.on_message(self, client, userdata, message)
def on_message(self, client: mqtt.Client, userdata, message: mqtt.MQTTMessage): if message.topic == self.scheduler_topic: # Stop the timer to prevent automatic changes payload: str = message.payload.decode() if payload == "ON": self.perform_action("lock") # self.state.notify_of_external_update("locked") elif payload == "OFF": self.perform_action("unlock") # self.state.notify_of_external_update("unlocked") else: # Pass it down SIISThing.on_message(self, client, userdata, message)
def on_message(self, client: mqtt.Client, userdata, message: mqtt.MQTTMessage): if message.topic == self.scheduler_topic: payload: str = message.payload.decode() self.auto_update = False if payload == "ON": self.state.notify_of_external_update(True) self.add_event(AlarmEvent(self)) elif payload == "OFF": self.state.notify_of_external_update(False) else: logging.error(f"Received unexpected message: {payload}") else: # Pass it down SIISThing.on_message(self, client, userdata, message)
def on_message(self, client: mqtt.Client, userdata, message: mqtt.MQTTMessage): # Check if this is a message that sets the lock if message.topic == self.set_topic or message.topic == self.scheduler_topic: # Read the target state lock: str = message.payload.decode("utf-8") print("Setting the lock to %s" % lock) self.last_state = lock # Echo it back response = lock client.publish(self.state_topic, response, qos=1, retain=True) else: # Pass the message down SIISThing.on_message(self, client, userdata, message)
def on_message(self, client: mqtt.Client, userdata, message: mqtt.MQTTMessage): if message.topic == self.scheduler_topic: new_state = message.payload.decode("utf-8") _ = self.device.value logging.debug(f"Setting state to {new_state}") if new_state == "ON": self.state.notify_of_external_update(True) elif new_state == "OFF": self.state.notify_of_external_update(False) else: logging.error(f"Invalid state received: {new_state}") else: # Pass it down SIISThing.on_message(self, client, userdata, message)
def on_message(self, client: mqtt.Client, userdata, message: mqtt.MQTTMessage): "MQTT callback for when the client receives a message" # Check if this is a message that sets the light in a specific config if message.topic == self.target_temperature_set: # Read the target temp target_temp: float = float(message.payload) print("Setting the target temp at %0.1f" % target_temp) self.last_target = target_temp # Echo it back response = str(target_temp) self.client.publish(self.target_temperature_state, response, qos=1, retain=True) elif message.topic == self.mode_set_topic: # Read the fan setting mode_setting: str = message.payload.decode("utf-8") print("Setting mode to %s" % mode_setting) self.last_mode = mode_setting # Echo it back response = mode_setting self.client.publish(self.mode_state_topic, response, qos=1, retain=True) elif message.topic == self.scheduler_topic: # Detemine if it is a temp or mode update payload = message.payload.decode("utf-8") try: # Read the new outside temp temp: float = float(payload) print(f"Setting outside temp to {temp}C") self.outside_temp = temp except ValueError: # Set the new mode, disable auto_update self.auto_update = False state: str = payload if state == "OFF": self.set_action("off") elif state == "HEAT": self.set_action("heating") elif state == "COOL": self.set_action("cooling") else: # Pass the message down SIISThing.on_message(self, client, userdata, message)
def on_message(self, client: mqtt.Client, userdata, message: mqtt.MQTTMessage): if message.topic == self.scheduler_topic: payload: str = message.payload.decode() if payload == "ON": self.on_state.notify_of_external_update(True) elif payload == "OFF": self.on_state.notify_of_external_update(False) elif payload == "BRI": self.brightness_state.notify_of_external_update(100) elif payload == "TEMP": self.temperature_state.notify_of_external_update(3400) elif payload == "COL": self.color_state.notify_of_external_update("#130296") else: # Pass it down SIISThing.on_message(self, client, userdata, message)
def on_message(self, client: mqtt.Client, userdata, message: mqtt.MQTTMessage): "MQTT callback for when the client receives a message" if message.topic == self.scheduler_topic: payload = message.payload.decode("utf-8") try: new_outside_temp = float(payload) logging.debug( f"Setting outside temperature to {new_outside_temp}C") self.outside_temp = new_outside_temp except ValueError: state = payload self.auto_update = False if state == "OFF": self.state.notify_of_external_update("off") elif state == "HEAT": self.state.notify_of_external_update("heating") elif state == "COOL": self.state.notify_of_external_update("cooling") else: # Pass it down SIISThing.on_message(self, client, userdata, message)
def on_message(self, client: mqtt.Client, userdata, message: mqtt.MQTTMessage): # Check if this is a message that sets the TV if message.topic == self.set_topic: # Read the target temp tv_state: str = message.payload.decode("utf-8") print("Setting the TV to %s" % tv_state) self.set_state(tv_state) # Echo it back response = tv_state self.client.publish(self.state_topic, response, qos=1, retain=True) elif message.topic == self.scheduler_topic: tv_state = message.payload.decode("utf-8") print( f"Received message from Scheduler, setting new state to {tv_state}" ) self.set_state(tv_state) # Publish the state to Hass response = tv_state self.client.publish(self.state_topic, response, qos=1, retain=True) else: # Pass it down SIISThing.on_message(self, client, userdata, message)