diff --git a/docs/configuration.md b/docs/configuration.md index 5cf873e..880296e 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -219,6 +219,7 @@ port: address: password: output_id: +timer: # The above options are used for "tasmota" devices. The # address should be a valid ip or hostname for the tasmota device. # Provide a password if configured in Tasmota (default is empty). @@ -231,12 +232,16 @@ address: user: password: output_id: +timer: # The above options are used for "shelly" devices. The # address should be a valid ip or hostname for the Shelly device. # Provide a user and password if configured in Shelly (default is empty). # If password is set but user is empty the default user "admin" will be used # Provided an output_id (relay id) if the Shelly device supports # more than one (default is 0). +# When timer option is used to delay the turn off make sure to set +# the state to "on" in action call_remote_method. +# So we send a command to turn it on for x sec when its already on then it turns off. address: device: user: diff --git a/moonraker/components/power.py b/moonraker/components/power.py index d82af1a..4193fbf 100644 --- a/moonraker/components/power.py +++ b/moonraker/components/power.py @@ -420,10 +420,13 @@ class Tasmota(PowerDevice): self.addr = config.get("address") self.output_id = config.getint("output_id", 1) self.password = config.get("password", "") + self.timer = config.get("timer","") async def _send_tasmota_command(self, command, password=None): if command in ["on", "off"]: out_cmd = f"Power{self.output_id}%20{command}" + if self.timer != "" and command == "off": + out_cmd = f"Backlog%20Delay%20{self.timer}0%3B%20{out_cmd}" elif command == "info": out_cmd = f"Power{self.output_id}" else: @@ -471,13 +474,14 @@ class Tasmota(PowerDevice): async def set_power(self, state): try: res = await self._send_tasmota_command(state) - try: - state = res[f"POWER{self.output_id}"].lower() - except KeyError as e: - if self.output_id == 1 : - state = res[f"POWER"].lower() - else: - raise KeyError(e) + if self.timer == "" or state != "off": + try: + state = res[f"POWER{self.output_id}"].lower() + except KeyError as e: + if self.output_id == 1 : + state = res[f"POWER"].lower() + else: + raise KeyError(e) except Exception: self.state = "error" msg = f"Error Setting Device Status: {self.name} to {state}" @@ -494,10 +498,14 @@ class Shelly(PowerDevice): self.output_id = config.getint("output_id", 0) self.user = config.get("user", "admin") self.password = config.get("password", "") + self.timer = config.get("timer","") async def _send_shelly_command(self, command): if command in ["on", "off"]: - out_cmd = f"relay/{self.output_id}?turn={command}" + if self.timer != "": + out_cmd = f"relay/{self.output_id}?turn={command}&timer={self.timer}" + else: + out_cmd = f"relay/{self.output_id}?turn={command}" elif command == "info": out_cmd = f"relay/{self.output_id}" else: