FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

KS220M(US) support · Issue #268 · python-kasa/python-kasa · GitHub

Repository navigation

KS220M(US) support #268

Closed
Closed

Description

It'd be great if Home Assistant could be used to manage the new KS220M Motion Detection Dimmer. I set up a man in the middle proxy and captured the following JSON commands being sent from the KASA app to the switch and changed various motion sensor settings. If someone better with Python wanted to integrate these, that'd be great.

Get the current PIR config:
Sent: {"smartlife.iot.PIR":{"get_config":{}}}
Received: {"smartlife.iot.PIR":{"get_config":{"enable":0,"version":"1.0","trigger_index":2,"cold_time":60000,"min_adc":0,"max_adc":4095,"array":[80,50,20,0],"err_code":0}}}

Disable the PIR: {"smartlife.iot.PIR":{"set_enable":{"enable":0}}}
Enable the PIR: {"smartlife.iot.PIR":{"set_enable":{"enable":1}}}
Set the PIR to far range detection: {"smartlife.iot.PIR":{"set_trigger_sens":{"index":0}}}
Mid Range: {"smartlife.iot.PIR":{"set_trigger_sens":{"index":1}}}
Near Range: {"smartlife.iot.PIR":{"set_trigger_sens":{"index":2}}}
"Custom" range of 20 ft: {"smartlife.iot.PIR":{"set_trigger_sens":{"index":3,"value":61}}} (Uses decimeters?)

I'll add more objects as I find them.

Activity

  1. mrbetta commented on Dec 8, 2021

    ContributorAuthor

    An integrated light sensor is used to disable the motion sensor if it's not needed:
    Disable sensor: {"smartlife.iot.LAS":{"set_enable":{"enable":0}}}
    Enable sensor: {"smartlife.iot.LAS":{"set_enable":{"enable":1}}}
    Get current config:
    Sent: {"smartlife.iot.LAS":{"get_config":{}}}
    Response: {"smartlife.iot.LAS":{"get_config":{"devs":[{"hw_id":0,"enable":0,"dark_index":1,"min_adc":0,"max_adc":2450,"level_array":[{"name":"cloudy","adc":490,"value":20},{"name":"overcast","adc":294,"value":12},{"name":"dawn","adc":222,"value":9},{"name":"twilight","adc":222,"value":9},{"name":"total darkness","adc":111,"value":4},{"name":"custom","adc":2400,"value":97}]}],"ver":"1.0","err_code":0}}}
    Get current light level in darkness:
    Sent: {"smartlife.iot.LAS":{"get_current_brt":{}}}
    Response: {"smartlife.iot.LAS":{"get_current_brt":{"value":0,"err_code":0}}}
    Current light level with surrounding lights on:
    Response: {"smartlife.iot.LAS":{"get_current_brt":{"value":26,"err_code":0}}}
    Set trigger light level to "Cloudy" preset: {"smartlife.iot.LAS":{"set_brt_level":{"index":0,"value":20}}}

  2. mrbetta commented on Dec 8, 2021

    ContributorAuthor

    It also has a feature to fade the lights on or off over time. Here's what that looks like:

    Get current settings with it set to "Instant On" and "Instant Off":
    Sent: {"smartlife.iot.dimmer":{"get_dimmer_parameters":{}}}
    Received: {"smartlife.iot.dimmer":{"get_dimmer_parameters":{"fadeOnTime":0,"fadeOffTime":0,"gentleOnTime":3000,"gentleOffTime":10000,"rampRate":30,"minThreshold":1,"bulb_type":1,"err_code":0}}}
    Fade on over 5 seconds: {"smartlife.iot.dimmer":{"set_fade_on_time":{"fadeTime":5000}}}
    Fade off over 5 seconds: {""smartlife.iot.dimmer":{"set_fade_off_time":{"fadeTime":5000}}}
    Response of the 'get' after setting fade on time:
    {"smartlife.iot.dimmer":{"get_dimmer_parameters":{"fadeOnTime":5000,"fadeOffTime":0,"gentleOnTime":3000,"gentleOffTime":10000,"rampRate":30,"minThreshold":1,"bulb_type":1,"err_code":0}}}

  3. mrbetta commented on Dec 8, 2021

    ContributorAuthor

    I'll make an attempt to add these to the code, but if someone wants to beat me to it I won't mind.

  4. mrbetta commented on Dec 8, 2021

    ContributorAuthor

    I added the LAS and PIR sensors to the devtools script and generated the following dump:
    KS220M(US)_1.0_1.0.4.txt

  5. rytilahti commented on Dec 8, 2021

    Member

    Based on the sysinfo, it should be detected as a SmartDimmer already, so I suppose this would be an extension to that class which implements the LAS & PIR module handling?

    Could you try and see if the controls are similar to the existing dimmer (using the PR that I just linked, kasa --type dimmer will force the tool to use the dimmer implementation)?

    Also, feel free to create a PR to add the modified devtools script as well as the fixture file to git. That can be done separately to any implementation PRs.

  6. mrbetta commented on Dec 9, 2021

    ContributorAuthor

    You're right. It does turn on and off and the dimmer works. This is for the motion and light sensors. Is there any interest in figuring out the scheduler or 'away mode'?

  7. rytilahti commented on Dec 9, 2021

    Member

    Okay, great! So the support for these new controls should be added to SmartDimmer class.

    For scheduler, see #265. There is another development branch where some work has been done on that, but it's far from complete. The away mode scheduler is called anti_theft in contrast to regular scheduling.

  8. rytilahti commented on Dec 13, 2021

    Member

    I had some downtime and created the base structure for those two new modules in the linked PR. They are not yet exposed via SmartDimmer anyhow, but I just wanted to add the queries already in place to see if the queries keep working on HS220 in case someone is running the modularize branch.

    @mrbetta if there is something missing from the smartlife.iot.dimmer, feel free to create a PR to add them to the current master branch. For adding the PIR & LAS, I think it's better to go with the modularize branch though.

  9. Chrisrdouglas commented on Apr 17, 2022

    So from what I understand, this library will support the ks220m now, correct? And if so would it be okay for me to update the readme to reflect that?

  10. rytilahti commented on Apr 24, 2022

    Member

    @Chrisrdouglas there is currently no nice way to interact with the new features either using the CLI nor the API, so that's why I didn't close the issue yet. The device itself is supported afaik, so feel free to update the readme!

  11. CrazyCoder commented on Nov 30, 2022

    @rytilahti I'm interested in using the motion sensor data for home automation. I planned to implement some quick hack to publish this info in HA via MQTT until the proper integration with HA is available. Can you share any example of how this API can be used? Thanks!

  12. rytilahti commented on Nov 30, 2022

    Member

    @CrazyCoder is the sensor data available in the mobile app? If yes, you could do a traffic capture and use the script in devtools to find out how it can be read from the device. The comments above I used to create the implementation provide only information about how to change the settings as far as I know.

  13. CrazyCoder commented on Nov 30, 2022

    @rytilahti Oh, I didn't realize that it may not expose the PIR status at all. I don't see anything in the app UI that would indicate that motion was detected or not detected. If it still exposes something, what would be the best way to find it?

  14. rytilahti commented on Nov 30, 2022

    Member

    @CrazyCoder considering the comprehensive input from @mrbetta, I doubt the device is reporting the status. But you could record the communications (either by using a simulator, or tcpdumping from your router) and use the script located in the devtools to inspect the trace for anything interesting.

  15. mrbetta commented on Nov 30, 2022

    ContributorAuthor

    I didn't see the PIR event in the captures I did, unfortunately. I had hoped to use the PIRs as a type of burglar alarm 'Away Mode' in HA, but they don't register directly as an event. Only thing I could think of was to monitor if the light turns on itself and register that as an alarm.

  16. CrazyCoder commented on Nov 30, 2022

    @rytilahti and @mrbetta Appreciate your quick responses. I'll give up on further tinkering as it appears to be unsupported by the device firmware.

    I checked built-in Kasa app Smart Actions, and there is no way to set up any action based on this switch motion sensing. So it's not supported even via a cloud. There is a feature request from another user.

    Will use external motion sensors for automation and the built-in sensor as the last backup option with some long interval for turning off. Could have bought switches without PIR to save some money, but at least the other controls work.

    Thanks again guys for your great support and for maintaining this library.

  17. rytilahti commented on Nov 30, 2022

    Member

    Sorry to hear that. Did you see anything besides the functionality that is already supported? I'm wondering if any of those values reported by get_config could be of any use.

    edit: I just saw your most recent update, looks like there is nothing much that can be done. I suppose this issue could be closed considering the implementation is already in place?

  18. CrazyCoder commented on Nov 30, 2022

    Yes, it looks like everything that is supported by the device is already implemented in this library. I tested with 1.0 HW switch, also have 1.8 HW version which I didn't try yet. I will open another issue if I find anything new.

  19. caretakerscurse commented on Dec 5, 2022

    Should the mentioned PIR JSON commands be expected to work with an ES20M? When smartlife.iot.PIR enable is either 1 or 0, the switch does not react to movement.

    Firmware: 1.0.8 Build 211201 Rel.123822
    Hardware: 1.0
    

    Sorry if this post is not appropriate to this thread.

  20. rytilahti commented on Dec 5, 2022

    Member

    Please create a separate issue or discussion for that, and describe what exactly is not working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL