Here is my slow and anti-climactic motorized TV mount hooked up to HA using the RM Mini Remote and some code to send commands through AppDaemon.
Here is a demo video (partially sped up the video because the motor is slow for safety reasons, you can tell by the audio):
Here is the APPDAEMON code i used to control it up and down (I very much welcome comments on improving my coding, even minor nitpicking. thank you):
import appdaemon.plugins.hass.hassapi as hass
import datetime
import time
#
# Send command to stop the motor then lift/drop the tv mount
#
class TVDrop(hass.Hass):
def initialize(self):
self.remote_entity_id = "remote.broadlink"
self.learned_cmd_device_name = "lift"
self.mediaplayer_entity_id = "media_player.bedroom_samsung_tv"
self.runin_handle = None
self.listen_state(self.LiftTV, "input_boolean.lift", new = "off", old = "on")
self.listen_state(self.DropTV, "input_boolean.lift", new = "on", old = "off")
def LiftTV(self, entity, attribute, old, new, kwargs):
remote_id = self.remote_entity_id
device_name = self.learned_cmd_device_name
TV_ID = self.mediaplayer_entity_id
desired_state = "off"
self.log("Step 0: <" + "LiftTV CALLED" + ">")
self.log("Step 1: <Turn {} TV>".format(desired_state))
self.TV_OFF_ON(remote_id,device_name,TV_ID,desired_state)
self.log("Step 1: <" + "SEND *STOP* TV COMMAND" + ">")
self.remoteCommandSTOP(remote_id,device_name)
self.log("Step 2: <" + "SEND *UP* TV COMMAND" + ">")
self.remoteCommandUP(remote_id,device_name)
def DropTV(self, entity, attribute, old, new, kwargs):
remote_id = self.remote_entity_id
device_name = self.learned_cmd_device_name
TV_ID = self.mediaplayer_entity_id
desired_state = "on"
self.log("Step 0: <" + "DropTV CALLED" + ">")
self.log("Step 1: <" + "SEND *STOP* TV COMMAND" + ">")
self.remoteCommandSTOP(remote_id,device_name)
self.log("Step 2: <" + "SEND *DOWN* TV COMMAND" + ">")
self.remoteCommandDOWN(remote_id,device_name)
self.log("Step 1: <Turn {} TV>".format(desired_state))
self.TV_OFF_ON(remote_id,device_name,TV_ID,desired_state)
def remoteCommandSTOP(self,remote_id,device_name):
''' entity_id: remote.broadlink
device: lift
command: STOP
num_repeats: 5
delay_secs: 0.75
hold_secs: 2.5 '''
repeatCommand = 5
delay = 0.75
hold_s = 2.5
cmd = "STOP"
self.call_service("remote/send_command", entity_id = remote_id, device = device_name, command = cmd, num_repeats = repeatCommand, delay_secs = delay, hold_secs = hold_s)
def remoteCommandUP(self,remote_id,device_name):
repeatCommand = 5
delay = 0.75
hold_s = 2.5
cmd = "UP"
self.call_service("remote/send_command", entity_id = remote_id, device = device_name, command = cmd, num_repeats = repeatCommand, delay_secs = delay, hold_secs = hold_s)
def remoteCommandDOWN(self,remote_id,device_name):
repeatCommand = 5
delay = 0.75
hold_s = 2.5
cmd = "DOWN"
self.call_service("remote/send_command", entity_id = remote_id, device = device_name, command = cmd, num_repeats = repeatCommand, delay_secs = delay, hold_secs = hold_s)
def TV_OFF_ON(self,remote_id,device_name,TV_ID,desired_state):
self.log("------ TV ON/OFF TEMPORARELY DISABLED -----")
return
#get state of TV
state = self.get_state(TV_ID)
#set delay before retring IR signal
run_in_s = 10
#Create a log msg for debugging
self.log("<><> The state of [{}] is [{}], we want it [{}]".format(TV_ID,state,desired_state))
#check if tv is in the desired on/off state
if state == desired_state:
return
else: #if not in the desired state, send the IR signal to power on/off
self.remoteCommandTVPOWER(remote_id,device_name)
#check if tv is in the desired on/off state [AGAIN]
if self.run_in(self.get_state(TV_ID),2) == desired_state:
return
else:
#Call function again if still not off
self.log("TV did not return derired state ({}), trying again in {}".format(desired_state,run_in_s))
self.run_in(self.TV_OFF_ON(remote_id,device_name,TV_ID,desired_state),run_in_s)
def remoteCommandTVPOWER(self,remote_id,device_name):
self.log("Sending power IR signal to {}".format(device_name))
repeatCommand = 1
delay = 0.2
hold_s = 1
cmd = "power_on1"
device_name = "television"
self.call_service("remote/send_command", entity_id = remote_id, device = device_name, command = cmd, num_repeats = repeatCommand, delay_secs = delay, hold_secs = hold_s)
Can anyone suggest a good card to control the lift/drop? I used a button card, but the up/down arrows you see on cover
entities might be cool. I dont know how to create that tho.
Any suggestions welcome