Exemplo n.º 1
0
                payload = "ON"
            client.publish("home/room/lights/main-light/cmnd/POWER",
                           payload=payload)
        else:
            print(val)

    elif topic == "home/room/lights/main-light/STATE":
        if msg["POWER"].lower() == "on":
            lights = True
        elif msg["POWER"].lower() == "off":
            lights = False
        else:
            print(msg)
    elif topic == "home/room/lights/main-light/RESULT":
        if msg["POWER"].lower() == "off":
            lights = False
        elif msg["POWER"].lower() == "on":
            lights = True


#######################################
client = connect_mqtt("lights", on_message)

try:
    while True:
        time.sleep(poll_time)
except KeyboardInterrupt:
    pass
print("Stopping")
client.loop_stop()  # stop the loop
Exemplo n.º 2
0
        asyncio.run(wsocket(str(msg['value']), "T"))

    elif topic == "home/room/humidity":
        client.publish('home/log',
                       payload=json.dumps(dict(key='H', value=msg['value'])))
        asyncio.run(wsocket(str(msg['value']), "H"))

    elif topic == "home/room/microview/poll":
        print("Polling to microview..")
        client.publish("home/room/433Gateway/commands/MQTTto433",
                       '{"value": 10000001}')
        time.sleep(0.5)


#######################################
client = connect_mqtt("micro", on_message)

try:
    while True:
        print('Polling...')
        wait_msg = True
        client.publish("home/room/microview/poll", 'poll')
        time.sleep(ack_time)
        if wait_msg == True:
            client.publish("home/room/microview/status", "off")
        else:
            client.publish("home/room/microview/status", "on")

        time.sleep(poll_time)
except KeyboardInterrupt:
    pass
Exemplo n.º 3
0
import os


def on_message(client, userdata, message):
    msg = str(message.payload.decode("utf-8"))

    try:
        msg = json.loads(msg)
    except:
        pass
    topic = message.topic

    if topic == 'home/log':
        print("logging")
        row = (datetime.datetime.now(), msg['key'], msg['value'])
        with open(os.getenv("LOGFILE"), 'a') as f:
            writer = csv.writer(f, delimiter=',')
            writer.writerow(row)


#######################################
client = connect_mqtt("log", on_message)

try:
    while True:
        time.sleep(10)
except KeyboardInterrupt:
    pass
print("Stopping")
client.loop_stop()  # stop the loop
Exemplo n.º 4
0
        client.publish('home/log',
                       payload=json.dumps(dict(key='HO', value=msg['value'])))
        asyncio.run(wsocket(str(msg['value']), "HO"))

    elif topic == "home/room/nano/bat":
        client.publish('home/log',
                       payload=json.dumps(dict(key='NB', value=msg['value'])))
        asyncio.run(wsocket(str(msg['value']), "NB"))

    elif topic == "home/room/nano/poll":
        print("Polling to nano..")
        client.publish("home/room/433Gateway/commands/MQTTto433",
                       '{"value": 10000002}')
        time.sleep(0.5)
    elif topic == "home/room/nano/poll2":
        client.publish("home/room/433Gateway/commands/MQTTto433",
                       '{"value": 10000003}')
        time.sleep(0.5)


#######################################
client = connect_mqtt("nano", on_message)

try:
    while True:
        time.sleep(poll_time)
except KeyboardInterrupt:
    pass
print("Stopping")
client.loop_stop()  # stop the loop
Exemplo n.º 5
0
                HVAC.send_command(
                      climate_mode=ClimateMode.Cold,
                      temperature=msg['temp'],
                      fan_mode=FanMode.Auto,
                      vanne_vertical_mode=VanneVerticalMode.Auto,
                      vanne_horizontal_mode=VanneHorizontalMode.NotSet,
                      isee_mode=ISeeMode.ISeeOn,
                      area_mode=AreaMode.Full,
                      end_time=datetime.datetime(2020,1,1,1,0,0),
                      powerful=PowerfulMode.PowerfulOn
                    )
            except Exception as e:
                print(repr(e))

        elif msg['temp']:
            print('solo temp')

#######################################
client = connect_mqtt("hvac", on_message)

gpio = 23
HVAC=Mitsubishi(gpio, LogLevel.ErrorsOnly)
print('HVAC Defined on GPIO ', gpio)
try:
    while True:
        time.sleep(poll_time)
except KeyboardInterrupt:
    pass
print("Stopping")
client.loop_stop()  # stop the loop