Webapp

Config Setup example

Turn on/off zwave device though the webapp

class Config(ConfigObject):

    def config(self):
        config = {}

        # Zwave
        config["zwave"] = {}
        config["zwave"]["device"] = "/dev/serial/by-id/usb_id_zwave_controller"

        # WebApp
        config["webapp"] = {}
        config["webapp"]["servers"] = ["zwave"]
        config["webapp"]["admin"] = {"email": "youremail@email.com", "name": "UserName"}
        config["webapp"]["tokens"] = {"YourToken": "token_alias", "YourToken2": "token_alias2"}
        config["webapp"]["oauth"] = {"google": {
            'id': 'googleid',
            'secret': 'secretkey'}
        }

        return config

    def setup(self):
        # zwave devices --------------------------------------------------------
        self.zwave_hallway_light_power = EventObject("zwave", "72057462682163904")

        # WebApp ---------------------------------------------------------------
        self.webapp_hallway_light = EventObject("webapp", "toggle.hallway.hallway")

        # API Event ------------------------------------------------------------
        self.api_event = EventObject("webapp", "api.token_alias.event_name")


    def process_event(self):
        if self.webapp_hallway_light.event == "request_true":
            self.webapp_hallway_light.set("request_true")
            self.zwave_hallway_light_power.set("true")

        if self.webapp_hallway_light.event == "request_false":
            self.webapp_hallway_light.set("request_false")
            self.zwave_hallway_light_power.set("false")

        if self.zwave_hallway_light_power.event == "true":
            self.webapp_hallway_light.set("true")

        if self.zwave_hallway_light_power.event == "false":
            self.webapp_hallway_light.set("false")

Config Setup color and slider example

Turn on/off zwave device though the webapp

class Config(ConfigObject):

    def config(self):
        config = {}

        # WebApp
        config["webapp"] = {}
        config["webapp"]["servers"] = ["yeelight"]
        config["webapp"]["admin"] = {"email": "youremail@email.com", "name": "UserName"}
        config["webapp"]["tokens"] = {"YourToken": "token_alias", "YourToken2": "token_alias2"}
        config["webapp"]["oauth"] = {"google": {
            'id': 'googleid',
            'secret': 'secretkey'}
        }

        return config

    def setup(self):
        # Yeelight devices ---------------------------------------------------------
        self.yeelight_livingroom_ball_light_power   = EventObject("yeelight", "192.168.32.20:power")    # Power event, turns light on/off
        self.yeelight_livingroom_ball_light_bright  = EventObject("yeelight", "192.168.32.20:bright")   # Bright event, set brightness
        self.yeelight_livingroom_ball_light_color   = EventObject("yeelight", "192.168.32.20:color")    # Color event, set color on the light

        # WebApp -------------------------------------------------------------------
        self.web_ball_light_power = EventObject("webapp", "toggle.ball_light.ball_light")       # Toggle ui, adds a button that can turn on/off and can be waiting for response
        self.web_ball_light_slide = EventObject("webapp", "slide.ball_light.slide")             # Slide ui, adds a slider that goes between 0-100
        self.web_ball_light_color = EventObject("webapp", "color.ball_light.color", "ff0000")   # Color ui, adds a color picker

    def process_event(self):
        # Setup connection to webapp toggle button
        if self.web_ball_light_power.event == "request_true":
            self.web_ball_light_power.set("request_true")
            self.yeelight_livingroom_ball_light_power.set("true")

        elif self.web_ball_light_power.event == "request_false":
            self.web_ball_light_power.set("request_false")
            self.yeelight_livingroom_ball_light_power.set("false")

        if self.yeelight_livingroom_ball_light_power.event == "true":
            self.web_ball_light_power.set("true")

        elif self.yeelight_livingroom_ball_light_power.event == "false":
            self.web_ball_light_power.set("false")

        # Setup connection to webapp slide button
        if self.web_ball_light_slide.event:
            self.yeelight_livingroom_ball_light_bright.set(self.web_ball_light_slide.event)

        elif self.yeelight_livingroom_ball_light_bright.event:
            self.web_ball_light_slide.set(self.yeelight_livingroom_ball_light_bright.event)

        # Setup connection to webapp color button
        if self.web_ball_light_color.event:
            self.yeelight_livingroom_ball_light_color.set(self.web_ball_light_color.event)

        elif self.yeelight_livingroom_ball_light_color.event:
            self.web_ball_light_color.set(self.yeelight_livingroom_ball_light_color.event)