Skip to content

Commit 5296c7c

Browse files
Install README.md as an online manual
1 parent 99591f5 commit 5296c7c

5 files changed

Lines changed: 46 additions & 1 deletion

File tree

Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ SHARE=$(prefix)/share/house
2727
INSTALL=/usr/bin/install
2828

2929
HAPP=housekasa
30+
HMAN=/var/lib/house/note/content/manuals/automation
31+
HMANCACHE=/var/lib/house/note/cache
3032

3133
# Application build. --------------------------------------------
3234

@@ -54,6 +56,9 @@ kasa: kasa.c
5456
install-ui: install-preamble
5557
$(INSTALL) -m 0755 -d $(DESTDIR)$(SHARE)/public/kasa
5658
$(INSTALL) -m 0644 public/* $(DESTDIR)$(SHARE)/public/kasa
59+
$(INSTALL) -m 0755 -d $(DESTDIR)$(HMAN)
60+
$(INSTALL) -m 0644 README.md $(DESTDIR)$(HMAN)/$(HAPP).md
61+
rm -rf $(DESTDIR)$(HMANCACHE)/*
5762

5863
install-runtime: install-preamble
5964
$(INSTALL) -m 0755 -s housekasa kasa $(DESTDIR)$(prefix)/bin
@@ -64,6 +69,8 @@ install-app: install-ui install-runtime
6469
uninstall-app:
6570
rm -f $(DESTDIR)$(prefix)/bin/housekasa $(DESTDIR)$(prefix)/bin/kasa
6671
rm -rf $(DESTDIR)$(SHARE)/public/kasa
72+
rm -f $(DESTDIR)$(HMAN)/$(HAPP).md
73+
rm -rf $(DESTDIR)$(HMANCACHE)/*
6774

6875
purge-app:
6976

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# HouseKasa
2+
23
A House web service to control TP-Link Kasa devices (lights, plugs..)
34

45
## Overview
@@ -29,8 +30,10 @@ So far HouseKasa has been tested with the following US models:
2930
Otherwise installing [houselights](https://github.com/pascal-fb-martin/houselights) is recommended, but not necessarily on the same computer.
3031

3132
## Configuration
33+
3234
The preferred method is to configure the devices from the Configure web page.
3335
The configuration is stored in file /etc/house/kasa.json. A typical example of configuration is:
36+
3437
```
3538
{
3639
"kasa" : {
@@ -49,7 +52,9 @@ The configuration is stored in file /etc/house/kasa.json. A typical example of c
4952
}
5053
}
5154
```
55+
5256
## Device Setup
57+
5358
Each device must be setup using the Kasa phone app. The protocol for setting up devices has not been reverse engineered at that time.
5459

5560
## Kasa Protocol
@@ -73,6 +78,7 @@ TCP-based commands are prefixed with a big-endian 4 bytes integer, which represe
7378
#### HS220
7479

7580
The example bellow shows the discovery of a HS220 (US model), using UDP:
81+
7682
```
7783
> {"system":{"get_sysinfo":{}}}
7884
< {"system":{"get_sysinfo":{"sw_ver":"1.5.11 Build 200214 Rel.152651",
@@ -88,34 +94,40 @@ The example bellow shows the discovery of a HS220 (US model), using UDP:
8894
"preferred_state":[{"index":0,"brightness":100},{"index":1,"brightness":75},{"index":2,"brightness":50},{"index":3,"brightness":25}],
8995
"next_action":{"type":-1},"err_code":0}}}
9096
```
97+
9198
In the example above, the system.get_sysinfo command returns a long structure that indicates the model of the device (system.get_sysinfo.model) and its device ID (system.get_sysinfo.deviceID.
9299

93100
This device is a single dimmer, and the state is directly part of the system.get_sysinfo structure (e.g. system.get_sysinfo.relay_state). It has four preferred levels (in array system.get_sysinfo.preferred_state: 100%, 75%, 50% and 25%). These preferred levels are shown on the phone app as shortcuts in the dimmer control screen.
94101

95102
The device can be turned on and of, without changing the dimmer level:
103+
96104
```
97105
> {"context":{"source":"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"},"smartlife.iot.dimmer":{"set_switch_state":{"state":0}}}
98106
< {"smartlife.iot.dimmer":{"set_switch_state":{"err_code":0}}}
99107
```
108+
100109
The "smartlife.iot.dimmer.set_switch_state.state" item controls if the light is on (1) or off (0).
101110

102111
The context structure is optional.
103112

104113
The brightness level is also controllable:
114+
105115
```
106116
> {"context":{"source":"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"},
107117
"smartlife.iot.dimmer":{"set_brightness":{"brightness":75},
108118
"set_switch_state":{"state":1}}}
109119
< {"smartlife.iot.dimmer":{"set_brightness":{"err_code":0},
110120
"set_switch_state":{"err_code":0}}}
111121
```
122+
112123
That command actually achieves two results: it both sets the dimmer level ("smartlife.iot.dimmer.set_brightness.brightness") and turns the light on ("smartlife.iot.dimmer.set_switch_state.state"). I guess the brightness level has little immediate effect when the light is turned off anyway.
113124

114125
(HouseKasa does not support controlling the dimmer level at this time.)
115126

116127
#### KP400
117128

118129
The example below shows the discovery of a KP400 (US model), using UDP:
130+
119131
```
120132
> {"system":{"get_sysinfo":{}}}
121133
< {"system":{"get_sysinfo":{"sw_ver":"1.0.6 Build 200821 Rel.090909",
@@ -129,26 +141,30 @@ The example below shows the discovery of a KP400 (US model), using UDP:
129141
"children":[{"id":"00","state":1,"alias":"Kasa_Smart Plug_BC6F_0","on_time":20,"next_action":{"type":-1}},{"id":"01","state":1,"alias":"Kasa_Smart Plug_BC6F_1","on_time":20,"next_action":{"type":-1}}],
130142
"child_num":2,"ntc_state":0,"err_code":0}}}
131143
```
144+
132145
The JSON returned is similar, but not all the same items are present (probably due to the different firmware version).
133146

134147
This device actually control two outlets independently, which is described in array "system.get_sysinfo.children". Note that each outlet has a two-character ID (00 and 01).
135148

136149
Note the "system.get_sysinfo.deviceID" value: this will be important later, when controlling each outlet.
137150

138151
Each outlet can be controlled independently by providing an identifier for that outlet. The outlet ID is the concatenation of the deviceID and outlet ID:
152+
139153
```
140154
> {"context":{"child_ids":["xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx042E00"],
141155
"source":"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"},
142156
"system":{"set_relay_state":{"state":1}}}
143157
< {"system":{"set_relay_state":{"err_code":0}}}
144158
```
159+
145160
The array context.child_ids indicates which outlet(s) should be controlled. Apparently the protocol allows controlling multiple outlets in one command. The "system.set_relay_state.state" value indicates if the outlet should be turned off (0) or on (1).
146161

147162
The source item is optional. The context struct is mandatory (at least if one wants to control a subset of the outlets).
148163

149164
#### Alias
150165

151166
Each device or outlet can be assigned an alias, which is a way for the user to give a name to each:
167+
152168
```
153169
> {"system":{"set_dev_alias":{"alias":"xxxxxxx"}}}
154170
< {"system":{"set_dev_alias":{"err_code":0}}}
@@ -167,7 +183,9 @@ Discovery of which devices are present on the network is made on a periodic basi
167183
```
168184
{"system":{"get_sysinfo":{}}}
169185
```
186+
170187
HouseKasa searches for the following items in the response:
188+
171189
```
172190
system.get_sysinfo.model
173191
system.get_sysinfo.alias (if not set in HouseKasa)
@@ -183,6 +201,7 @@ If the array "system.get_sysinfo.children" is present, its state and alias eleme
183201
The state of every known device is maintained by doing an unicast system.get_sysinfo request every 10 seconds, except after issuing a command, in which case the request is made at higher frequency for a minute, or else until the requested state was reached.
184202

185203
The Kasa devices (KP400 and HS220) all accept the "system.set_relay_state" command. However since the KP400 has two outlets, the exact outlet targetted must be specified using "context.child_ids". It happens that the HS220 also accept the presence of an outlet ID: it just ignores it. So the command sent for on and off is:
204+
186205
```
187206
{"context":{"child_ids":["xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"]},"system":{"set_relay_state":{"state":x}}}
188207
```
@@ -194,30 +213,41 @@ HouseKasa will query the state of each known device periodically (unicast UDP pa
194213
## Command line tool
195214

196215
This software provides a tool named `kasa` to test controls of device:
216+
197217
```
198218
kasa
199219
```
220+
200221
Query the status of all devices present. This is a way to do some manual discovery.
222+
201223
```
202224
kasa *host*
203225
```
226+
204227
Query the status of the specified device.
228+
205229
```
206230
kasa *host* alias *name*
207231
```
208232

209233
Set the alias name for this device. This alias name is stored in the device.
234+
210235
```
211236
kasa *host* on|off [hs220]
212237
```
238+
213239
Set the device on or off. The hs220 option makes the tool use the alternative syntax accepted by the HS220 devices.
240+
214241
```
215242
kasa *host* on|off kp400 *n*
216243
```
244+
217245
Set an outlet on or off on a KP400 device. The KP400 has multiple outlets that can be controled independently, which is why the outlet number must be specified.
246+
218247
```
219248
kasa -h|--help|help
220249
```
250+
221251
Show the tool's help.
222252

223253
## Debian Packaging
@@ -232,6 +262,7 @@ The provided Makefile supports building private Debian packages. These are _not_
232262
no source package.
233263

234264
To build a Debian package, use the `debian-package` target:
265+
235266
```
236267
make debian-package
237268
```

debian/changelog

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
housekasa (1.1) UNREALEASED; urgency=low
2+
3+
* Install README.md as an online manual.
4+
5+
-- Pascal Martin <pascal.fb.martin@gmail.com> Wed, 15 Aug 2025 12:00:00 PDT
6+
17
housekasa (1.0) UNREALEASED; urgency=low
28

39
* Initial release as a Debian package.

debian/control

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Source: housekasa
2-
Version: 1.0
2+
Version: 1.1
33
Section: Web servers
44
Maintainer: Pascal Martin <pascal.fb.martin@gmail.com>
55
Priority: optional

debian/postinst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ HAPP=housekasa
44

55
case $1 in
66
configure|abort-upgrade|abort-deconfigure|abort-remove)
7+
if [ -d /var/lib/house/note/cache ] ; then rm -rf /var/lib/house/note/cache/* ; fi
78
grep -q '^house:' /etc/passwd || useradd -r house -s /usr/sbin/nologin -d /var/lib/house
89
systemctl daemon-reload
910
if systemctl is-active --quiet $HAPP ; then

0 commit comments

Comments
 (0)