Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions dialLayout.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"id": "$B1",
"items": [
{
"key": "title",
"type": "text",
"rect": [ 16, 10, 136, 24 ],
"font": {
"size": 16,
"weight": 600
},
"alignment": "left"
},
{
"key": "icon",
"type": "pixmap",
"rect": [ 16, 40, 48, 48 ]
},
{
"key": "value",
"type": "text",
"rect": [ 76, 40, 108, 32 ],
"font": {
"size": 24,
"weight": 600
},
"alignment": "right"
},
{
"key": "indicator",
"type": "gbar",
"rect": [ 76, 74, 108, 20 ],
"value": 0,
"subtype": 4,
"bar_h": 12,
"border_w": 0,
"bar_bg_c": "0:#427018,1:#427018"
}
]
}
25 changes: 24 additions & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"Name": "Toggle Switch",
"States": [
{
"Image": "resources/img/light_gray",
"Image": "resources/img/light_gray.png",
"TitleAlignment": "bottom",
"FontSize": "12",
"Title": "Switch"
Expand All @@ -15,6 +15,29 @@
"Tooltip": "This action toggles a switch",
"UUID": "com.ripnet.hubitat.toggleswitch.action"
},
{
"Icon": "resources/img/toggle",
"Name": "Dial Switch",
"States": [
{
"Image": "resources/img/bulb_gray.png",
"TitleAlignment": "bottom",
"FontSize": "12",
"Title": "Switch"
}
],
"Controllers": [ "Encoder" ],
"Encoder": {
"layout": "dialLayout.json",
"TriggerDescription": {
"Rotate": "Increase/Decrease Level",
"Push": "Toggle On/Off"
}
},
"SupportedInMultiActions": true,
"Tooltip": "This action controls a switch with a dial",
"UUID": "com.ripnet.hubitat.dialswitch.action"
},
{
"Icon": "resources/img/toggle",
"Name": "Set Switch",
Expand Down
89 changes: 63 additions & 26 deletions plugin/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,16 @@

function start() {
// StreamDeck connected, subscribe to events
$sd.subscribe('dialRotate', dialRotate)
$sd.subscribe('dialPress', dialPress)
$sd.subscribe('keyDown', keyDown)
//$sd.subscribe('keyUp', buttonPress);
$sd.subscribe('keyUp', keyUp);
$sd.subscribe('willAppear', appear);
$sd.subscribe('didReceiveGlobalSettings', receivedGlobalSettings);
$sd.subscribe('didReceiveSettings', receivedSettings);
$sd.sendEvents(); // ready!
}






const hubitat = {
start: function() {
let url = new URL(globalSettings.hostname)
Expand Down Expand Up @@ -125,20 +121,35 @@
}

function updateState(instance) {
const level = instances[instance].level;
const state = instances[instance].state;


switch (state) {
case "on":
$sd.setImageFile(instance, 'light_green');
$sd.setImageFile(instance, 'bulb_green');
$sd.setFeedback(instance, {
"icon": "./resources/img/bulb_green.png",
"value": level.toString(),
"indicator": { "value": level, "enabled": true }
})
break;
case "off":
$sd.setImageFile(instance, 'light_red');
$sd.setImageFile(instance, 'bulb_red');
$sd.setFeedback(instance, {
"icon": "./resources/img/bulb_red.png",
"value": "0",
"indicator": { "value": 0, "enabled": false }
})
break;
case "setLevel":
break;
default:
$sd.setImageFile(instance, 'light_gray');
$sd.setImageFile(instance, 'bulb_gray');
$sd.setFeedback(instance, {
"icon": "./resources/img/bulb_gray.png",
"value": "0",
"indicator": { "value": 0, "enabled": false }
})
}
}

Expand All @@ -147,23 +158,19 @@
const state = instances[instance].state;

if (state === "on") {
if (level < 17) {
$sd.setImageFile(instance, 'light_green_1');
} else if (level < 34) {
$sd.setImageFile(instance, 'light_green_2');
} else if (level < 50) {
$sd.setImageFile(instance, 'light_green_3');
} else if (level < 67) {
$sd.setImageFile(instance, 'light_green_4');
} else if (level < 84) {
$sd.setImageFile(instance, 'light_green_5');
} else {
$sd.setImageFile(instance, 'light_green');
}

$sd.setFeedback(instance, {
"icon": "./resources/img/bulb_green.png",
"value": level.toString(),
"indicator": { "value": level, "enabled": true }
})

$sd.setImageFile(instance, 'bulb_green');

} else if (state === "off") {
$sd.setImageFile(instance, 'light_red');
$sd.setImageFile(instance, 'bulb_red');
} else {
$sd.setImageFile(instance, 'light_gray');
$sd.setImageFile(instance, 'bulb_gray');
}

}
Expand Down Expand Up @@ -235,7 +242,6 @@

}


function keyUp(data) {

switch (data.action) {
Expand All @@ -250,6 +256,7 @@
}

}

function keyDown(data) {
instances[data.context]['settings'] = data.payload.settings;
switch (data.action) {
Expand Down Expand Up @@ -328,6 +335,7 @@
}

}

function multi_doubleClick(data) {
let newLevel = instances[data.context].level - 17;

Expand All @@ -342,10 +350,39 @@


}

function multi_held(data) {
hubitat.setState(data.context, "off");
}

function dialRotate(data) {
let adjustment = data.payload.ticks * 2 //adjust multiplier for knob sensitivity.
let newLevel = instances[data.context].level + adjustment;

if (newLevel < 1) {
hubitat.setState(data.context, "off");
updateLevel(data.context);
} else {
hubitat.setState(data.context, "setLevel", String(newLevel));
instances[data.context].level = newLevel;
updateLevel(data.context);
}

}

function dialPress(data) {

if (!data.payload.pressed) {
return;
}

if (instances[data.context].state === "off") {
hubitat.setState(data.context, "on");
} else {
hubitat.setState(data.context, "off");
}

}

</script>
</body>
Expand Down
Binary file added resources/img/bulb_gray.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/img/bulb_green.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/img/bulb_red.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed resources/img/light_gray.png
Binary file not shown.
Binary file removed resources/img/light_gray@2x.png
Binary file not shown.
Binary file removed resources/img/light_green.png
Binary file not shown.
Binary file removed resources/img/light_green_1.png
Binary file not shown.
Binary file removed resources/img/light_green_2.png
Binary file not shown.
Binary file removed resources/img/light_green_3.png
Binary file not shown.
Binary file removed resources/img/light_green_4.png
Binary file not shown.
Binary file removed resources/img/light_green_5.png
Binary file not shown.
Binary file removed resources/img/light_red.png
Binary file not shown.
5 changes: 5 additions & 0 deletions resources/js/streamdeck.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ class StreamDeck extends Emitter {
this.sendMessage({'event': 'setSettings', 'context': context, 'payload': settings});
}

setFeedback(context, feedback) {
console.log(feedback)
this.sendMessage({'event': 'setFeedback', 'context': context, 'payload': feedback});
}

ready = false;
}
let $sd = {ready: false};
Expand Down