Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Discussion options

I know that there is a branch that has made some progress on implementing schedules. If it is possible yet, I was wondering if any of you wizards could provide an example script to add a countdown timer to power off a plug after 1 minute. My hope is to run it during shutdown on my raspberry pi, so that it can be automatically powered off after safely shutting down.

You must be logged in to vote

So I just checked how this works on KP115, and from the looks of it there can only be a single countdown timer and they do not get removed automatically... However, here's what you could do using raw commands to achieve your goal:

  1. Create a rule that is disabled for now:
$ kasa --host 192.168.xx.xx raw-command count_down add_rule '{"enable": 0, "delay": 5, "act": 0, "name": "test"}'
No --strip nor --bulb nor --plug given, discovering..
{'id': 'FFCC02F439FFEE7E1D8853935949AA4A'}

Note down the rule id or perform a query to list available rules, you will need this to modify the rule to activate it later.
If you get an error on already existing rule, you can either delete this by using dele…

Replies: 3 comments · 5 replies

Comment options

So I just checked how this works on KP115, and from the looks of it there can only be a single countdown timer and they do not get removed automatically... However, here's what you could do using raw commands to achieve your goal:

  1. Create a rule that is disabled for now:
$ kasa --host 192.168.xx.xx raw-command count_down add_rule '{"enable": 0, "delay": 5, "act": 0, "name": "test"}'
No --strip nor --bulb nor --plug given, discovering..
{'id': 'FFCC02F439FFEE7E1D8853935949AA4A'}

Note down the rule id or perform a query to list available rules, you will need this to modify the rule to activate it later.
If you get an error on already existing rule, you can either delete this by using delete_rule and passing the ID as payload, or re-use the timer by noting down the ID returned by get_rules (see the next step).

  1. You can check that the rule exists:
kasa --host 192.168.xx.xx raw-command count_down get_rules
No --strip nor --bulb nor --plug given, discovering..
{'rule_list': [{'id': 'FFCC02F439FFEE7E1D8853935949AA4A', 'name': 'foo', 'enable': 0, 'delay': 5, 'act': 0, 'remain': 0}]}
  1. Start the count down by setting the enable to 1, you can also adjust other settings if wanted:
kasa --host 192.168.xx.xx raw-command count_down edit_rule '{"id": "FFCC02F439FFEE7E1D8853935949AA4A", "enable": 1, "delay": 5, "act": 0, "name": "foo"}'

delay indicates in how many seconds the rule will be executed, act can be either 0 (turn off) or 1 (turn on).

The action will be run after the timer expires, and it will get disabled. You can re-run the same edit_rule command to re-enable it.

You must be logged in to vote
2 replies
@senghauser
Comment options

Thanks so much! it works exactly as I had hoped

@jneilliii
Comment options

@rytilahti is this possible with python-kasa as a module? I don't see any form of "raw-command" in the docs.

Answer selected by senghauser
Comment options

I'm getting an error on a HS110(UK) plug when I try it, does anyone have any thoughts on how I can resolve?

./kasa --host 192.168.1.3 raw-command count_down add_rule '{"enable": 0, "delay": 5, "act": 0, "name": "test"}'
No --type defined, discovering..
Got error: SmartDeviceException("Error on count_down add_rule: {'err_code': -10, 'err_msg': 'table is full'}")

You must be logged in to vote
2 replies
@senghauser
Comment options

It sounds like your device's rule list is already full, so it is throwing an error when you are trying to add a new rule.

You can use the second command in rytilahti's comment to check for existing rules, then use the third comment to edit one of those rules instead of adding a new one.

@MrSimmo
Comment options

It looks like the rule table is empty, which is odd?

kasa --host 192.168.1.3 raw-command count_down get_rules
No --type defined, discovering..
{"rule_list": }

Comment options

Has the raw-command been deprecated? I can't seem to get it working:
Error: No such command 'raw-command'.

You must be logged in to vote
1 reply
@Big-Channie
Comment options

Im getting the same issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
🙏
Q&A
Labels
None yet
6 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.