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
199 changes: 174 additions & 25 deletions PlexManager/PlexHomeTheatre.groovy
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/**
* Pi Relay Control
* Plex Home Theatre
*
* Copyright 2016 Tom Beech
* Modified by Ph4r
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at:
Expand All @@ -28,13 +29,31 @@
metadata {
definition (name: "Plex Home Theatre", namespace: "ibeech", author: "ibeech") {
capability "Switch"
capability "musicPlayer"
capability "musicPlayer"
capability "Sensor"
capability "Actuator"

command "scanNewClients"
command "setPlaybackIcon", ["string"]
command "setPlaybackTitle", ["string"]
command "setVolumeLevel", ["number"]
}
command "setVolumeLevel", ["number"]
command "setPlaybackPosition", ["number"]
command "setPlaybackDuration", ["number"]
command "playbackType", ["string"]
command "stepBack"
command "stepForward"
command "home"
command "moveUp"
command "music"
command "moveLeft"
command "select"
command "moveRight"
command "back"
command "moveDown"

input name: "CommandTarget", type: "enum", title: "Command Target", options: ["Server", "Client", "ServerProxy"], description: "Select Command Target", required: true, defaultValue: "Client"
input name: "TimelineStatus", type: "enum", title: "Timeline Status", options: ["None", "Subscribe", "Poll", "ServerSubscribe"], description: "Select How To Get Status", required: true, defaultValue: "Subscribe"
}

simulator {
// TODO: define status and reply messages here
Expand All @@ -44,9 +63,9 @@ metadata {

multiAttributeTile(name:"status", type: "generic", width: 6, height: 4, canChangeIcon: true){
tileAttribute ("device.status", key: "PRIMARY_CONTROL") {
attributeState "playing", label:'Playing', action:"music Player.pause", icon:"st.Electronics.electronics16", nextState:"paused", backgroundColor:"#79b821"
attributeState "playing", label:'Playing', action:"music Player.pause", icon:"st.Electronics.electronics16", nextState:"paused", backgroundColor:"#00a0dc"
attributeState "stopped", label:'Stopped', action:"music Player.play", icon:"st.Electronics.electronics16", backgroundColor:"#ffffff"
attributeState "paused", label:'Paused', action:"music Player.play", icon:"st.Electronics.electronics16", nextState:"playing", backgroundColor:"#FFA500"
attributeState "paused", label:'Paused', action:"music Player.play", icon:"st.Electronics.electronics16", nextState:"playing", backgroundColor:"#e86d13"
}
tileAttribute ("device.trackDescription", key: "SECONDARY_CONTROL") {
attributeState "trackDescription", label:'${currentValue}'
Expand All @@ -57,36 +76,81 @@ metadata {
}
}

standardTile("next", "device.status", width: 2, height: 2, decoration: "flat") {
state "next", label:'', action:"music Player.nextTrack", icon:"st.sonos.next-btn", backgroundColor:"#ffffff"
standardTile("previous", "device.status", width: 1, height: 1, decoration: "flat") {
state "previous", label:'', action:"music Player.previousTrack", icon:"st.sonos.previous-btn", backgroundColor:"#ffffff"
}

standardTile("stepBack", "device.status", width: 1, height: 1, decoration: "flat") {
state "stepBack", label:'<10', action:"stepBack", icon:"", backgroundColor:"#ffffff"
}

standardTile("stop", "device.status", width: 2, height: 1, decoration: "flat") {
state "default", label:'', action:"music Player.stop", icon:"st.sonos.stop-btn", backgroundColor:"#ffffff"
}

standardTile("previous", "device.status", width: 2, height: 2, decoration: "flat") {
state "previous", label:'', action:"music Player.previousTrack", icon:"st.sonos.previous-btn", backgroundColor:"#ffffff"
standardTile("stepForward", "device.status", width: 1, height: 1, decoration: "flat") {
state "stepForward", label:'>30', action:"stepForward", icon:"", backgroundColor:"#ffffff"
}

standardTile("fillerTile", "device.status", width: 5, height: 1, decoration: "flat") {
state "default", label:'', action:"", icon:"", backgroundColor:"#ffffff"
standardTile("next", "device.status", width: 1, height: 1, decoration: "flat") {
state "next", label:'', action:"music Player.nextTrack", icon:"st.sonos.next-btn", backgroundColor:"#ffffff"
}

standardTile("stop", "device.status", width: 2, height: 2, decoration: "flat") {
state "default", label:'', action:"music Player.stop", icon:"st.sonos.stop-btn", backgroundColor:"#ffffff"
state "grouped", label:'', action:"music Player.stop", icon:"st.sonos.stop-btn", backgroundColor:"#ffffff"
valueTile("playbackType", "device.playbackType", decoration: "flat", width: 6, height: 1) {
state "playbackType", label:'Playing: ${currentValue}', defaultState: true
}

controlTile("playbackPosition", "device.playbackPosition", "slider", width: 5, height: 1, range:"(0..100)") {
state "playbackPosition", label:'Position', action:"setPlaybackPosition"
}

valueTile("playbackDuration", "device.playbackDuration", width: 1, height: 1) {
state "playbackDuration", label:'${currentValue}', defaultState: 0
}

standardTile("home", "device.status", width: 2, height: 2, decoration: "flat") {
state "default", label:'', action:"home", icon:"st.Home.home2", backgroundColor:"#ffffff"
}

standardTile("moveUp", "device.status", width: 2, height: 2, decoration: "flat") {
state "default", label:'', action:"moveUp", icon:"st.thermostat.thermostat-up", backgroundColor:"#ffffff"
}

standardTile("music", "device.status", width: 2, height: 2, decoration: "flat") {
state "default", label:'music', action:"music", icon:"", backgroundColor:"#ffffff"
}

standardTile("scanNewClients", "device.status", width: 5, height: 1, decoration: "flat") {
state "default", label:'Scan New Clients', action:"scanNewClients", icon:"state.icon", backgroundColor:"#ffffff"
state "grouped", label:'', action:"scanNewClients", icon:"state.icon", backgroundColor:"#ffffff"
standardTile("moveLeft", "device.status", width: 2, height: 2, decoration: "flat") {
state "default", label:'', action:"moveLeft", icon:"st.thermostat.thermostat-left", backgroundColor:"#ffffff"
}

standardTile("select", "device.status", width: 2, height: 2, decoration: "flat") {
state "default", label:'select', action:"select", icon:"", backgroundColor:"#ffffff"
}

main "status"
details (["status", "previous", "stop", "next", "currentSong"])
standardTile("moveRight", "device.status", width: 2, height: 2, decoration: "flat") {
state "default", label:'', action:"moveRight", icon:"st.thermostat.thermostat-right", backgroundColor:"#ffffff"
}

standardTile("back", "device.status", width: 2, height: 2, decoration: "flat") {
state "default", label:'back', action:"back", icon:"", backgroundColor:"#ffffff"
}

standardTile("moveDown", "device.status", width: 2, height: 2, decoration: "flat") {
state "default", label:'', action:"moveDown", icon:"st.thermostat.thermostat-down", backgroundColor:"#ffffff"
}

standardTile("scanNewClients", "device.status", width: 2, height: 2, decoration: "flat") {
state "default", label:'New Clients', action:"scanNewClients", icon:"st.secondary.refresh", backgroundColor:"#ffffff"
}

main "status"
}
}

// parse events into attributes
def parse(String description) {
log.debug "Virtual siwtch parsing '${description}'"
log.debug "Virtual switch parsing '${description}'"
}

def play() {
Expand All @@ -112,13 +176,13 @@ def stop() {
sendEvent(name: "switch", value: device.deviceNetworkId + ".stop");
sendEvent(name: "switch", value: "off");
sendEvent(name: "status", value: "stopped");
setPlaybackTitle("Stopped");
//setPlaybackTitle("Stopped");
}

def previousTrack() {
log.debug "Executing 'previous': "

setPlaybackTitle("Skipping previous");
//setPlaybackTitle("Skipping previous");
sendCommand("previous");
}

Expand All @@ -140,6 +204,79 @@ def setVolumeLevel(level) {
sendCommand("setVolume." + level);
}

def setPlaybackPosition(level) {
log.debug "Executing 'setPlaybackPosition(" + level + ")'"
sendEvent(name: "playbackPosition", value: level);
sendCommand("setPosition." + level);
}

def setPlaybackDuration(level) {
log.debug "Executing 'setPlaybackDuration(" + level + ")'"
sendEvent(name: "playbackDuration", value: level);
}

def stepBack() {
log.debug "Executing 'stepBack'"

//setPlaybackTitle("Jumping back 10s");
sendCommand("stepBack");
}

def stepForward() {
log.debug "Executing 'stepForward'"

//setPlaybackTitle("Jumping up 30s");
sendCommand("stepForward");
}

def home() {
log.debug "Executing 'home'"

sendCommand("home");
}

def moveUp() {
log.debug "Executing 'moveUp'"

sendCommand("moveUp");
}

def music() {
log.debug "Executing 'music'"

sendCommand("music");
}

def moveLeft() {
log.debug "Executing 'moveLeft'"

sendCommand("moveLeft");
}

def select() {
log.debug "Executing 'select'"

sendCommand("select");
}

def moveRight() {
log.debug "Executing 'moveRight'"

sendCommand("moveRight");
}

def back() {
log.debug "Executing 'back'"

sendCommand("back");
}

def moveDown() {
log.debug "Executing 'moveDown'"

sendCommand("moveDown");
}

def sendCommand(command) {

def lastState = device.currentState('switch').getValue();
Expand All @@ -149,7 +286,7 @@ def sendCommand(command) {

def setPlaybackState(state) {

log.debug "Executing 'setPlaybackState'"
log.debug "Executing 'setPlaybackState' to state $state"
switch(state) {
case "stopped":
sendEvent(name: "switch", value: "off");
Expand Down Expand Up @@ -186,4 +323,16 @@ def setPlaybackIcon(iconUrl) {

def playbackType(type) {
sendEvent(name: "playbackType", value: type);
}
}

def volumeLevelIn(level) {
sendEvent(name: "level", value: level);
}

def playbackPositionIn(level) {
sendEvent(name: "playbackPosition", value: level);
}

def playbackDurationIn(level) {
sendEvent(name: "playbackDuration", value: level);
}
Loading