I have a KS200M (non-dimmer) working as an HS200. With Hilbrand’s help, I was able to get data from the light sensor. However, the motion sensor doesn’t appear to be exposed (even to other Kasa devices in the Kasa app). So, the most we can do right now is to enable/disable the motion sensor.
There’s a topic in the Kasa forum about this. If you want them to expose the motion sensor, you might want to add your voice to it.
Here are my DSL rules to enable/disable the motion sensor and get the ambient light. If you’re on OH 3.2, you’ll need to uninstall the release version of the TP-Link binding and install the beta from the marketplace. Hilbrand added an action to send JSON commands to switches.
Enable/disable motion sensor
This rule enables the motion sensor whenever my home is set to “Home” mode. In the Kasa app, I’ve set up the switch to always turn on when motion is detected, and then I use the openHAB rule to determine when it’s active.
Note that you need to replace hs200:INSERT_THING_ID
with your switch’s ID.
rule "Enable Bedroom motion detection (KS200M)"
when
Item System_Mode changed
then
var action = getActions("tplinksmarthome", "tplinksmarthome:hs200:INSERT_THING_ID")
if (System_Mode.state == "Home") { action.send('{"smartlife.iot.PIR":{"set_enable":{"enable":1}}}') }
else if (System_Mode.state != "Home") { action.send('{"smartlife.iot.PIR":{"set_enable":{"enable":0}}}') }
end
Get current ambient light
This rule queries the switch for the current ambient light, which I think is in Foot Candles (but I’m not certain of that). I’m triggering it when my other light sensors change or when certain light switches are turned on/off, but you could also use CRON. I just figured that these items would cover most of the scenarios when I’d want to get the light values.
For this rule you also need to have JSONPATH transformation installed.
rule "Update Bedroom Light Sensor (KS200M)"
when
Item Sensor_Light_Zooz changed or
Item Sensor_Light_Haozee changed or
Item Switch_Main_Lights changed or
Item Switch_Bedroom changed
then
var action = getActions("tplinksmarthome", "tplinksmarthome:hs200:INSERT_THING_ID")
Sensor_Bedroom_Light_JSON.postUpdate(action.send('{"smartlife.iot.LAS":{"get_current_brt":{}}}'))
//Returns: {"smartlife.iot.LAS":{"get_current_brt":{"value":VALUE,"err_code":0}}}
// use the transformation service to retrieve the value
val newValue = transform("JSONPATH", "$['smartlife.iot.LAS']['get_current_brt']['value']", Sensor_Bedroom_Light_JSON.state.toString())
// post the new value to the Number item and update timestamp
Sensor_Bedroom_Light.postUpdate(newValue)
Sensor_Bedroom_Light_Last.postUpdate(new DateTimeType())
end