Thanks to @Robban I got something up and running! Could somebody with python experience tell me if I am doing anything terribly wrong or if I could streamline my code in a better way?
class LivingRoomSceneStore(appapi.AppDaemon):
def initialize(self):
self.tv_lightstrip_previous_state = 0
self.lamp_l_previous_state = 0
self.lamp_r_previous_state = 0
self.entryway_1_previous_state = 0
self.entryway_2_previous_state = 0
self.listen_state(self.change, "input_boolean.movie_time", attribute = "all")
self.listen_state(self.restore, "input_boolean.movie_time", attribute = "all")
self.log("Save and restore initialized!")
def change(self, entity, attribute, old, new, kwargs):
if ("state" in new and new["state"] == "on" and old["state"] == "off") or new == "on":
self.tv_lightstrip_previous_state = self.get_state("light.tv_lightstrip", "all")
self.lamp_l_previous_state = self.get_state("light.floor_lamp_l", "all")
self.lamp_r_previous_state = self.get_state("light.floor_lamp_r", "all")
self.entryway_1_previous_state = self.get_state("light.entryway_1", "all")
self.entryway_2_previous_state = self.get_state("light.entryway_2", "all")
self.turn_on("light.tv_lightstrip", brightness = 45, rgb_color = [119, 104, 80], transition = 10)
self.turn_on("light.floor_lamp_l", brightness = 15, rgb_color = [56, 56, 119], transition = 10)
self.turn_on("light.floor_lamp_r", brightness = 15, rgb_color = [56, 56, 119], transition = 10)
self.turn_on("light.entryway_1", brightness = 20, transition = 10)
self.turn_on("light.entryway_2", brightness = 20, transition = 10)
def restore(self, entity, attribute, old, new, kwargs):
if ("state" in new and new["state"] == "off" and old["state"] == "on") or new == "off":
if self.tv_lightstrip_previous_state['state'] == "on":
self.turn_on("light.tv_lightstrip", brightness = self.tv_lightstrip_previous_state['attributes']['brightness'], rgb_color = self.tv_lightstrip_previous_state['attributes']['rgb_color'])
else:
self.turn_off("light.tv_lightstrip")
if self.lamp_l_previous_state['state'] == "on":
self.turn_on("light.floor_lamp_l", brightness = self.lamp_l_previous_state['attributes']['brightness'], rgb_color = self.lamp_l_previous_state['attributes']['rgb_color'])
else:
self.turn_off("light.floor_lamp_l")
if self.lamp_r_previous_state['state'] == "on":
self.turn_on("light.floor_lamp_r", brightness = self.lamp_r_previous_state['attributes']['brightness'], rgb_color = self.lamp_r_previous_state['attributes']['rgb_color'])
else:
self.turn_off("light.floor_lamp_r")
if self.entryway_1_previous_state['state'] == "on":
self.turn_on("light.entryway_1", brightness = self.entryway_1_previous_state['attributes']['brightness'])
else:
self.turn_off("light.entryway_1")
if self.entryway_2_previous_state['state'] == "on":
self.turn_on("light.entryway_2", brightness = self.entryway_2_previous_state['attributes']['brightness'])
else:
self.turn_off("light.entryway_2")