Flic Home

    Community

    • Login
    • Search
    • Popular
    • Users

    Leviton?

    General Discussion
    2
    2
    377
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • superdave67
      superdave67 last edited by

      So is anyone using their Flic with any Leviton smart switches? I can't seem to associated any of my 5 outside flood lights controlled by 5 Leviton Smart switches. Anyone run into that?

      1 Reply Last reply Reply Quote 0
      • dustingtorres
        dustingtorres last edited by

        HI @superdave67 ,

        I use Flic with Leviton smart switches but I needed to use a custom setup on my Flic hub using the SDK.

        If you are interested in that approach you can use the sample code below.

        The const at the top need to be replaced with IDs specific to your setup. I think I can dig up a postman collection on how to get those IDs which I created based on this library. It is on a different computer, but I think I can get access to it in a few days.

        // main.js
        var buttonManager = require("buttons");
        var http = require("http");
        
        const L_DUSTIN_ID = "<LEVITON ID 1>";
        const L_CAT_ID = "<LEVITON ID 2>";
        const L_MASTER_ID = "<LEVITON ID 3>";
        const FLIC_BUTTON_ID = "<FLIC BUTTON ID>";
        const ACCESS_KEY = "<LEVITON ACCESS KEY>";
        function toggleSwitch(switchId) {
        	  console.log("toggling: " + switchId);
        	  // Get current Switch Status.
        	  http.makeRequest({
        			url: "https://my.leviton.com/api/IotSwitches/" + switchId,
        		  method: "GET",
        		  headers: {"Content-Type": "application/json", "authorization": ACCESS_KEY}		
        		}, function(err, res) {
        			
        			if(res.statusCode != 200) {
        				console.log("request status: " + res.statusMessage);
        			} else {
        				// Toggle the switch
        					http.makeRequest({
        						url: "https://my.leviton.com/api/IotSwitches/" + switchId,
        						method: "PUT",
        						headers: {"Content-Type": "application/json", "authorization": ACCESS_KEY},
        						content: JSON.stringify({"power": JSON.parse(res.content).power == "ON" ? "OFF": "ON"}),		
        				}, function(err, res) {
        					
        				});
        			}
        		});
        	
        }
        
        function handleButton(obj){
          if(obj.isSingleClick) {
        		toggleSwitch(L_DUSTIN_ID);
        	}
        	
        	if(obj.isDoubleClick) {
        		toggleSwitch(L_CAT_ID);
        	}
        	
        	if(obj.isHold) {
        		toggleSwitch(L_MASTER_ID);
        	}
        }
        
        buttonManager.on("buttonSingleOrDoubleClickOrHold", function(obj) {
        	var button = buttonManager.getButton(obj.bdaddr);
        	if(button.uuid == FLIC_BUTTON_ID) {
        		handleButton(obj)
        	}
        });
        
        console.log("Started");
        
        1 Reply Last reply Reply Quote 0
        • First post
          Last post